Search Apps Documentation Source Content File Folder Download Copy Actions Download

uint32_btreeset.gno

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