-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.go
More file actions
42 lines (32 loc) · 743 Bytes
/
iterator.go
File metadata and controls
42 lines (32 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package art
// Iterate over every key from a given point
func (t *ART) Iterate(from []byte, fn func(key []byte, value Comparable)) {
var current *node
if len(from) > 0 {
_, current, _, _ = t.find(from)
} else {
current = t.root
}
t.iterate(from, current, fn)
}
func (t *ART) iterate(key []byte, current *node, fn func(key []byte, value Comparable)) {
if current.edges == nil {
return
}
for i := 0; i < 256; i++ {
next := current.next(byte(i))
if next == nil {
continue
}
ckey := make([]byte, len(key))
copy(ckey, key)
ckey = append(ckey, byte(i))
if len(next.prefix) > 0 {
ckey = append(ckey, next.prefix...)
}
if next.value != nil {
fn(ckey, next.value)
}
t.iterate(ckey, next, fn)
}
}