From df1f00627ec904f9523fa7972b9dd75d9c908749 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 25 Feb 2022 15:34:42 +0000 Subject: [PATCH] Remove Stats structure --- internal/trie/node/branch.go | 7 +- internal/trie/node/copy.go | 6 +- internal/trie/node/stats.go | 20 +- internal/trie/node/stats_test.go | 32 +- lib/trie/trie.go | 6 +- lib/trie/trie_test.go | 790 +++++++++++++++---------------- 6 files changed, 414 insertions(+), 447 deletions(-) diff --git a/internal/trie/node/branch.go b/internal/trie/node/branch.go index a5eab768e63..fd767585ccc 100644 --- a/internal/trie/node/branch.go +++ b/internal/trie/node/branch.go @@ -30,7 +30,12 @@ type Branch struct { // which is updated to match the trie Generation once they are // inserted, moved or iterated over. Generation uint64 - Stats Stats + + // Statistics + + // Descendants is the number of descendant nodes for + // this particular node. + Descendants uint32 } // NewBranch creates a new branch using the arguments given. diff --git a/internal/trie/node/copy.go b/internal/trie/node/copy.go index 142b535d274..62d680a42cd 100644 --- a/internal/trie/node/copy.go +++ b/internal/trie/node/copy.go @@ -8,9 +8,9 @@ package node // children as well. func (b *Branch) Copy(copyChildren bool) Node { cpy := &Branch{ - Dirty: b.Dirty, - Generation: b.Generation, - Stats: b.Stats, + Dirty: b.Dirty, + Generation: b.Generation, + Descendants: b.Descendants, } if copyChildren { diff --git a/internal/trie/node/stats.go b/internal/trie/node/stats.go index c3e1be7dbb4..478cda15639 100644 --- a/internal/trie/node/stats.go +++ b/internal/trie/node/stats.go @@ -1,30 +1,16 @@ package node -// Stats contains statistical information for a node. -type Stats struct { - // Descendants is the number of descendant nodes for - // this particular node. - Descendants uint32 -} - -// NewStats creates a new Stats structure given the arguments. -func NewStats(descendants uint32) Stats { - return Stats{ - Descendants: descendants, - } -} - // GetDescendants returns the number of descendants in the branch. func (b *Branch) GetDescendants() (descendants uint32) { - return b.Stats.Descendants + return b.Descendants } // AddDescendants adds descendant nodes count to the node stats. func (b *Branch) AddDescendants(n uint32) { - b.Stats.Descendants += n + b.Descendants += n } // SubDescendants subtracts descendant nodes count from the node stats. func (b *Branch) SubDescendants(n uint32) { - b.Stats.Descendants -= n + b.Descendants -= n } diff --git a/internal/trie/node/stats_test.go b/internal/trie/node/stats_test.go index c424c3ca5f8..afa6599bb99 100644 --- a/internal/trie/node/stats_test.go +++ b/internal/trie/node/stats_test.go @@ -6,26 +6,12 @@ import ( "github.com/stretchr/testify/assert" ) -func Test_NewStats(t *testing.T) { - t.Parallel() - - const descendants uint32 = 10 - stats := NewStats(descendants) - - expected := Stats{ - Descendants: descendants, - } - assert.Equal(t, expected, stats) -} - func Test_Branch_GetDescendants(t *testing.T) { t.Parallel() const descendants uint32 = 10 branch := &Branch{ - Stats: Stats{ - Descendants: descendants, - }, + Descendants: descendants, } result := branch.GetDescendants() @@ -41,15 +27,11 @@ func Test_Branch_AddDescendants(t *testing.T) { finalDescendants uint32 = 12 ) branch := &Branch{ - Stats: Stats{ - Descendants: initialDescendants, - }, + Descendants: initialDescendants, } branch.AddDescendants(addDescendants) expected := &Branch{ - Stats: Stats{ - Descendants: finalDescendants, - }, + Descendants: finalDescendants, } assert.Equal(t, expected, branch) @@ -64,15 +46,11 @@ func Test_Branch_SubDescendants(t *testing.T) { finalDescendants uint32 = 8 ) branch := &Branch{ - Stats: Stats{ - Descendants: initialDescendants, - }, + Descendants: initialDescendants, } branch.SubDescendants(subDescendants) expected := &Branch{ - Stats: Stats{ - Descendants: finalDescendants, - }, + Descendants: finalDescendants, } assert.Equal(t, expected, branch) diff --git a/lib/trie/trie.go b/lib/trie/trie.go index a822a96e7a4..73391dc2731 100644 --- a/lib/trie/trie.go +++ b/lib/trie/trie.go @@ -1091,10 +1091,8 @@ func handleDeletion(branch *node.Branch, key []byte) (newNode Node, branchChildM Value: childBranch.Value, Generation: branch.Generation, Dirty: true, - Stats: node.Stats{ - // this is the descendants of the original branch minus one - Descendants: childBranch.GetDescendants(), - }, + // this is the descendants of the original branch minus one + Descendants: childBranch.GetDescendants(), } // Adopt the grand-children diff --git a/lib/trie/trie_test.go b/lib/trie/trie_test.go index cb83e85d75b..ced15c6586a 100644 --- a/lib/trie/trie_test.go +++ b/lib/trie/trie_test.go @@ -474,9 +474,9 @@ func Test_Trie_Hash(t *testing.T) { "branch root": { trie: Trie{ root: &node.Branch{ - Key: []byte{1, 2, 3}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{1, 2, 3}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{9}}, }, @@ -489,9 +489,9 @@ func Test_Trie_Hash(t *testing.T) { 0xbe, 0x27, 0xab, 0x13, 0xcb, 0xf0, 0xfd, 0xd7}, expectedTrie: Trie{ root: &node.Branch{ - Key: []byte{1, 2, 3}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{1, 2, 3}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{9}, @@ -554,9 +554,9 @@ func Test_Trie_Entries(t *testing.T) { t.Parallel() root := &node.Branch{ - Key: []byte{0xa}, - Value: []byte("root"), - Stats: node.NewStats(2), + Key: []byte{0xa}, + Value: []byte("root"), + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ // index 0 Key: []byte{2, 0xb}, @@ -587,15 +587,15 @@ func Test_Trie_Entries(t *testing.T) { t.Parallel() root := &node.Branch{ - Key: []byte{0xa, 0xb}, - Value: []byte("root"), - Stats: node.NewStats(5), + Key: []byte{0xa, 0xb}, + Value: []byte("root"), + Descendants: 5, Children: [16]node.Node{ nil, nil, nil, &node.Branch{ // branch with value at child index 3 - Key: []byte{0xb}, - Value: []byte("branch 1"), - Stats: node.NewStats(1), + Key: []byte{0xb}, + Value: []byte("branch 1"), + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, &node.Leaf{ // leaf at child index 3 @@ -611,9 +611,9 @@ func Test_Trie_Entries(t *testing.T) { }, nil, &node.Branch{ // branch without value at child index 9 - Key: []byte{0xe}, - Value: []byte("branch 2"), - Stats: node.NewStats(1), + Key: []byte{0xe}, + Value: []byte("branch 2"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // leaf at child index 0 Key: []byte{0xf}, @@ -760,9 +760,9 @@ func Test_nextKey(t *testing.T) { "key smaller than root branch full key": { trie: Trie{ root: &node.Branch{ - Key: []byte{2}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{1}, @@ -776,9 +776,9 @@ func Test_nextKey(t *testing.T) { "key equal to root branch full key": { trie: Trie{ root: &node.Branch{ - Key: []byte{2}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{1}, @@ -791,9 +791,9 @@ func Test_nextKey(t *testing.T) { "key smaller than leaf full key": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ nil, nil, &node.Leaf{ @@ -809,9 +809,9 @@ func Test_nextKey(t *testing.T) { "key equal to leaf full key": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ nil, nil, &node.Leaf{ @@ -826,9 +826,9 @@ func Test_nextKey(t *testing.T) { "key greater than leaf full key": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ nil, nil, &node.Leaf{ @@ -843,16 +843,16 @@ func Test_nextKey(t *testing.T) { "next key branch with value": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Value: []byte("top branch"), - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte("top branch"), + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Branch{ // full key [1, 2, 3] - Key: []byte{3}, - Value: []byte("branch 1"), - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte("branch 1"), + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, nil, &node.Leaf{ @@ -871,14 +871,14 @@ func Test_nextKey(t *testing.T) { "next key go through branch without value": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Branch{ // full key [1, 2, 3] - Key: []byte{3}, - Stats: node.NewStats(1), + Key: []byte{3}, + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, nil, &node.Leaf{ @@ -897,15 +897,15 @@ func Test_nextKey(t *testing.T) { "next key leaf from bottom branch": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Branch{ // full key [1, 2, 3] - Key: []byte{3}, - Value: []byte("bottom branch"), - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte("bottom branch"), + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, nil, &node.Leaf{ @@ -924,15 +924,15 @@ func Test_nextKey(t *testing.T) { "next key greater than branch": { trie: Trie{ root: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Branch{ // full key [1, 2, 3] - Key: []byte{3}, - Value: []byte("bottom branch"), - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte("bottom branch"), + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, nil, &node.Leaf{ @@ -951,9 +951,9 @@ func Test_nextKey(t *testing.T) { "key smaller length and greater than root branch full key": { trie: Trie{ root: &node.Branch{ - Key: []byte{2, 0}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{2, 0}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1009,10 +1009,10 @@ func Test_Trie_Put(t *testing.T) { expectedTrie: Trie{ generation: 1, root: &node.Branch{ - Key: []byte{1, 2}, - Generation: 1, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Generation: 1, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ Key: []byte{5}, @@ -1109,10 +1109,10 @@ func Test_Trie_put(t *testing.T) { expectedTrie: Trie{ generation: 1, root: &node.Branch{ - Key: []byte{1}, - Generation: 1, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{1}, + Generation: 1, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ Key: []byte{5}, @@ -1175,9 +1175,9 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte("branch"), - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte("branch"), + Descendants: 1, Children: [16]node.Node{ nil, &node.Leaf{Key: []byte{2}}, @@ -1186,11 +1186,11 @@ func Test_Trie_insert(t *testing.T) { key: []byte{1, 0}, value: []byte("leaf"), newNode: &node.Branch{ - Key: []byte{1}, - Value: []byte("branch"), - Generation: 1, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte("branch"), + Generation: 1, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ Key: []byte{}, @@ -1247,11 +1247,11 @@ func Test_Trie_insert(t *testing.T) { key: []byte{1, 0}, value: []byte("leaf"), newNode: &node.Branch{ - Key: []byte{1}, - Value: []byte("original leaf"), - Dirty: true, - Generation: 1, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte("original leaf"), + Dirty: true, + Generation: 1, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{}, @@ -1274,10 +1274,10 @@ func Test_Trie_insert(t *testing.T) { key: []byte{2, 3}, value: []byte("leaf"), newNode: &node.Branch{ - Key: []byte{}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(2), + Key: []byte{}, + Dirty: true, + Generation: 1, + Descendants: 2, Children: [16]node.Node{ nil, &node.Leaf{ @@ -1322,11 +1322,11 @@ func Test_Trie_insert(t *testing.T) { key: []byte{1}, value: []byte("leaf"), newNode: &node.Branch{ - Key: []byte{1}, - Value: []byte("leaf"), - Dirty: true, - Generation: 1, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte("leaf"), + Dirty: true, + Generation: 1, + Descendants: 1, Children: [16]node.Node{ nil, nil, &node.Leaf{ @@ -1369,9 +1369,9 @@ func Test_Trie_insertInBranch(t *testing.T) { }{ "update with branch": { parent: &node.Branch{ - Key: []byte{2}, - Value: []byte("old"), - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte("old"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1379,10 +1379,10 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{2}, value: []byte("new"), newNode: &node.Branch{ - Key: []byte{2}, - Value: []byte("new"), - Dirty: true, - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte("new"), + Dirty: true, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1390,9 +1390,9 @@ func Test_Trie_insertInBranch(t *testing.T) { }, "update with leaf": { parent: &node.Branch{ - Key: []byte{2}, - Value: []byte("old"), - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte("old"), + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1400,10 +1400,10 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{2}, value: []byte("new"), newNode: &node.Branch{ - Key: []byte{2}, - Value: []byte("new"), - Dirty: true, - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte("new"), + Dirty: true, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1411,9 +1411,9 @@ func Test_Trie_insertInBranch(t *testing.T) { }, "add leaf as direct child": { parent: &node.Branch{ - Key: []byte{2}, - Value: []byte{5}, - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte{5}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1421,10 +1421,10 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{2, 3, 4, 5}, value: []byte{6}, newNode: &node.Branch{ - Key: []byte{2}, - Value: []byte{5}, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{2}, + Value: []byte{5}, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, nil, nil, @@ -1439,14 +1439,14 @@ func Test_Trie_insertInBranch(t *testing.T) { }, "add leaf as nested child": { parent: &node.Branch{ - Key: []byte{2}, - Value: []byte{5}, - Stats: node.NewStats(2), + Key: []byte{2}, + Value: []byte{5}, + Descendants: 2, Children: [16]node.Node{ nil, nil, nil, &node.Branch{ - Key: []byte{4}, - Stats: node.NewStats(1), + Key: []byte{4}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1456,16 +1456,16 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{2, 3, 4, 5, 6}, value: []byte{6}, newNode: &node.Branch{ - Key: []byte{2}, - Value: []byte{5}, - Dirty: true, - Stats: node.NewStats(3), + Key: []byte{2}, + Value: []byte{5}, + Dirty: true, + Descendants: 3, Children: [16]node.Node{ nil, nil, nil, &node.Branch{ - Key: []byte{4}, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{4}, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, nil, nil, nil, nil, @@ -1482,9 +1482,9 @@ func Test_Trie_insertInBranch(t *testing.T) { }, "split branch for longer key": { parent: &node.Branch{ - Key: []byte{2, 3}, - Value: []byte{5}, - Stats: node.NewStats(1), + Key: []byte{2, 3}, + Value: []byte{5}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1492,16 +1492,16 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{2, 4, 5, 6}, value: []byte{6}, newNode: &node.Branch{ - Key: []byte{2}, - Dirty: true, - Stats: node.NewStats(3), + Key: []byte{2}, + Dirty: true, + Descendants: 3, Children: [16]node.Node{ nil, nil, nil, &node.Branch{ - Key: []byte{}, - Value: []byte{5}, - Dirty: true, - Stats: node.NewStats(1), + Key: []byte{}, + Value: []byte{5}, + Dirty: true, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1517,9 +1517,9 @@ func Test_Trie_insertInBranch(t *testing.T) { }, "split root branch": { parent: &node.Branch{ - Key: []byte{2, 3}, - Value: []byte{5}, - Stats: node.NewStats(1), + Key: []byte{2, 3}, + Value: []byte{5}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1527,16 +1527,16 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{3}, value: []byte{6}, newNode: &node.Branch{ - Key: []byte{}, - Dirty: true, - Stats: node.NewStats(3), + Key: []byte{}, + Dirty: true, + Descendants: 3, Children: [16]node.Node{ nil, nil, &node.Branch{ - Key: []byte{3}, - Value: []byte{5}, - Dirty: true, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{5}, + Dirty: true, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1552,9 +1552,9 @@ func Test_Trie_insertInBranch(t *testing.T) { }, "update with leaf at empty key": { parent: &node.Branch{ - Key: []byte{2}, - Value: []byte{5}, - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte{5}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1562,17 +1562,17 @@ func Test_Trie_insertInBranch(t *testing.T) { key: []byte{}, value: []byte{6}, newNode: &node.Branch{ - Key: []byte{}, - Value: []byte{6}, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{}, + Value: []byte{6}, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Branch{ - Key: []byte{}, - Value: []byte{5}, - Dirty: true, - Stats: node.NewStats(1), + Key: []byte{}, + Value: []byte{5}, + Dirty: true, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -1635,10 +1635,10 @@ func Test_Trie_LoadFromMap(t *testing.T) { }, expectedTrie: Trie{ root: &node.Branch{ - Key: []byte{00, 01}, - Value: []byte{6}, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{00, 01}, + Value: []byte{6}, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Leaf{ @@ -1658,10 +1658,10 @@ func Test_Trie_LoadFromMap(t *testing.T) { "override trie": { trie: Trie{ root: &node.Branch{ - Key: []byte{00, 01}, - Value: []byte{106}, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{00, 01}, + Value: []byte{106}, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ Value: []byte{9}, @@ -1682,10 +1682,10 @@ func Test_Trie_LoadFromMap(t *testing.T) { }, expectedTrie: Trie{ root: &node.Branch{ - Key: []byte{00, 01}, - Value: []byte{6}, - Dirty: true, - Stats: node.NewStats(3), + Key: []byte{00, 01}, + Value: []byte{6}, + Dirty: true, + Descendants: 3, Children: [16]node.Node{ &node.Leaf{ Value: []byte{9}, @@ -1735,12 +1735,12 @@ func Test_Trie_GetKeysWithPrefix(t *testing.T) { "some trie": { trie: Trie{ root: &node.Branch{ - Key: []byte{0, 1}, - Stats: node.NewStats(4), + Key: []byte{0, 1}, + Descendants: 4, Children: [16]node.Node{ &node.Branch{ // full key 0, 1, 0, 3 - Key: []byte{3}, - Stats: node.NewStats(2), + Key: []byte{3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ // full key 0, 1, 0, 0, 4 Key: []byte{4}, @@ -1793,8 +1793,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "common prefix for parent branch and search key": { parent: &node.Branch{ - Key: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -1809,8 +1809,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "parent branch and empty key": { parent: &node.Branch{ - Key: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -1825,8 +1825,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "search key smaller than branch key with no full common prefix": { parent: &node.Branch{ - Key: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -1838,8 +1838,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "common prefix smaller tan search key": { parent: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -1851,8 +1851,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "recursive call": { parent: &node.Branch{ - Key: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -1951,8 +1951,8 @@ func Test_addAllKeys(t *testing.T) { }, "parent branch without value": { parent: &node.Branch{ - Key: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -1966,9 +1966,9 @@ func Test_addAllKeys(t *testing.T) { }, "parent branch with empty value": { parent: &node.Branch{ - Key: []byte{1, 2, 3}, - Value: []byte{}, - Stats: node.NewStats(2), + Key: []byte{1, 2, 3}, + Value: []byte{}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{4}}, &node.Leaf{Key: []byte{5}}, @@ -2007,14 +2007,14 @@ func Test_Trie_Get(t *testing.T) { "some trie": { trie: Trie{ root: &node.Branch{ - Key: []byte{0, 1}, - Value: []byte{1, 3}, - Stats: node.NewStats(3), + Key: []byte{0, 1}, + Value: []byte{1, 3}, + Descendants: 3, Children: [16]node.Node{ &node.Branch{ // full key 0, 1, 0, 3 - Key: []byte{3}, - Value: []byte{1, 2}, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{1, 2}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2071,9 +2071,9 @@ func Test_retrieve(t *testing.T) { }, "branch key match": { parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{2}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{2}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2083,9 +2083,9 @@ func Test_retrieve(t *testing.T) { }, "branch key with empty search key": { parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{2}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{2}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2094,9 +2094,9 @@ func Test_retrieve(t *testing.T) { }, "branch key mismatch with shorter search key": { parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{2}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{2}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2105,15 +2105,15 @@ func Test_retrieve(t *testing.T) { }, "bottom leaf in branch": { parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ nil, nil, &node.Branch{ // full key 1, 2, 3 - Key: []byte{3}, - Value: []byte{2}, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{2}, + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, nil, &node.Leaf{ // full key 1, 2, 3, 4, 5 @@ -2164,9 +2164,9 @@ func Test_Trie_ClearPrefixLimit(t *testing.T) { "clear prefix limit": { trie: Trie{ root: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ nil, nil, nil, &node.Leaf{ @@ -2268,8 +2268,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { }, "branch without value parent with common prefix": { parent: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2283,8 +2283,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { }, "branch without value with key equal prefix": { parent: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2301,8 +2301,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2311,8 +2311,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 3}, limit: 1, newParent: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2325,8 +2325,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2335,8 +2335,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 2, 3}, limit: 1, newParent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2349,8 +2349,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2359,8 +2359,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 2}, limit: 1, newParent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2370,9 +2370,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { }, "branch with value with common prefix": { parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2385,9 +2385,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { }, "branch with value with key equal prefix": { parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2403,9 +2403,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2413,9 +2413,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 3}, limit: 1, newParent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2427,9 +2427,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2437,9 +2437,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 2, 3}, limit: 1, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2451,9 +2451,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2461,9 +2461,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 2}, limit: 1, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2475,9 +2475,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -2486,11 +2486,11 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1}, limit: 1, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Dirty: true, + Generation: 1, + Descendants: 1, Children: [16]node.Node{ nil, &node.Leaf{Key: []byte{4}}, @@ -2501,9 +2501,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { }, "delete only child of branch": { parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, }, @@ -2524,9 +2524,9 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -2545,8 +2545,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { }, "fully delete children of branch without value": { parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -2563,14 +2563,14 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(3), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 3, Children: [16]node.Node{ &node.Branch{ // full key 1, 0, 3 - Key: []byte{3}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 3, 0, 5 Key: []byte{5}, @@ -2585,11 +2585,11 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { prefix: []byte{1, 0}, limit: 1, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Dirty: true, + Generation: 1, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 3 Key: []byte{3}, @@ -2611,14 +2611,14 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Branch{ // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, }, @@ -2642,8 +2642,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -2665,8 +2665,8 @@ func Test_Trie_clearPrefixLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -2739,7 +2739,7 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, "delete branch without value": { parent: &node.Branch{ - Stats: node.NewStats(2), + Descendants: 2, Children: [16]node.Node{ &node.Leaf{}, &node.Leaf{}, @@ -2751,9 +2751,9 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, "delete branch with value": { parent: &node.Branch{ - Key: []byte{3}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -2764,8 +2764,8 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, "delete branch and all children": { parent: &node.Branch{ - Key: []byte{3}, - Stats: node.NewStats(2), + Key: []byte{3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2780,9 +2780,9 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{3}, - Value: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{3}, + Value: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2790,11 +2790,11 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, limit: 1, newNode: &node.Branch{ - Key: []byte{3}, - Value: []byte{1, 2, 3}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{1, 2, 3}, + Dirty: true, + Generation: 1, + Descendants: 1, Children: [16]node.Node{ nil, &node.Leaf{Key: []byte{2}}, @@ -2808,9 +2808,9 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{3}, - Value: []byte{1, 2, 3}, - Stats: node.NewStats(2), + Key: []byte{3}, + Value: []byte{1, 2, 3}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{1}}, &node.Leaf{Key: []byte{2}}, @@ -2831,8 +2831,8 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{3}, - Stats: node.NewStats(3), + Key: []byte{3}, + Descendants: 3, Children: [16]node.Node{ nil, &node.Leaf{Key: []byte{1}}, @@ -2898,8 +2898,8 @@ func Test_Trie_ClearPrefix(t *testing.T) { "clear prefix": { trie: Trie{ root: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(3), + Key: []byte{1, 2}, + Descendants: 3, Children: [16]node.Node{ &node.Leaf{ // full key in nibbles 1, 2, 0, 5 Key: []byte{5}, @@ -2961,8 +2961,8 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -3017,9 +3017,9 @@ func Test_Trie_clearPrefix(t *testing.T) { }, "branch parent with common prefix": { parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -3029,9 +3029,9 @@ func Test_Trie_clearPrefix(t *testing.T) { }, "branch with key equal prefix": { parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -3044,18 +3044,18 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, }, prefix: []byte{1, 3}, newParent: &node.Branch{ - Key: []byte{1, 2}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1, 2}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -3066,18 +3066,18 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, }, prefix: []byte{1, 2, 3}, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -3088,18 +3088,18 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, }, prefix: []byte{1, 2}, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -3110,9 +3110,9 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, &node.Leaf{Key: []byte{4}}, @@ -3120,11 +3120,11 @@ func Test_Trie_clearPrefix(t *testing.T) { }, prefix: []byte{1, 0, 3}, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Dirty: true, + Generation: 1, + Descendants: 1, Children: [16]node.Node{ nil, &node.Leaf{Key: []byte{4}}, @@ -3137,9 +3137,9 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, }, @@ -3158,14 +3158,14 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Branch{ // full key 1, 0, 3 - Key: []byte{3}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{3}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 3, 0, 5 Key: []byte{5}, @@ -3176,11 +3176,11 @@ func Test_Trie_clearPrefix(t *testing.T) { }, prefix: []byte{1, 0, 3, 0}, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Dirty: true, + Generation: 1, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 3 Key: []byte{3}, @@ -3197,8 +3197,8 @@ func Test_Trie_clearPrefix(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{3}}, // full key 1, 0, 3 &node.Leaf{Key: []byte{4}}, // full key 1, 1, 4 @@ -3257,17 +3257,17 @@ func Test_Trie_Delete(t *testing.T) { trie: Trie{ generation: 1, root: &node.Branch{ - Key: []byte{1, 2}, - Stats: node.NewStats(3), + Key: []byte{1, 2}, + Descendants: 3, Children: [16]node.Node{ &node.Leaf{ Key: []byte{5}, Value: []byte{97}, }, &node.Branch{ // full key in nibbles 1, 2, 1, 6 - Key: []byte{6}, - Value: []byte{98}, - Stats: node.NewStats(1), + Key: []byte{6}, + Value: []byte{98}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key in nibbles 1, 2, 1, 6, 0, 7 Key: []byte{7}, @@ -3282,10 +3282,10 @@ func Test_Trie_Delete(t *testing.T) { expectedTrie: Trie{ generation: 1, root: &node.Branch{ - Key: []byte{1, 2}, - Dirty: true, - Generation: 1, - Stats: node.NewStats(2), + Key: []byte{1, 2}, + Dirty: true, + Generation: 1, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{ Key: []byte{5}, @@ -3377,9 +3377,9 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{2}, @@ -3399,9 +3399,9 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{2}, @@ -3422,9 +3422,9 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ Key: []byte{2}, @@ -3445,9 +3445,9 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 2 Key: []byte{2}, @@ -3469,18 +3469,18 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, }, key: []byte{2}, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{}, }, @@ -3491,9 +3491,9 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 2 Key: []byte{2}, @@ -3502,9 +3502,9 @@ func Test_Trie_delete(t *testing.T) { }, key: []byte{1, 0, 3}, newParent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 2 Key: []byte{2}, @@ -3517,8 +3517,8 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Stats: node.NewStats(1), + Key: []byte{1}, + Descendants: 1, Children: [16]node.Node{ &node.Leaf{ // full key 1, 0, 2 Key: []byte{2}, @@ -3545,9 +3545,9 @@ func Test_Trie_delete(t *testing.T) { generation: 1, }, parent: &node.Branch{ - Key: []byte{1}, - Value: []byte{1}, - Stats: node.NewStats(2), + Key: []byte{1}, + Value: []byte{1}, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{2}}, &node.Leaf{Key: []byte{2}}, @@ -3555,10 +3555,10 @@ func Test_Trie_delete(t *testing.T) { }, key: []byte{1}, newParent: &node.Branch{ - Key: []byte{1}, - Generation: 1, - Dirty: true, - Stats: node.NewStats(2), + Key: []byte{1}, + Generation: 1, + Dirty: true, + Descendants: 2, Children: [16]node.Node{ &node.Leaf{Key: []byte{2}}, &node.Leaf{Key: []byte{2}},