Skip to content
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

Addition getters for leafs #43

Closed
Amxx opened this issue Feb 28, 2024 · 0 comments · Fixed by #44
Closed

Addition getters for leafs #43

Amxx opened this issue Feb 28, 2024 · 0 comments · Fixed by #44

Comments

@Amxx
Copy link
Contributor

Amxx commented Feb 28, 2024

The MerkleTree class currently provides mechanism to:

  • get hash of a leaf: leafHash(leaf: T): HexString;
  • get the index of a leaf: leafLookup(leaf: T): number;
  • get an iterator to all leaves (with index): entries(): Iterable<[number, T]>;

What we don't have is:

  • a way to get a leaf value given its index.
  • a way to get the number of leaves.

Both are directly in tree.values, but it is marked as protected readonly, probably because it also contains the treeIndex which should remain hidden.

I propose we add:

  • at(number): T | undefined that gives the value of node at a given position (name?).
  • length(): number that returns the number of leaves in the tree (name?).
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 a pull request may close this issue.

1 participant