-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trie code tracks number of descendants for each node
- `clearPrefix`: use `nodesRemoved == 0` instead of `updated` bool - Add more test cases - Remove old irrelevant `TODO` - Print descendants in node String methods - Add descendants check fuzz test
- Loading branch information
Showing
13 changed files
with
977 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2022 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package node | ||
|
||
// GetDescendants returns the number of descendants in the branch. | ||
func (b *Branch) GetDescendants() (descendants uint32) { | ||
return b.Descendants | ||
} | ||
|
||
// AddDescendants adds descendant nodes count to the node stats. | ||
func (b *Branch) AddDescendants(n uint32) { | ||
b.Descendants += n | ||
} | ||
|
||
// SubDescendants subtracts descendant nodes count from the node stats. | ||
func (b *Branch) SubDescendants(n uint32) { | ||
b.Descendants -= n | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022 ChainSafe Systems (ON) | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
package node | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Branch_GetDescendants(t *testing.T) { | ||
t.Parallel() | ||
|
||
const descendants uint32 = 10 | ||
branch := &Branch{ | ||
Descendants: descendants, | ||
} | ||
result := branch.GetDescendants() | ||
|
||
assert.Equal(t, descendants, result) | ||
} | ||
|
||
func Test_Branch_AddDescendants(t *testing.T) { | ||
t.Parallel() | ||
|
||
const ( | ||
initialDescendants uint32 = 10 | ||
addDescendants uint32 = 2 | ||
finalDescendants uint32 = 12 | ||
) | ||
branch := &Branch{ | ||
Descendants: initialDescendants, | ||
} | ||
branch.AddDescendants(addDescendants) | ||
expected := &Branch{ | ||
Descendants: finalDescendants, | ||
} | ||
|
||
assert.Equal(t, expected, branch) | ||
} | ||
|
||
func Test_Branch_SubDescendants(t *testing.T) { | ||
t.Parallel() | ||
|
||
const ( | ||
initialDescendants uint32 = 10 | ||
subDescendants uint32 = 2 | ||
finalDescendants uint32 = 8 | ||
) | ||
branch := &Branch{ | ||
Descendants: initialDescendants, | ||
} | ||
branch.SubDescendants(subDescendants) | ||
expected := &Branch{ | ||
Descendants: finalDescendants, | ||
} | ||
|
||
assert.Equal(t, expected, branch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.