ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - srfrog/dict: Python-like dictionaries for Go
Python-like dictionaries for Go. Contribute to srfrog/dict development by creating an account on GitHub.
Visit Site

GitHub - srfrog/dict: Python-like dictionaries for Go

GitHub - srfrog/dict: Python-like dictionaries for Go

Dict

GoDoc Go Report Card Coverage Status Build Status

Python dictionary data type (dict) in Go

Package dict is a Go implementation of Python dict, which are hashable object maps. Dictionaries complement Go map and slice types to provide a simple interface to store and access key-value data with relatively fast performance at the cost of extra memory. This is done by using the features of both maps and slices.

Quick Start

Install using "go get":

go get github.com/srfrog/dict

Then import from your source:

import "github.com/srfrog/dict"

View example_test.go for an extended example of basic usage and features.

Features

  • Initialize a new dict with scalars, slices, maps, channels and other dictionaries.
  • Go types int, uint, float, string and fmt.Stringer are hashable for dict keys.
  • Go map keys are used for dict keys if they are hashable.
  • Dict items are sorted in their insertion order, unlike Go maps.
  • Go routine safe with minimal mutex locking (WIP)
  • Builtin JSON support for marshalling and unmarshalling
  • sql.Scanner support via optional sub-package (WIP)
  • Plenty of tests and examples to get you started quickly (WIP)

Documentation

The full code documentation is located at GoDoc:

http://godoc.org/github.com/srfrog/dict

The source code is thoroughly commented, have a look.

Usage

Minimal example showing basic usage:

package main

import (
	"fmt"

	"github.com/srfrog/dict"
)

type Car struct {
	Model, BrandID string
	Recalls        int
}

func main() {
	// Map of car models, indexed by VIN.
	// Data source: NHTSA.gov
	vins := map[string]*Car{
		"2C3KA43R08H129584": &Car{
			Model:   "2008 CHRYSLER 300",
			BrandID: "ACB9976A-DB5F-4D57-B9A8-9F5C53D87C7C",
			Recalls: 1,
		},
		"1N6AD07U78C416152": &Car{
			Model:   "2008 NISSAN FRONTIER SE-V6 RWD",
			BrandID: "003096EE-C8FC-4C2F-ADEF-406F86C1F70B",
			Recalls: 5,
		},
		"WDDGF8AB8EA940372": &Car{
			Model:   "2014 Mercedes-Benz C300W4",
			BrandID: "57B7B707-4357-4306-9FD6-1EDCA43CF77B",
			Recalls: 4,
		},
	}

	// Create new dict and initialize with vins map.
	d := dict.New(vins)

	// Add a couple more VINs.
	d.Set("1N4AL2AP4BN404580", &Car{
		Model:   "2011 NISSAN ALTIMA 2.5 S CVT",
		BrandID: "003096EE-C8FC-4C2F-ADEF-406F86C1F70B",
		Recalls: 2,
	})
	d.Set("4T1BE46K48U762452", &Car{
		Model:   "2008 TOYOTA Camry",
		BrandID: "C5764FE4-F1E8-46BE-AFC6-A2FC90110387",
		Recalls: 5,
	})

	// Check current total
	fmt.Println("Total VIN Count:", d.Len())

	// Print VINs that have 3 or more recalls
	for item := range d.Items() {
		car, ok := item.Value.(*Car)
		if !ok {
			continue // Not a Car
		}
		if car.Recalls < 3 {
			continue // Not enough recalls
		}
		fmt.Println("---")
		fmt.Println("VIN:", item.Key)
	}
}

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory