K - the type of keys maintained by this mappublic class HMapKF<K extends Comparable<?>> extends Object implements MapKF<K>, Cloneable, Serializable
MapKF is a specialized variant
the standard Java Map interface, except that the values are hard coded as floats 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 |
|---|
HMapKF()
Constructs an empty HMapKF with the default initial capacity (1024) and the default
load factor (0.75).
|
HMapKF(int initialCapacity)
Constructs an empty HMapKF with the specified initial capacity and the default load
factor (0.75).
|
HMapKF(int initialCapacity,
float loadFactor)
Constructs an empty HMapKF with the specified initial capacity and load factor.
|
HMapKF(MapKF<? extends K> m)
Constructs a new HMapKF with the same mappings as the specified MapKF.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all of the mappings from this map.
|
Object |
clone()
Returns a shallow copy of this HMapKF 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(float value)
Returns true if this map contains one or more mappings with the specified value.
|
double |
dot(MapKF<K> m)
Computes the dot product of this map with another map.
|
Set<MapKF.Entry<K>> |
entrySet()
Returns a
Set view of the mappings contained in this map. |
float |
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. |
MapKF.Entry<K>[] |
getEntriesSortedByValue()
Returns entries sorted by descending value.
|
MapKF.Entry<K>[] |
getEntriesSortedByValue(int n)
Returns top n entries sorted by descending value.
|
void |
increment(K key)
Increments the key.
|
void |
increment(K key,
float 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. |
float |
length()
Returns the length of the vector represented by this map.
|
void |
normalize()
Normalizes values such that the vector represented by this map has unit length.
|
void |
plus(MapKF<K> m)
Adds values of keys from another map to this map.
|
float |
put(K key,
float value)
Associates the specified value with the specified key in this map.
|
void |
putAll(MapKF<? extends K> m)
Copies all of the mappings from the specified map to this map.
|
float |
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<Float> |
values()
Returns a
Collection view of the values contained in this map. |
public HMapKF(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacityloadFactor - the load factorIllegalArgumentException - if the initial capacity is negative or the load factor is
nonpositivepublic HMapKF(int initialCapacity)
initialCapacity - the initial capacity.IllegalArgumentException - if the initial capacity is negative.public HMapKF()
public HMapKF(MapKF<? extends K> m)
m - the map whose mappings are to be placed in this mapNullPointerException - if the specified map is nullpublic int size()
MapKFsize in interface MapKF<K extends Comparable<?>>public boolean isEmpty()
MapKFisEmpty in interface MapKF<K extends Comparable<?>>public float get(K key)
MapKFNoSuchElementException if this map contains no mapping for the key.get in interface MapKF<K extends Comparable<?>>key - the key whose associated value is to be returnedpublic boolean containsKey(K key)
MapKFcontainsKey in interface MapKF<K extends Comparable<?>>key - key whose presence in this map is to be testedpublic float put(K key, float value)
MapKFput in interface MapKF<K extends Comparable<?>>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic void putAll(MapKF<? extends K> m)
MapKFputAll in interface MapKF<K extends Comparable<?>>m - mappings to be stored in this mappublic float remove(K key)
MapKFremove in interface MapKF<K extends Comparable<?>>key - key whose mapping is to be removed from the mappublic void clear()
MapKFclear in interface MapKF<K extends Comparable<?>>public boolean containsValue(float value)
MapKFcontainsValue in interface MapKF<K extends Comparable<?>>value - value whose presence in this map is to be testedpublic Object clone()
public Set<K> keySet()
MapKFSet 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 MapKF<K extends Comparable<?>>public Collection<Float> values()
MapKFCollection view of the values contained in this map. Note that this is a
inefficient operation since it triggers autoboxing of the float 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 MapKF<K extends Comparable<?>>public Set<MapKF.Entry<K>> entrySet()
MapKFSet 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 MapKF<K extends Comparable<?>>public void plus(MapKF<K> m)
MapKFplus in interface MapKF<K extends Comparable<?>>m - the other mappublic double dot(MapKF<K> m)
MapKFdot in interface MapKF<K extends Comparable<?>>m - the other mappublic void increment(K key)
MapKFincrement in interface MapKF<K extends Comparable<?>>key - key to incrementpublic void increment(K key, float value)
MapKFincrement in interface MapKF<K extends Comparable<?>>key - key to incrementvalue - increment valuepublic float length()
public void normalize()
public MapKF.Entry<K>[] getEntriesSortedByValue()
public MapKF.Entry<K>[] getEntriesSortedByValue(int n)
n - number of entries to returnCopyright © 2018. All rights reserved.