-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaphead.go
108 lines (83 loc) · 2.1 KB
/
maphead.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package skiplistmap
import (
"fmt"
"io"
"math/bits"
"unsafe"
"github.com/kazu/elist_head"
)
type mapState uint32
const (
mapIsDummy mapState = 1 << iota
mapIsDeleted
)
type MapHead struct {
state mapState
conflict uint64
reverse uint64
elist_head.ListHead
}
var EmptyMapHead *MapHead = (*MapHead)(unsafe.Pointer(uintptr(0)))
func (mh *MapHead) KeyInHmap() uint64 {
return bits.Reverse64(mh.reverse)
}
func (mh *MapHead) IsIgnored() bool {
return mh.state > 0
}
func (mh *MapHead) IsDummy() bool {
return mh.state&mapIsDummy > 0
}
func (mh *MapHead) IsDeleted() bool {
return mh.state&mapIsDeleted > 0
}
func (mh *MapHead) ConflictInHamp() uint64 {
return mh.conflict
}
func (mh *MapHead) PtrListHead() *elist_head.ListHead {
return &(mh.ListHead)
}
const mapheadOffset = unsafe.Offsetof(EmptyMapHead.ListHead)
func (mh *MapHead) Offset() uintptr {
return mapheadOffset
}
//go:nocheckptr
func mapheadFromLListHead(l *elist_head.ListHead) *MapHead {
return (*MapHead)(ElementOf(unsafe.Pointer(l), mapheadOffset))
}
func (mh *MapHead) fromListHead(l *elist_head.ListHead) *MapHead {
return mapheadFromLListHead(l)
}
func (c *MapHead) FromListHead(l *elist_head.ListHead) elist_head.List {
return c.fromListHead(l)
}
func (c *MapHead) NextWithNil() *MapHead {
if c.Next() == &c.ListHead {
return nil
}
if c.Next().Empty() {
return nil
}
return c.fromListHead(c.Next())
}
func (c *MapHead) PrevtWithNil() *MapHead {
if c.Prev() == &c.ListHead {
return nil
}
if c.Prev().Empty() {
return nil
}
return c.fromListHead(c.Prev())
}
func (mhead *MapHead) dump(w io.Writer) {
e := fromMapHead(mhead)
var ekey interface{}
ekey = e.Key()
fmt.Fprintf(w, " entryHMap{key: %+10v, k: 0x%16x, reverse: 0x%16x), conflict: 0x%x, cur: %p, prev: %p, next: %p}\n",
ekey, bits.Reverse64(mhead.reverse), mhead.reverse, mhead.conflict, mhead.PtrListHead(), mhead.PtrListHead().DirectPrev(), mhead.PtrListHead().DirectNext())
}
func fromMapHead(mhead *MapHead) MapItem {
if mhead.IsDummy() {
return entryHMapFromListHead(mhead.PtrListHead())
}
return SampleItemFromListHead(mhead.PtrListHead())
}