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