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

Number of elements in trie #29

Open
LucaCappelletti94 opened this issue Apr 15, 2024 · 7 comments
Open

Number of elements in trie #29

LucaCappelletti94 opened this issue Apr 15, 2024 · 7 comments

Comments

@LucaCappelletti94
Copy link
Contributor

Hi, I am not sure whether there is a method in the trie that returns the number of elements in the trie. Is there?

@shanecelis
Copy link
Collaborator

You could search for "" and count the iterator.

@LucaCappelletti94
Copy link
Contributor Author

Maybe it would be best to add a counter in the Map struct? Like in a Vec.

@shanecelis
Copy link
Collaborator

I don't see the use case where knowing the size in O(1) time is worth it. You generally don't want to reify it, so it's not like you need to know to preallocate. Most searches will always be a different size but it would represent an upper bound. Is there a use case you had in mind?

@LucaCappelletti94
Copy link
Contributor Author

Generally speaking, I would expect the length of a set to be an O(1) complexity thing, especially since it only requires an usize. As a tradeoff time vs memory, it would seem worth it to me.

@shanecelis
Copy link
Collaborator

All right. Let's see it.

@LucaCappelletti94
Copy link
Contributor Author

I will make a small pull request adding it after we finish merging #28

@shanecelis
Copy link
Collaborator

I've gone from hesitant to, "Yes, this is all good and makes sense."

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

No branches or pull requests

2 participants