github.com/blong14/gache@v0.0.0-20240124023949-89416fd8bbfa/internal/db/memtable/node.go (about) 1 package memtable 2 3 import ( 4 "sync/atomic" 5 "unsafe" 6 ) 7 8 type node struct { 9 hash uint64 10 next *node 11 key []byte 12 val []byte 13 } 14 15 func newNode(h uint64, k, v []byte, next *node) *node { 16 return &node{ 17 hash: h, 18 next: next, 19 key: k, 20 val: v, 21 } 22 } 23 24 func freeNode(n *node) {} 25 26 func (n *node) Next() *node { 27 if n == nil { 28 return nil 29 } 30 return (*node)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&n.next)))) 31 } 32 33 type index struct { 34 node *node 35 down *index 36 right *index 37 } 38 39 func newIndex(next *node, down, right *index) *index { 40 return &index{ 41 node: next, 42 down: down, 43 right: right, 44 } 45 } 46 47 func freeIndex(n *index) {} 48 49 func (i *index) Node() *node { 50 if i == nil { 51 return nil 52 } 53 return (*node)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&i.node)))) 54 } 55 56 func (i *index) Down() *index { 57 if i == nil { 58 return nil 59 } 60 return (*index)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&i.down)))) 61 } 62 63 func (i *index) Right() *index { 64 if i == nil { 65 return nil 66 } 67 return (*index)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&i.right)))) 68 }