-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaf.go
62 lines (59 loc) · 1.57 KB
/
leaf.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package immutable
/*
leaf_t
Internal node that contains only a key and a value.
*/
type leafV struct {
entryV
}
type leafKV struct {
key_ string
leafV
}
func leaf(key string, val Value) itrie {
if len(key) > 0 {
Cumulative[kLeafKV]++
l := new(leafKV)
l.key_ = str(key); l.val_ = val
return l
}
Cumulative[kLeafV]++
l := new(leafV)
l.val_ = val
return l
}
func (l *leafV) modify(incr, i int, sub itrie) itrie {
panic("can't modify a leaf in this way")
}
func (l *leafV) cloneWithKey(key string) itrie {
return leaf(key, l.val_)
}
func (l *leafV) cloneWithKeyValue(key string, val Value) (itrie, int) {
return leaf(key, val), 0
}
func (l *leafV) withoutValue() (itrie, int) {
return nil, 1
}
func (l *leafV) subAt(cb byte) itrie { return nil }
func (l *leafV) with(incr int, cb byte, r itrie) itrie {
return bag1("", l.val_, true, cb, r)
}
func (l *leafKV) with(incr int, cb byte, r itrie) itrie {
return bag1(l.key_, l.val_, true, cb, r)
}
func (l *leafV) without(cb byte, r itrie) itrie {
panic("leaves can't do 'without'.")
}
func (l *leafV) foreach(prefix string, f func(string, Value)) {
f(prefix, l.val_)
}
func (l *leafKV) foreach(prefix string, f func(string, Value)) {
f(prefix + l.key_, l.val_)
}
func (l *leafV) withsubs(start uint, end uint, fn func(byte, itrie)) {}
func (l *leafV) key() string { return "" }
func (l *leafKV) key() string { return l.key_ }
func (l *leafV) count() int { return 1 }
func (l *leafV) occupied() int { return 0 }
func (l *leafV) expanse() expanse_t { return expanse0() }
func (l *leafV) expanseWithout(byte) expanse_t { return expanse0() }