Search Apps Documentation Source Content File Folder Download Copy Actions Download

uint64_btreeset.gno

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