Search Apps Documentation Source Content File Folder Download Copy Actions Download

uint64_btree.gno

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