https://github.com/s0rg/orderedmap
generic ordered maps for golang
https://github.com/s0rg/orderedmap
generic golang-library maps
Last synced: 6 months ago
JSON representation
generic ordered maps for golang
- Host: GitHub
- URL: https://github.com/s0rg/orderedmap
- Owner: s0rg
- License: mit
- Created: 2025-01-02T19:56:28.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-01-07T14:40:13.000Z (9 months ago)
- Last Synced: 2025-03-24T05:33:34.772Z (7 months ago)
- Topics: generic, golang-library, maps
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/s0rg/orderedmap)
[](https://github.com/s0rg/orderedmap/blob/master/LICENSE)
[](go.mod)
[](https://github.com/s0rg/orderedmap/tags)[](https://github.com/s0rg/grid/actions?query=workflow%3Aci)
[](https://goreportcard.com/report/github.com/s0rg/orderedmap)
[](https://codeclimate.com/github/s0rg/orderedmap/maintainability)
[](https://codeclimate.com/github/s0rg/orderedmap/test_coverage)
# orderedmap
Package orderedmap implements two types of generic maps, both iterates keys in ordered manner
# features
- two types of maps:
- Ordered - iterates in same order as items inserted
- Sorted - iterates in sorted order
- zero-dependency
- generic
- 100% test coverage# example
```go
import (
"fmt""github.com/s0rg/orderedmap"
)func exampleSorted() {
var m orderedmap.Sorted[string, string]m.Set("1", "foo")
m.Set("3", "baz")
m.Set("2", "bar")for k, v := range m.Iter {
fmt.Printf("%s: %s\n", k, v) // will print in order: 1, 2, 3 (as its sorted)
}
}func exampleOrdered() {
var m orderedmap.Ordered[string, string]m.Set("1", "foo")
m.Set("3", "baz")
m.Set("2", "bar")for k, v := range m.Iter {
fmt.Printf("%s: %s\n", k, v) // will print in order: 1, 3, 2 (in order of insertion)
}
}
```