r/ProgrammerTIL • • Oct 22 '17

Other [Java] HashSet<T> just uses HashMap<T, Object> behind the scenes

76 Upvotes

35 comments sorted by

View all comments

Show parent comment

7

u/blazedaces Oct 22 '17

Do you know of any languages that implement it that way? Most languages that I can think of off the top of my head consider a hashtable to be a simpler data structure and implement set either as a hashtable or a binary tree. Examples include Java, c++, python, Haskell.

2

u/xonjas Oct 22 '17

Ruby uses hashes under the hood also.

Sets are tables with constraints added, it makes sense to use tables to implement them.