Skip to content

Commit

Permalink
Add NewOrderedMapWithElements function for initializing an ordered ma…
Browse files Browse the repository at this point in the history
…p with data (#45)
  • Loading branch information
pd93 authored Nov 27, 2024
1 parent 9767ae7 commit ce850a7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions v2/orderedmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V] {
}
}

func NewOrderedMapWithElements[K comparable, V any](els ...*Element[K, V]) *OrderedMap[K, V] {
om := &OrderedMap[K, V]{
kv: make(map[K]*Element[K, V], len(els)),
}
for _, el := range els {
om.Set(el.Key, el.Value)
}
return om
}

// Get returns the value for a key. If the key does not exist, the second return
// parameter will be false and the value will be nil.
func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool) {
Expand Down

0 comments on commit ce850a7

Please sign in to comment.