Package dsa.lab06.exercises
Class ProbingHashMap<Key,Value>
java.lang.Object
dsa.lab06.exercises.ProbingHashMap<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 (linearly-)probing hash map.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty probing hash map.ProbingHashMap(MapItem<Key, Value>... items) Construct a probing hash map containing the given items.ProbingHashMap(Iterable<MapItem<Key, Value>> items) Construct a probing hash map containing the given items.ProbingHashMap(Iterable<MapItem<Key, Value>> items, int size) Construct a probing hash map containing the given items more efficiently thanProbingHashMap(Iterable). -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface dsa.lab04.base.Map
containsKey, containsValue, get, insert, keys, values
-
Constructor Details
-
ProbingHashMap
public ProbingHashMap()Construct an empty probing hash map. -
ProbingHashMap
Construct a probing hash map containing the given items.- Parameters:
items- the items
-
ProbingHashMap
Construct a probing hash map containing the given items more efficiently thanProbingHashMap(Iterable).- Parameters:
items- the itemssize- the number of items- Throws:
IllegalArgumentException- ifsize!=n(wherenisitems's size)
-
ProbingHashMap
Construct a probing hash map containing the given items.- Parameters:
items- the items
-
-
Method Details
-
size
public int size()Description copied from interface:ContainerGet the number of contained items. -
insert
Description copied from interface:MapInsert 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.
-
find
Description copied from interface:MapFind the item with the given key.- Specified by:
findin interfaceMap<Key,Value> - Parameters:
key- the item's key- Returns:
- the item
- Throws:
NoSuchElementException- if no item has keykey
-
remove
Description copied from interface:MapRemove and return the item with the given key.Decrements the size (assuming the item was actually in the map).
- Specified by:
removein interfaceMap<Key,Value> - Parameters:
key- the item's key- Returns:
- the item
- Throws:
NoSuchElementException- ifkeyis not contained
-
items
Description copied from interface:ContainerGet an iterable that yields each item once.
-