github.com/maypok86/otter@v1.2.1/internal/generated/node/b.go (about) 1 // Code generated by NodeGenerator. DO NOT EDIT. 2 3 // Package node is a generated generator package. 4 package node 5 6 import ( 7 "sync/atomic" 8 "unsafe" 9 ) 10 11 // B is a cache entry that provide the following features: 12 // 13 // 1. Base 14 type B[K comparable, V any] struct { 15 key K 16 value V 17 prev *B[K, V] 18 next *B[K, V] 19 state uint32 20 frequency uint8 21 queueType uint8 22 } 23 24 // NewB creates a new B. 25 func NewB[K comparable, V any](key K, value V, expiration, cost uint32) Node[K, V] { 26 return &B[K, V]{ 27 key: key, 28 value: value, 29 state: aliveState, 30 } 31 } 32 33 // CastPointerToB casts a pointer to B. 34 func CastPointerToB[K comparable, V any](ptr unsafe.Pointer) Node[K, V] { 35 return (*B[K, V])(ptr) 36 } 37 38 func (n *B[K, V]) Key() K { 39 return n.key 40 } 41 42 func (n *B[K, V]) Value() V { 43 return n.value 44 } 45 46 func (n *B[K, V]) AsPointer() unsafe.Pointer { 47 return unsafe.Pointer(n) 48 } 49 50 func (n *B[K, V]) Prev() Node[K, V] { 51 return n.prev 52 } 53 54 func (n *B[K, V]) SetPrev(v Node[K, V]) { 55 if v == nil { 56 n.prev = nil 57 return 58 } 59 n.prev = (*B[K, V])(v.AsPointer()) 60 } 61 62 func (n *B[K, V]) Next() Node[K, V] { 63 return n.next 64 } 65 66 func (n *B[K, V]) SetNext(v Node[K, V]) { 67 if v == nil { 68 n.next = nil 69 return 70 } 71 n.next = (*B[K, V])(v.AsPointer()) 72 } 73 74 func (n *B[K, V]) PrevExp() Node[K, V] { 75 panic("not implemented") 76 } 77 78 func (n *B[K, V]) SetPrevExp(v Node[K, V]) { 79 panic("not implemented") 80 } 81 82 func (n *B[K, V]) NextExp() Node[K, V] { 83 panic("not implemented") 84 } 85 86 func (n *B[K, V]) SetNextExp(v Node[K, V]) { 87 panic("not implemented") 88 } 89 90 func (n *B[K, V]) HasExpired() bool { 91 return false 92 } 93 94 func (n *B[K, V]) Expiration() uint32 { 95 panic("not implemented") 96 } 97 98 func (n *B[K, V]) Cost() uint32 { 99 return 1 100 } 101 102 func (n *B[K, V]) IsAlive() bool { 103 return atomic.LoadUint32(&n.state) == aliveState 104 } 105 106 func (n *B[K, V]) Die() { 107 atomic.StoreUint32(&n.state, deadState) 108 } 109 110 func (n *B[K, V]) Frequency() uint8 { 111 return n.frequency 112 } 113 114 func (n *B[K, V]) IncrementFrequency() { 115 n.frequency = minUint8(n.frequency+1, maxFrequency) 116 } 117 118 func (n *B[K, V]) DecrementFrequency() { 119 n.frequency-- 120 } 121 122 func (n *B[K, V]) ResetFrequency() { 123 n.frequency = 0 124 } 125 126 func (n *B[K, V]) MarkSmall() { 127 n.queueType = smallQueueType 128 } 129 130 func (n *B[K, V]) IsSmall() bool { 131 return n.queueType == smallQueueType 132 } 133 134 func (n *B[K, V]) MarkMain() { 135 n.queueType = mainQueueType 136 } 137 138 func (n *B[K, V]) IsMain() bool { 139 return n.queueType == mainQueueType 140 } 141 142 func (n *B[K, V]) Unmark() { 143 n.queueType = unknownQueueType 144 }