diff --git a/art.go b/art.go index 2dfcb7b..e4f2ff9 100644 --- a/art.go +++ b/art.go @@ -150,7 +150,7 @@ func (a *Tree[V]) walk(n node[V], prefix []byte, callback func(key []byte, value // WalkRange will call the provided callback function with each key/value pair, in key order. // keys will be limited to those equal to or greater than start and less than end. So its inclusive -// of start, and exclusive of send. +// of start, and exclusive of end. // nil can used to mean no limit in that direction. e.g. WalkRange(nil,nil,cb) is the same as // WalkRange(cb). WalkRange([]byte{1}, nil, cb) will wall all that are equal to or greater than [1] // WalkRange([]byte{1}, []byte{2},cb) will walk all keys with a prefix of [1]. @@ -166,7 +166,7 @@ func (a *Tree[V]) WalkRange(start []byte, end []byte, callback func(key []byte, a.walkStart(a.root, make([]byte, 0, 32), keyLimit{start, 0}, cmpEnd, callback) } -func (a *Tree[V]) walkStart(n node[V], current []byte, start, end keyLimit, callback func(key []byte, value V)WalkState) WalkState { +func (a *Tree[V]) walkStart(n node[V], current []byte, start, end keyLimit, callback func(key []byte, value V) WalkState) WalkState { h := n.header() for _, k := range h.path.asSlice() { start.cmpSegment(k) diff --git a/art_test.go b/art_test.go index 3aacc94..79ecfcf 100644 --- a/art_test.go +++ b/art_test.go @@ -123,7 +123,7 @@ func Test_SetValueOnExistingNode(t *testing.T) { t.Run(fmt.Sprintf("children %d", tc.children), func(t *testing.T) { inserts := []keyVal[string]{} for i := 0; i < tc.children; i++ { - inserts = append(inserts, kv([]byte{1, byte(i)},strconv.Itoa(i))) + inserts = append(inserts, kv([]byte{1, byte(i)}, strconv.Itoa(i))) } inserts = append(inserts, kv([]byte{1}, "value")) testArt(t, inserts, tc.stats) @@ -171,13 +171,13 @@ func Test_CompressedPathLargerThan24(t *testing.T) { } func Test_GrowWithPrefixValue(t *testing.T) { - keyVals := []keyVal[any]{ - kvs[any]("BBB", "kk"), - kvs[any]("B", "k"), - kvs[any]("BBx", 100), + keyVals := []keyVal[int]{ + kvs("BBB", 1010), + kvs("B", 505), + kvs("BBx", 5555), } for i := 0; i < 256; i++ { - keyVals = append(keyVals, kv[any]([]byte{'B', byte(i)}, i)) + keyVals = append(keyVals, kv([]byte{'B', byte(i)}, i)) } testArt(t, keyVals, &Stats{Node256s: 1, Node4s: 1, Keys: 259}) } @@ -210,10 +210,11 @@ func Test_EmptyKey(t *testing.T) { } func Test_NilValue(t *testing.T) { - testArt(t, []keyVal[any]{ - kv[any]([]byte{0, 0, 0}, nil), - kv[any]([]byte{0, 0, 0, 1}, "3"), - kv[any]([]byte{10}, nil), + three := "3" + testArt(t, []keyVal[*string]{ + kv[*string]([]byte{0, 0, 0}, nil), + kv([]byte{0, 0, 0, 1}, &three), + kv[*string]([]byte{10}, nil), }, nil) } diff --git a/example/ex.go b/example/ex.go index 6434750..1d657cc 100644 --- a/example/ex.go +++ b/example/ex.go @@ -8,14 +8,14 @@ import ( ) func main() { - a := new(art.Tree) + a := new(art.Tree[string]) k := []byte{1, 2, 4, 0, 1} k2 := []byte{1, 2, 4, 0, 2} a.Put(k, "bob") v, exists := a.Get(k) fmt.Printf("key %v exists %t with value %v\n", k, exists, v) a.Put(k2, "eve") - a.Walk(func(k []byte, v interface{}) art.WalkState { + a.Walk(func(k []byte, v string) art.WalkState { fmt.Printf("%v : %v\n", k, v) return art.Continue }) diff --git a/leaf.go b/leaf.go index c4aa092..95183de 100644 --- a/leaf.go +++ b/leaf.go @@ -2,8 +2,6 @@ package art import "fmt" -var emptyPath [24]byte - type leaf[V any] struct { value V path keyPath