Sometimes, as a developer, you want to store key-value pairs. For example you may want to access a user object by its username. The best suited d...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Jan,
thank you for sharing yours insight here :)
I would just like to add that the map implementation you have shown (which of course is a very simple one) is not O(1) for insert and lookup, as it might iterate the whole list whole finding a spot. This approach also requires a lot of work when removing items, as you have to fill gaps that might arise. But with a good hash function, maps of course can have an average case order of one, as collisions are rare compared to the number of items already in the map.
Philip
Yeah, linear hashing is a simple but rather weak avoidance strategy.
Hashing is also not the only common implementation of an abstract map. There's also variants on the binary search tree.
The above implementation sucks, by the way. I don't think it's valid TypeScript, and it isn't self-balancing so it has average-case O(log n) lookup and worst-case O(n) lookup.
Yeah, Haskell uses balanced binary trees for example