Package com.csse3200.game.utils
Class SortedIntMap<V>
java.lang.Object
com.csse3200.game.utils.SortedIntMap<V>
- Type Parameters:
V
- Class type to map
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionSortedIntMap
(int capacity) Create a sorted intmap with the specified capacity -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the mapboolean
boolean
containsKey
(int key) void
get
(int key) Get value from mapint
getKeyAt
(int index) Get the map key at a given indexgetValueAt
(int index) Get the value at the given indexiterator()
void
Put key, value pair in mapint
size()
Get number of keys
-
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
-
size
public int size()Get number of keys- Returns:
- number of keys
-
getKeyAt
public int getKeyAt(int index) Get the map key at a given index- Parameters:
index
- index- Returns:
- map key
-
getValueAt
Get the value at the given index- Parameters:
index
- index- Returns:
- value from map
-
clear
public void clear()Clear the map -
iterator
-
forEach
-
spliterator
- Specified by:
spliterator
in interfaceIterable<V>
-