Package com.deco2800.game.utils
Class SortedIntMap<V>
java.lang.Object
com.deco2800.game.utils.SortedIntMap<V>
- Type Parameters:
V- Class type to map
- All Implemented Interfaces:
java.lang.Iterable<V>
public class SortedIntMap<V>
extends java.lang.Object
implements java.lang.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 Summary
Constructors Constructor Description SortedIntMap(int capacity)Create a sorted intmap with the specified capacity -
Method Summary
Modifier and Type Method Description voidclear()Clear the mapbooleancontains(V value)booleancontainsKey(int key)voidforEach(java.util.function.Consumer<? super V> action)Vget(int key)Get value from mapjava.util.Iterator<V>iterator()voidput(int key, V value)Put key, value pair in mapjava.util.Spliterator<V>spliterator()
-
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
- Parameters:
value- value in map- Returns:
- true if map contains value
-
put
Put key, value pair in map- Parameters:
key- keyvalue- value
-
get
Get value from map- Parameters:
key- map key- Returns:
- map value or null if not found
-
clear
public void clear()Clear the map -
iterator
- Specified by:
iteratorin interfacejava.lang.Iterable<V>
-
forEach
- Specified by:
forEachin interfacejava.lang.Iterable<V>
-
spliterator
- Specified by:
spliteratorin interfacejava.lang.Iterable<V>
-