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