-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree configuration #138
base: master
Are you sure you want to change the base?
Tree configuration #138
Conversation
We don't need an interface (yet), since there is only one implementation. A client (user) of the package can easily add its own interface as necessary.
This makes the test data specify the label: number to make it more readable; it is hard to map the four numbers to the field name of original createTreeTest type.
We only need to store the IDs once; the index into the ID slice represents that ID's position in the tree. I think it will be faster for small trees to do this approach; we may consider to add a benchmark to find the breaking point where it is faster to use a map for this. If a map is needed for larger trees for speed, we could consider to revert this change, or allocate the map only if the tree is actually large.
trees/treeconfig.go
Outdated
} | ||
|
||
// GetHeight returns the height of the replica | ||
func (t *Tree) GetHeight() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to export this? That is, will we use it in the code outside the tree
package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was useful to me for timer computation
trees/treeconfig.go
Outdated
} | ||
|
||
// GetSubTreeNodes returns all the nodes of its subtree. | ||
func (t *Tree) GetSubTreeNodes() []hotstuff.ID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename it to SubTree()
.
// SubTree returns the subtree of the tree's replica.
trees/treeconfig.go
Outdated
queue = append(queue, children...) | ||
subTreeNodes = append(subTreeNodes, children...) | ||
if len(children) == 0 { | ||
return subTreeNodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also be empty slice, if len(children) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no children means, it is a leaf node hence empty subtree
trees/treeconfig.go
Outdated
if len(children) == 0 { | ||
return subTreeNodes | ||
} | ||
for len(queue) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the logic. I need to dig deeper. But perhaps it would make sense to use the std lib slices
package for some of these things?
Maybe you could add a comment or two to explain the idea.
create trees from position slice