-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmapEntry.go
44 lines (34 loc) · 1.08 KB
/
mapEntry.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
package frozen
import (
"github.com/arr-ai/hash"
"github.com/arr-ai/frozen/internal/pkg/value"
)
type mapEntry[K, V any] struct {
KeyValue[K, V]
}
func newMapEntry[K, V any](k K, v V) mapEntry[K, V] {
return mapEntry[K, V]{KeyValue: KeyValue[K, V]{Key: k, Value: v}}
}
func newMapKey[K, V any](k K) mapEntry[K, V] {
var v V
return mapEntry[K, V]{KeyValue: KeyValue[K, V]{Key: k, Value: v}}
}
func (e mapEntry[K, V]) Equal(e2 mapEntry[K, V]) bool {
return value.Equal(e.Key, e2.Key)
}
// Hash computes a hash for a mapEntry[K, V].
func (e mapEntry[K, V]) Hash(seed uintptr) uintptr {
return hash.Any(e.Key, seed)
}
// mapEntryHash hashes using the KeyValue's own key.
func mapEntryEqual[K, V any](a, b mapEntry[K, V]) bool {
return value.Equal(a.Key, b.Key) && value.Equal(a.Value, b.Value)
}
// mapEntryHash hashes using the KeyValue's own key.
func mapEntryKeyEqual[K, V any](a, b mapEntry[K, V]) bool {
return value.Equal(a.Key, b.Key)
}
// mapEntryHash hashes using the KeyValue's own key.
func mapEntryHash[K, V any](e mapEntry[K, V], seed uintptr) uintptr {
return e.Hash(seed)
}