Class SortedIntMap<V>

java.lang.Object
com.deco2800.game.utils.SortedIntMap<V>
Type Parameters:
V - Class type to map
All Implemented Interfaces:
Iterable<V>

public class SortedIntMap<V> extends Object implements Iterable<V>
A map sorted by the value of key with O(1) iteration. put/get/contains are O(n). useful when we don't modify values often, but want to iterate quickly.
  • Constructor Details

    • SortedIntMap

      public SortedIntMap(int capacity)
      Create a sorted intmap with the specified capacity
      Parameters:
      capacity - initial capacity
  • Method Details

    • containsKey

      public boolean containsKey(int key)
      Parameters:
      key - map key
      Returns:
      true if map contains key
    • contains

      public boolean contains(V value)
      Parameters:
      value - value in map
      Returns:
      true if map contains value
    • put

      public void put(int key, V value)
      Put key, value pair in map
      Parameters:
      key - key
      value - value
    • get

      public V get(int key)
      Get value from map
      Parameters:
      key - map key
      Returns:
      map value or null if not found
    • clear

      public void clear()
      Clear the map
    • iterator

      public Iterator<V> iterator()
      Specified by:
      iterator in interface Iterable<V>
    • forEach

      public void forEach(Consumer<? super V> action)
      Specified by:
      forEach in interface Iterable<V>
    • spliterator

      public Spliterator<V> spliterator()
      Specified by:
      spliterator in interface Iterable<V>