-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
hashmap.go
51 lines (44 loc) · 1.09 KB
/
hashmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ecs
import (
// "github.com/dolthub/swiss"
// "github.com/brentp/intintmap"
// "github.com/unitoftime/intmap"
"github.com/unitoftime/ecs/internal/intmap"
)
type intkey interface {
// comparable
~int | ~uint | ~int64 | ~uint64 | ~int32 | ~uint32 | ~int16 | ~uint16 | ~int8 | ~uint8 | ~uintptr
}
// This is useful for testing different map implementations in my workload
type internalMap[K intkey, V any] struct {
// inner map[K]V
// inner *swiss.Map[K, V]
inner *intmap.Map[K, V]
}
func newMap[K,V intkey](size int) *internalMap[K,V] {
return &internalMap[K,V]{
// make(map[K]V),
// swiss.NewMap[K, V](0), // Swissmap
intmap.New[K, V](0),
}
}
func (m *internalMap[K,V]) Get(k K) (V, bool) {
// v,ok := m.inner[k]
// return v, ok
return m.inner.Get(k)
}
func (m *internalMap[K,V]) Put(k K, val V) {
// m.inner[k] = val
m.inner.Put(k, val)
}
func (m *internalMap[K,V]) Delete(k K) {
// delete(m.inner, k)
// m.inner.Delete(k)
m.inner.Del(k)
}
func (m *internalMap[K,V]) Has(k K) bool {
// _, has := m.inner[k]
// return m.inner.Has(k)
_, has := m.inner.Get(k)
return has
}