Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 18, 2022
1 parent 73b4713 commit d2235bb
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 78 deletions.
1 change: 1 addition & 0 deletions internal/trie/node/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Branch struct {
// inserted, moved or iterated over.
Generation uint64
sync.RWMutex
Stats Stats
}

// NewBranch creates a new branch using the arguments given.
Expand Down
23 changes: 23 additions & 0 deletions internal/trie/node/stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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
}

// GetDescendants returns the number of descendants in the branch.
func (b *Branch) GetDescendants() (descendants uint32) {
return b.Stats.Descendants
}

// AddDescendants adds descendant nodes count to the node stats.
func (b *Branch) AddDescendants(n uint32) {
b.Stats.Descendants += n
}

// SubDescendants subtracts descendant nodes count from the node stats.
func (b *Branch) SubDescendants(n uint32) {
b.Stats.Descendants -= n
}
1 change: 1 addition & 0 deletions internal/trie/node/stats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package node
Loading

0 comments on commit d2235bb

Please sign in to comment.