Skip to content

Conversation

@hanish520
Copy link
Contributor

create trees from position slice

hanish520 and others added 5 commits December 21, 2024 23:48
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.
hanish520 and others added 21 commits December 23, 2024 00:21
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.
This avoids the use of math.Pow in a loop. Does not matter much,
but it is an easy fix and makes the code easier to read as well.
This makes it clearer that it refers to tree positions and the
"To" word implies that it is a mapping to an "ID".
This avoids having to provide a lessFunc.
meling added 2 commits January 3, 2025 00:06
I removed the "currently only fault free tree config is supported"
comment; don't feel it provides enough context -- at least not yet.
Copy link
Member

@meling meling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a bunch of comments that I had forgotten to submit a review for. Sorry about that. I fixed most of them already just now, but there are two remaining issues. Could you please fix them.

@meling meling merged commit 12f6c66 into master Jan 5, 2025
4 checks passed
@meling meling deleted the trees branch January 5, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants