K - the type of keys maintained by this mappublic class HMapKI<K extends Comparable<?>> extends Object implements MapKI<K>, Cloneable, Serializable
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.DEFAULT_VALUE| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
long |
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.
|
void |
increment(K key,
int value)
Increments the key by some value.
|
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. |
public HMapKI(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacityloadFactor - the load factorIllegalArgumentException - 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 mapNullPointerException - if the specified map is nullpublic int size()
MapKIsize in interface MapKI<K extends Comparable<?>>public boolean isEmpty()
MapKIisEmpty 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 returnedpublic boolean containsKey(K key)
MapKIcontainsKey in interface MapKI<K extends Comparable<?>>key - key whose presence in this map is to be testedpublic int put(K key, int value)
MapKIput 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)
MapKIputAll in interface MapKI<K extends Comparable<?>>m - mappings to be stored in this mappublic int remove(K key)
MapKIremove in interface MapKI<K extends Comparable<?>>key - key whose mapping is to be removed from the mappublic void clear()
MapKIclear in interface MapKI<K extends Comparable<?>>public boolean containsValue(int value)
MapKIcontainsValue in interface MapKI<K extends Comparable<?>>value - value whose presence in this map is to be testedpublic Object clone()
public 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.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.entrySet in interface MapKI<K extends Comparable<?>>public void plus(MapKI<K> m)
MapKIplus in interface MapKI<K extends Comparable<?>>m - the other mappublic long dot(MapKI<K> m)
MapKIdot in interface MapKI<K extends Comparable<?>>m - the other mappublic void increment(K key)
MapKIincrement in interface MapKI<K extends Comparable<?>>key - key to incrementpublic void increment(K key, int value)
MapKIincrement in interface MapKI<K extends Comparable<?>>key - key to incrementvalue - increment valuepublic MapKI.Entry<K>[] getEntriesSortedByValue()
public MapKI.Entry<K>[] getEntriesSortedByValue(int n)
n - number of entries to returnpublic MapKI.Entry<K>[] getEntriesSortedByKey()
public MapKI.Entry<K>[] getEntriesSortedByKey(int n)
Copyright © 2014. All rights reserved.