uint32_btree.gno
1.86 Kb · 78 lines
1package btree
2
3type Uint32IterCbFn func(key uint32, value any) bool
4
5type Uint32BTree struct {
6 tree *bTree
7}
8
9func NewUint32BTree(degree int) *Uint32BTree {
10 return &Uint32BTree{tree: newBTree(degree)}
11}
12
13func (t *Uint32BTree) Size() int {
14 return t.tree.Size()
15}
16
17func (t *Uint32BTree) Set(key uint32, value any) bool {
18 return t.tree.Set(uint32Key(key), value)
19}
20
21func (t *Uint32BTree) Get(key uint32) (any, bool) {
22 return t.tree.Get(uint32Key(key))
23}
24
25func (t *Uint32BTree) Has(key uint32) bool {
26 return t.tree.Has(uint32Key(key))
27}
28
29func (t *Uint32BTree) Remove(key uint32) (any, bool) {
30 return t.tree.Remove(uint32Key(key))
31}
32
33func (t *Uint32BTree) GetByIndex(index int) (uint32, any) {
34 key, value := t.tree.GetByIndex(index)
35 return uint32(key.(uint32Key)), value
36}
37
38func (t *Uint32BTree) Iterate(start, end *uint32, cb Uint32IterCbFn) bool {
39 var startKey key
40 if start != nil {
41 startKey = uint32Key(*start)
42 }
43
44 var endKey key
45 if end != nil {
46 endKey = uint32Key(*end)
47 }
48 return t.tree.Iterate(startKey, endKey, func(key key, value any) bool {
49 return cb(uint32(key.(uint32Key)), value)
50 })
51}
52
53func (t *Uint32BTree) ReverseIterate(start, end *uint32, cb Uint32IterCbFn) bool {
54 var startKey key
55 if start != nil {
56 startKey = uint32Key(*start)
57 }
58
59 var endKey key
60 if end != nil {
61 endKey = uint32Key(*end)
62 }
63 return t.tree.ReverseIterate(startKey, endKey, func(key key, value any) bool {
64 return cb(uint32(key.(uint32Key)), value)
65 })
66}
67
68func (t *Uint32BTree) IterateByOffset(offset int, count int, cb Uint32IterCbFn) bool {
69 return t.tree.IterateByOffset(offset, count, func(key key, value any) bool {
70 return cb(uint32(key.(uint32Key)), value)
71 })
72}
73
74func (t *Uint32BTree) ReverseIterateByOffset(offset int, count int, cb Uint32IterCbFn) bool {
75 return t.tree.ReverseIterateByOffset(offset, count, func(key key, value any) bool {
76 return cb(uint32(key.(uint32Key)), value)
77 })
78}