We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
linked.Hashmap
1 parent 88d304c commit 4a1d0bbCopy full SHA for 4a1d0bb
utils/linked/hashmap.go
@@ -20,10 +20,19 @@ type Hashmap[K comparable, V any] struct {
20
}
21
22
func NewHashmap[K comparable, V any]() *Hashmap[K, V] {
23
- return &Hashmap[K, V]{
24
- entryMap: make(map[K]*ListElement[keyValue[K, V]]),
+ return NewHashmapWithSize[K, V](0)
+}
25
+
26
+func NewHashmapWithSize[K comparable, V any](initialSize int) *Hashmap[K, V] {
27
+ lh := &Hashmap[K, V]{
28
+ entryMap: make(map[K]*ListElement[keyValue[K, V]], initialSize),
29
entryList: NewList[keyValue[K, V]](),
30
+ freeList: make([]*ListElement[keyValue[K, V]], initialSize),
31
+ }
32
+ for i := range lh.freeList {
33
+ lh.freeList[i] = &ListElement[keyValue[K, V]]{}
34
35
+ return lh
36
37
38
func (lh *Hashmap[K, V]) Put(key K, value V) {
0 commit comments