From charlesreid1

No edit summary
No edit summary
 
Line 5: Line 5:
The Set class should not just blindly use the HashMap, however, as the HashMap allocates space for both keys and values, and all we need to implement a set are the values.  
The Set class should not just blindly use the HashMap, however, as the HashMap allocates space for both keys and values, and all we need to implement a set are the values.  


As in mathematics, the Set type can be thought of as an elemental building block of more complex objects. For example, Justin Wetherell @phishman3579 on github implemented several data structures in Java (Link: https://github.com/phishman3579/java-algorithms-implementation), but one he did not implement was the Set type. For that data structure, the library relied on the Java API's HashSet, TreeSet, and AbstractSet classes.
As in mathematics, the Set type can be thought of as an elemental building block of more complex objects. For example, @phishman3579 on github implemented several data structures in Java (Link: https://github.com/phishman3579/java-algorithms-implementation), but one he did not implement was the Set type. Instead, his library relies on the Java API's HashSet, TreeSet, and AbstractSet classes.  
 





Latest revision as of 13:42, 10 September 2017

Sets can utilize many of the same OOP features during implementation that Maps do (see Maps/OOP).

However, one important feature is that sets can be implemented using nothing more than a hash table or hash map, where the value itself is its own key. This enables the definition of a Set class, whose interface may be entirely different from a map or a hash table, but which nevertheless utilizes these data structures under the hood.

The Set class should not just blindly use the HashMap, however, as the HashMap allocates space for both keys and values, and all we need to implement a set are the values.

As in mathematics, the Set type can be thought of as an elemental building block of more complex objects. For example, @phishman3579 on github implemented several data structures in Java (Link: https://github.com/phishman3579/java-algorithms-implementation), but one he did not implement was the Set type. Instead, his library relies on the Java API's HashSet, TreeSet, and AbstractSet classes.