goradd/maps
Go 1.18+ generic map interface for maps; safe maps; ordered maps; ordered, safe maps; etc
About goradd/maps
maps
maps is a library using Go generics that offers a standard interface for manipulating different kinds of maps.
Using the same interface, you can create and use a standard Go map, a map that is safe for concurrency and/or a map that lets you order the keys in the map.
A Set class is included for quickly determining membership in a group.
Example
package main
import . "github.com/goradd/maps"
import "fmt"
type myMap = Map[string,int] // the equal sign here is critical!
type myStdMap = StdMap[string, int]
func main() {
m := new(Map[string, int])
m.Copy(myStdMap{"b":2, "c":3})
m.Set("a",1)
sum := 0
for v := range m.All() {
sum += v
}
fmt.Print(sum)
}
By simply changing myMap to a SafeMap, you can make the map safe for concurrent use. Or, you can change myMap to a SliceMap, or a SafeSliceMap to also be able to iterate the map in the order it was created, similar to a PHP map.
Frequently Asked Questions
What is goradd/maps?
goradd/maps is a Data Structures and Algorithms library for the Go programming language. Go 1.18+ generic map interface for maps; safe maps; ordered maps; ordered, safe maps; etc
How do I install goradd/maps?
Install goradd/maps with the Go module system using `go get goradd/maps`. Check the repository for the current installation instructions.
What category does goradd/maps belong to?
goradd/maps is listed under Data Structures and Algorithms, specifically Maps.