-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
It is somewhat unfortunate that size is O(n) for HashMap and HashSet:
-
If a faster
sizeis desired, I have to store it separately in my code and make sure that I update it whenever I do aninsertordelete. With filtering functions,union, etc. it gets even more cumbersome. -
Even experienced programmers often assume that
sizeis O(1) without checking, which leads to performance bugs :(
(I have looked at the code, but I have to confess that I don't understand how HashMap/Set work and so it's hard for me to assess how much of a performance/memory penalty adding a size field to the constructors would be, or whether it is possible at all.)
chshersh, rockbmb and pepeiborra