Skip to content

Commit ce850a7

Browse files
authored
Add NewOrderedMapWithElements function for initializing an ordered map with data (#45)
1 parent 9767ae7 commit ce850a7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

v2/orderedmap.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V] {
1111
}
1212
}
1313

14+
func NewOrderedMapWithElements[K comparable, V any](els ...*Element[K, V]) *OrderedMap[K, V] {
15+
om := &OrderedMap[K, V]{
16+
kv: make(map[K]*Element[K, V], len(els)),
17+
}
18+
for _, el := range els {
19+
om.Set(el.Key, el.Value)
20+
}
21+
return om
22+
}
23+
1424
// Get returns the value for a key. If the key does not exist, the second return
1525
// parameter will be false and the value will be nil.
1626
func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool) {

0 commit comments

Comments
 (0)