roma-glushko / romaglushkocom-discussions

0 stars 0 forks source link

blog/design-lru-cache/ #3

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Design LRU Cache - Blog by Roman Glushko

Have fun designing least-recently-used cache in Python

https://www.romaglushko.com/blog/design-lru-cache/

josueadelima commented 1 year ago

Great article!! I have question, since we are not using a function to generate an index, shouldn't we call it HashMap instead of HashTable?

roma-glushko commented 1 year ago

Hey @josueadelima Josué thank you ❤️ In my mind, hashtable, hashmap, dict (in Python case), map (in Golang case), mapping are names for pretty much the same data structure. Do you see differences? Would interesting to learn more on that.

josueadelima commented 1 year ago

Hi, my thinking is that even if their purpose is the same (O(1) time access), for the case of a HashTable, you'll be using a function that generates an index of an array (at least in ruby you don't have a library so you always implement this), for the case of hashmap (hash in ruby) or dict (set in ruby), I see them as part of the language, thats why I like to make a distinction between them. Even with hashmap and set, you have a difference, while one have key->value, the other use only key.

I found your article very useful, but is not strictly using a HashTable, and to not confuse somebody learning, I thought it would be better to name it as hashmap.