Search Apps Documentation Source Content File Folder Download Copy Actions Download

string_btreeset.gno

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