Class ArrayMap<Key,Value>

java.lang.Object
com.iu.javadatastructureslab.datastructures.ArrayMap<Key,Value>
Type Parameters:
Key - key type
Value - value type

public class ArrayMap<Key,Value> extends Object
Simple hash map implementation backed by an array of buckets.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty ArrayMap with the default capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the current bucket array length.
    boolean
    Returns true if the map contains a key-value pair with the given key.
    Returns a list of all entries in the map.
    get(Key key)
    Retrieves the value for the given key.
    void
    put(Key key, Value value)
    Associates the given value with the provided key.
    void
    remove(Key key)
    Removes the key-value pair associated with the given key.
    int
    Returns the number of stored entries.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayMap

      public ArrayMap()
      Creates an empty ArrayMap with the default capacity.
  • Method Details

    • put

      public void put(Key key, Value value)
      Associates the given value with the provided key.
      Parameters:
      key - key to store
      value - value to store
    • get

      public Value get(Key key)
      Retrieves the value for the given key.
      Parameters:
      key - key to lookup
      Returns:
      stored value or null if missing
    • remove

      public void remove(Key key)
      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

      public boolean containsKey(Key key)
      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

      public List<Entry<Key,Value>> entryList()
      Returns a list of all entries in the map.
      Returns:
      list of entries