-
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
Open
hanish520
wants to merge
21
commits into
master
Choose a base branch
from
trees
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tree configuration #138
Conversation
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
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.
meling
requested changes
Dec 22, 2024
meling
reviewed
Dec 22, 2024
This moves the code to compute the height together rather than splitting it with code for argument checks. This makes it easier to see that computing the height could be moved to a external function if it was ever necessary to do separately.
In Go we try to avoid using the Get prefix.
We don't need to check that t.id's position isn't -1 since we do that check in CreateTree, so we would never get -1 here.
NodeChildren returns this tree's replica's children, while the ChildrenOf(node) returns the node's children. This also removes an unnecessary allocation; we can return nil instead of an empty slice of IDs.
NodeHeight returns the height of this tree's replica's height.
We can return a subsclice of the original to avoid allocating.
The math.Pow calls in a loop can be slow; this should be faster.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
create trees from position slice