tiborschneider / prefix-trie

Apache License 2.0
20 stars 4 forks source link

Add `len` method #6

Closed scotow closed 6 months ago

scotow commented 6 months ago

It would be nice to have a O(1) method to get the number of elements in the Map/Set the same way it is done in the std for HashMap and HashSet.

It's possible to get it in O(n) using iter().count() but could be costly if needed frequently on large Map/Set.

tiborschneider commented 6 months ago

I think we could add a counter variable. But this variable would need to be updated properly. Functions like remove_children must be handled with care. I am looking into that. I agree that it would be very useful!

tiborschneider commented 6 months ago

Closing this issue now, as #7 was merged.

scotow commented 6 months ago

Thanks!