Class IntShortMap

java.lang.Object
java.util.AbstractMap<Integer,Short>
net.solarnetwork.util.IntShortMap
All Implemented Interfaces:
Cloneable, Map<Integer,Short>, IntShortOrderedIterable

public class IntShortMap extends AbstractMap<Integer,Short> implements Map<Integer,Short>, IntShortOrderedIterable, Cloneable
A map implementation optimized for sparse array like storage of integer keys with associated short values.

This implementation is optimized for small sizes and appending keys in ascending order. Random mutations trigger array copies that can slow performance down considerably. Accessing values run in O(log n) time. Keys are maintained in ascending order, so iteration occurs also in ascending order.

Since:
1.58
Version:
1.0
Author:
matt
  • Field Details

    • DEFAULT_INITIAL_CAPACITY

      public static final int DEFAULT_INITIAL_CAPACITY
      The default initial capacity.
      See Also:
    • VALUE_NO_SUCH_ELEMENT

      public static final short VALUE_NO_SUCH_ELEMENT
      The default value that causes NoSuchElementException to be thrown in getValue(int).
      See Also:
  • Constructor Details

    • IntShortMap

      public IntShortMap()
      Default constructor.

      Defaults to returning 0 for nonexistent keys in getValue(int).

    • IntShortMap

      public IntShortMap(int initialCapacity)
      Constructor.

      Defaults to returning 0 for nonexistent keys in getValue(int).

      Parameters:
      initialCapacity - the initial capacity
      Throws:
      IllegalArgumentException - if initialCapacity is less than 1
    • IntShortMap

      public IntShortMap(int initialCapacity, short notFoundValue)
      Constructor.
      Parameters:
      initialCapacity - the initial capacity
      notFoundValue - the value to return in getValue(int) if a key is not found, or VALUE_NO_SUCH_ELEMENT to throw a NoSuchElementException
      Throws:
      IllegalArgumentException - if initialCapacity is less than 1
  • Method Details