Class SortedTableMap<K,V>
- java.lang.Object
-
- AbstractMap<K,V>
-
- AbstractSortedMap<K,V>
-
- SortedTableMap<K,V>
-
- All Implemented Interfaces:
- Map<K,V>
public class SortedTableMap<K,V> extends AbstractSortedMap<K,V>
An implementation of a map using a sorted table. All accessors run in O(log n) worst-case time, other than subMap, which runs in O(s + log n) where s is the size of the resulting submap, and the complete iterations that run in O(n) time. TODO: Finish implementation
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.MapEntry<K,V>
-
-
Constructor Summary
Constructors Constructor and Description SortedTableMap()
Constructs an empty map using the natural ordering of keys.SortedTableMap(java.util.Comparator<K> comp)
Constructs an empty map using the given comparator to order keys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Iterable<Entry<K,V>>
entrySet()
Returns an iterable collection of all key-value entries of the map.V
get(K key)
Returns the value associated with the specified key, or null if no such entry exists.V
put(K key, V value)
Associates the given value with the given key.V
remove(K key)
Removes the entry with the specified key, if present, and returns its associated value.int
size()
Returns the number of entries in the map.-
Methods inherited from class AbstractMap
isEmpty
-
-
-
-
Constructor Detail
-
SortedTableMap
public SortedTableMap()
Constructs an empty map using the natural ordering of keys.
-
SortedTableMap
public SortedTableMap(java.util.Comparator<K> comp)
Constructs an empty map using the given comparator to order keys.- Parameters:
comp
- comparator defining the order of keys in the map
-
-
Method Detail
-
size
public int size()
Returns the number of entries in the map.- Returns:
- number of entries in the map
-
get
public V get(K key) throws java.lang.IllegalArgumentException
Returns the value associated with the specified key, or null if no such entry exists.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the associated value, or null if no such entry exists
- Throws:
java.lang.IllegalArgumentException
-
put
public V put(K key, V value) throws java.lang.IllegalArgumentException
Associates the given value with the given key. If an entry with the key was already in the map, this replaced the previous value with the new one and returns the old value. Otherwise, a new entry is added and null is returned.- Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key- Returns:
- the previous value associated with the key (or null, if no such entry)
- Throws:
java.lang.IllegalArgumentException
-
remove
public V remove(K key) throws java.lang.IllegalArgumentException
Removes the entry with the specified key, if present, and returns its associated value. Otherwise does nothing and returns null.- Parameters:
key
- the key whose entry is to be removed from the map- Returns:
- the previous value associated with the removed key, or null if no such entry exists
- Throws:
java.lang.IllegalArgumentException
-
-