|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.umd.cloud9.util.map.HMapKI<K>
K - the type of keys maintained by this mappublic class HMapKI<K extends Comparable<?>>
Hash-based implementation of the MapKI interface. MapKI is
a specialized variant the standard Java Map interface, except that
the values are hard coded as ints for efficiency reasons (keys can be
arbitrary objects). This implementation was adapted from HashMap
version 1.73, 03/13/07. See this
benchmark for an efficiency comparison.
| Field Summary |
|---|
| Fields inherited from interface edu.umd.cloud9.util.map.MapKI |
|---|
DEFAULT_VALUE |
| Constructor Summary | |
|---|---|
HMapKI()
Constructs an empty HMapKI with the default initial capacity (1024) and the default load factor (0.75). |
|
HMapKI(int initialCapacity)
Constructs an empty HMapKI with the specified initial capacity and the default load factor (0.75). |
|
HMapKI(int initialCapacity,
float loadFactor)
Constructs an empty HMapKI with the specified initial capacity and load factor. |
|
HMapKI(MapKI<? extends K> m)
Constructs a new HMapKI with the same mappings as the specified MapKI. |
|
| Method Summary | |
|---|---|
void |
clear()
Removes all of the mappings from this map. |
Object |
clone()
Returns a shallow copy of this HMapKI instance: the keys and values themselves are not cloned. |
boolean |
containsKey(K key)
Returns true if this map contains a mapping for the specified key. |
boolean |
containsValue(int value)
Returns true if this map contains one or more mappings with the specified value. |
int |
dot(MapKI<K> m)
Computes the dot product of this map with another map. |
Set<MapKI.Entry<K>> |
entrySet()
Returns a Set view of the mappings contained in this map. |
int |
get(K key)
Returns the value to which the specified key is mapped, or throws NoSuchElementException if this map contains no mapping for the
key. |
MapKI.Entry<K>[] |
getEntriesSortedByKey()
|
MapKI.Entry<K>[] |
getEntriesSortedByKey(int n)
|
MapKI.Entry<K>[] |
getEntriesSortedByValue()
Returns entries sorted by descending value. |
MapKI.Entry<K>[] |
getEntriesSortedByValue(int n)
Returns top n entries sorted by descending value. |
void |
increment(K key)
Increments the key. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
Set<K> |
keySet()
Returns a Set view of the keys contained in this map. |
void |
plus(MapKI<K> m)
Adds values of keys from another map to this map. |
int |
put(K key,
int value)
Associates the specified value with the specified key in this map. |
void |
putAll(MapKI<? extends K> m)
Copies all of the mappings from the specified map to this map. |
int |
remove(K key)
Removes the mapping for a key from this map if it is present. |
int |
size()
Returns the number of key-value mappings in this map. |
String |
toString()
|
Collection<Integer> |
values()
Returns a Collection view of the values contained in this map. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface edu.umd.cloud9.util.map.MapKI |
|---|
equals, hashCode |
| Constructor Detail |
|---|
public HMapKI(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacityloadFactor - the load factor
IllegalArgumentException - if the initial capacity is negative or the load factor is
nonpositivepublic HMapKI(int initialCapacity)
initialCapacity - the initial capacity.
IllegalArgumentException - if the initial capacity is negative.public HMapKI()
public HMapKI(MapKI<? extends K> m)
m - the map whose mappings are to be placed in this map
NullPointerException - if the specified map is null| Method Detail |
|---|
public int size()
MapKI
size in interface MapKI<K extends Comparable<?>>public boolean isEmpty()
MapKI
isEmpty in interface MapKI<K extends Comparable<?>>public int get(K key)
MapKINoSuchElementException if this map contains no mapping for the
key.
get in interface MapKI<K extends Comparable<?>>key - the key whose associated value is to be returned
public boolean containsKey(K key)
MapKI
containsKey in interface MapKI<K extends Comparable<?>>key - key whose presence in this map is to be tested
public int put(K key,
int value)
MapKI
put in interface MapKI<K extends Comparable<?>>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic void putAll(MapKI<? extends K> m)
MapKI
putAll in interface MapKI<K extends Comparable<?>>m - mappings to be stored in this mappublic int remove(K key)
MapKI
remove in interface MapKI<K extends Comparable<?>>key - key whose mapping is to be removed from the mappublic void clear()
MapKI
clear in interface MapKI<K extends Comparable<?>>public boolean containsValue(int value)
MapKI
containsValue in interface MapKI<K extends Comparable<?>>value - value whose presence in this map is to be tested
public Object clone()
clone in class Objectpublic Set<K> keySet()
MapKISet view of the keys contained in this map. The set is
backed by the map, so changes to the map are reflected in the set, and
vice-versa. See Map.keySet() for more details.
keySet in interface MapKI<K extends Comparable<?>>public Collection<Integer> values()
MapKICollection view of the values contained in this map.
Note that this is a inefficient operation since it triggers autoboxing of
the int values, which is exactly what this implementation is trying to
avoid. Unlike a standard Java Map, values in the backing map
cannot be altered with this collection view.
values in interface MapKI<K extends Comparable<?>>public Set<MapKI.Entry<K>> entrySet()
MapKISet view of the mappings contained in this map. The set
is backed by the map, so changes to the map are reflected in the set, and
vice-versa. See Map.entrySet() for more details.
entrySet in interface MapKI<K extends Comparable<?>>public String toString()
toString in class Objectpublic void plus(MapKI<K> m)
m - the other mappublic int dot(MapKI<K> m)
m - the other mappublic void increment(K key)
key - key to incrementpublic MapKI.Entry<K>[] getEntriesSortedByValue()
public MapKI.Entry<K>[] getEntriesSortedByValue(int n)
n - number of entries to return
public MapKI.Entry<K>[] getEntriesSortedByKey()
public MapKI.Entry<K>[] getEntriesSortedByKey(int n)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||