iradix update

This commit is contained in:
Frank Denis 2018-01-30 11:20:41 +01:00
parent c2494cfc40
commit 367f7fd675
3 changed files with 45 additions and 5 deletions

6
Gopkg.lock generated
View File

@ -50,7 +50,7 @@
branch = "master" branch = "master"
name = "github.com/hashicorp/go-immutable-radix" name = "github.com/hashicorp/go-immutable-radix"
packages = ["."] packages = ["."]
revision = "59b67882ec612f43b9d4c4fd97cebd507be4b3ee" revision = "7f3cd4390caab3250a57f30efdb2a65dd7649ecf"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -115,7 +115,7 @@
"poly1305", "poly1305",
"salsa20/salsa" "salsa20/salsa"
] ]
revision = "3d37316aaa6bd9929127ac9a527abf408178ea7b" revision = "1875d0a70c90e57f11972aefd42276df65e895b9"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -139,7 +139,7 @@
"windows/svc/eventlog", "windows/svc/eventlog",
"windows/svc/mgr" "windows/svc/mgr"
] ]
revision = "ef802241c90f84d84d644a2d8d0de8ee96038c9c" revision = "3dbebcf8efb6a5011a60c2b4591c1022a759af8a"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"

View File

@ -338,6 +338,11 @@ func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) {
if !n.isLeaf() { if !n.isLeaf() {
return nil, nil return nil, nil
} }
// Copy the pointer in case we are in a transaction that already
// modified this node since the node will be reused. Any changes
// made to the node will not affect returning the original leaf
// value.
oldLeaf := n.leaf
// Remove the leaf node // Remove the leaf node
nc := t.writeNode(n, true) nc := t.writeNode(n, true)
@ -347,7 +352,7 @@ func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) {
if n != t.root && len(nc.edges) == 1 { if n != t.root && len(nc.edges) == 1 {
t.mergeChild(nc) t.mergeChild(nc)
} }
return nc, n.leaf return nc, oldLeaf
} }
// Look for an edge // Look for an edge

View File

@ -173,7 +173,7 @@ func TestRoot(t *testing.T) {
} }
val, ok := r.Get(nil) val, ok := r.Get(nil)
if !ok || val != true { if !ok || val != true {
t.Fatalf("bad: %v %#v", val) t.Fatalf("bad: %#v", val)
} }
r, val, ok = r.Delete(nil) r, val, ok = r.Delete(nil)
if !ok || val != true { if !ok || val != true {
@ -1494,3 +1494,38 @@ func TestTrackMutate_cachedNodeChange(t *testing.T) {
} }
} }
} }
func TestLenTxn(t *testing.T) {
r := New()
if r.Len() != 0 {
t.Fatalf("not starting with empty tree")
}
txn := r.Txn()
keys := []string{
"foo/bar/baz",
"foo/baz/bar",
"foo/zip/zap",
"foobar",
"nochange",
}
for _, k := range keys {
txn.Insert([]byte(k), nil)
}
r = txn.Commit()
if r.Len() != len(keys) {
t.Fatalf("bad: expected %d, got %d", len(keys), r.Len())
}
txn = r.Txn()
for _, k := range keys {
txn.Delete([]byte(k))
}
r = txn.Commit()
if r.Len() != 0 {
t.Fatalf("tree len should be zero, got %d", r.Len())
}
}