Package dsa.lab05.exercises
Class ChainingHashMap<Key,Value>
java.lang.Object
dsa.lab05.exercises.ChainingHashMap<Key,Value>
- Type Parameters:
Key
- the key typeValue
- the value type
- All Implemented Interfaces:
Container<MapItem<Key,
,Value>> Map<Key,
,Value> Iterable<MapItem<Key,
Value>>
A chaining hash map.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty chaining hash map.ChainingHashMap
(MapItem<Key, Value>... items) Construct a chaining hash map containing the given items.ChainingHashMap
(Iterable<MapItem<Key, Value>> items) Construct a chaining hash map containing the given items.ChainingHashMap
(Iterable<MapItem<Key, Value>> items, int size) Construct a chaining hash map containing the given items more efficiently thanChainingHashMap(Iterable)
. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface dsa.lab04.base.Map
containsKey, containsValue, get, insert, keys, values
-
Constructor Details
-
ChainingHashMap
public ChainingHashMap()Construct an empty chaining hash map. -
ChainingHashMap
Construct a chaining hash map containing the given items.- Parameters:
items
- the items
-
ChainingHashMap
public ChainingHashMap(Iterable<MapItem<Key, Value>> items, int size) throws IllegalArgumentExceptionConstruct a chaining hash map containing the given items more efficiently thanChainingHashMap(Iterable)
.- Parameters:
items
- the itemssize
- the number of items- Throws:
IllegalArgumentException
- ifsize
!=n
(wheren
isitems
's size)
-
ChainingHashMap
Construct a chaining hash map containing the given items.- Parameters:
items
- the items
-
-
Method Details
-
size
public int size()Description copied from interface:Container
Get the number of contained items. -
find
Description copied from interface:Map
Find the item with the given key.- Specified by:
find
in interfaceMap<Key,
Value> - Parameters:
key
- the item's key- Returns:
- the item
- Throws:
NoSuchElementException
- if no item has keykey
-
insert
Description copied from interface:Map
Insert the given item.If there's already an item with the same key, that item is replaced with this one.
This means that if the key was not already contained, the size is incremented, otherwise it isn't.
-
remove
Description copied from interface:Map
Remove and return the item with the given key.Decrements the size (assuming the item was actually in the map).
- Specified by:
remove
in interfaceMap<Key,
Value> - Parameters:
key
- the item's key- Returns:
- the item
- Throws:
NoSuchElementException
- ifkey
is not contained
-
items
Description copied from interface:Container
Get an iterable that yields each item once.
-