OrderedMap provides three implementations of a map that preserves insertion order.
Unlike Go’s built-in map
, these maps maintain predictable iteration order.
This library built on top of AbstractLinkedMap from Apache Commons Collections.
- Key type: any integers
- Optimized for integer keys
- Preserves insertion order
- Fast
Get
,Put
,Delete
, and iteration - Predictable iteration via
Keys()
,Values()
, andItems()
- Generic key type
- Requires a custom hash function for the key type
- Preserves insertion order
- Useful for complex key types (structs, strings, etc.)
- Predictable iteration via
Keys()
,Values()
, andItems()
- Wrapper over Go’s built-in
map[K]V
- Uses
container/list
to maintain insertion order - Simple, safe, and fully generic
- Slightly higher overhead due to linked list
- Predictable iteration via
Keys()
,Values()
, andItems()
go get github.com/bibenga/orderedmap
import "github.com/olala/orderedmap/intlinkedhashmap"
// IntLinkedHashMap
intMap := intlinkedhashmap.NewDefault[int, int]()
intMap.Put(1, 12)
intMap.Put(2, 234)
for k, v := range m.Items() {
...
}