Hash Maps/AbstractHashMap
From charlesreid1
Notes
Start by defining an interface for the Map ADT (Map.java).
Next, define an abstract class to lay out some useful methods, fields, and utility classes (AbstractMap.java).
The process of defining the abstract map:
- Needed to define a map item wrapper class
- This is designed to take a K,V key value pair
- Also need to define four more classes:
- Two Iterators and two Iterables
Iterators vs Iterables - ?
- Map key Iterator object
- Map value Iterator object
- Map key Iterable object (?) - thought I understood this, but maybe not?
- Map value Iterable object (?)
- The Iterator objects are like mini-scanners.
- The Iterable objects just have an iterator() method and are what are actually returned.
itemSet:
- Note that the key and value sets use the itemSet method
- We aren't defining itemSet, just using it
- itemSet must be defined in our concrete class
- This means we have three total Iterators and three total Iterables
More iterators vs iterables:
- Iterable just says, I return an Iterator. it is part of the core language.
- Iterator has to be defined for each container.
Exceptions:
- NoSuchElementException
- UnsupportedOperationException
- Don't forget to check for size!
- Especially if you are not wraapping someone else's iterator
Ordering of class declaration and undeclared class declarations
- I could not use MapItem class undefined in the Map interface (most generic of all)
- MapItem class was actually protected and lived in AbstractMap class
- Therefore, we had to hold off declaring an abstract MapItem iterator until the AbstractMap class, not the Map interface
Flags
| Maps and Dictionaries Part of Computer Science Notes
Series on Data Structures
Maps/Dictionaries Maps · Maps/ADT · Maps in Java · Maps/OOP · Maps/Operations and Performance Map implementations: Maps/AbstractMap · Maps/UnsortedArrayMap · Maps/SortedArrayMap Dictionary implementations: Dictionaries/LinkedDict · Dictionaries/ArrayDict
Hashes Hash Maps/OOP · Hash Maps/Operations and Performance Hash Maps/Dynamic Resizing · Hash Maps/Collision Handling with Chaining Hash functions: Hash Functions · Hash Functions/Cyclic Permutation Hash map implementations: Hash Maps/AbstractHashMap · Hash Maps/ChainedHashMap
Skip Lists · Java/ConcurrentSkipList · Java implementations: SkipList
Sets Sets · Sets/ADT · Sets in Java · Sets/OOP · Multisets
|