Class ArrayMap<Key,Value>
java.lang.Object
com.iu.javadatastructureslab.datastructures.ArrayMap<Key,Value>
- Type Parameters:
Key- key typeValue- value type
Simple hash map implementation backed by an array of buckets.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Returns the current bucket array length.booleancontainsKey(Key key) Returns true if the map contains a key-value pair with the given key.Returns a list of all entries in the map.Retrieves the value for the given key.voidAssociates the given value with the provided key.voidRemoves the key-value pair associated with the given key.intsize()Returns the number of stored entries.
-
Constructor Details
-
ArrayMap
public ArrayMap()Creates an empty ArrayMap with the default capacity.
-
-
Method Details
-
put
Associates the given value with the provided key.- Parameters:
key- key to storevalue- value to store
-
get
Retrieves the value for the given key.- Parameters:
key- key to lookup- Returns:
- stored value or null if missing
-
remove
Removes the key-value pair associated with the given key.- Parameters:
key- the key to remove from the map- Throws:
IllegalArgumentException- if the key is not found in the map
-
containsKey
Returns true if the map contains a key-value pair with the given key.- Parameters:
key- the key to check for in the map- Returns:
- true if the map contains a key-value pair with the given key
-
size
public int size()Returns the number of stored entries.- Returns:
- entry count
-
capacity
public int capacity()Returns the current bucket array length.- Returns:
- bucket capacity
-
entryList
Returns a list of all entries in the map.- Returns:
- list of entries
-