Skip to content

Commit

Permalink
formatting & test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
superfell committed Apr 19, 2022
1 parent d01f77d commit b07a3ac
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions art.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions art_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
}
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions example/ex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 0 additions & 2 deletions leaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package art

import "fmt"

var emptyPath [24]byte

type leaf[V any] struct {
value V
path keyPath
Expand Down

0 comments on commit b07a3ac

Please sign in to comment.