K
- the key, which must be hashable.public class HashedAggregator<K>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected double |
initialValue
The initial value for each key
|
protected java.util.HashMap<K,java.lang.Double> |
storage
The backing hash map
|
Constructor and Description |
---|
HashedAggregator()
Initializes with initial value for each key being 0.0.
|
HashedAggregator(double initialValue)
Initializes with the given initial value for each key.
|
HashedAggregator(double initialValue,
int capacity)
Initializes with the given initial value for each key and the initial capacity for the table.
|
Modifier and Type | Method and Description |
---|---|
void |
add(K ind,
double v)
Adds a specified value to a key.
|
boolean |
containsKey(K key)
Returns true if this object has a value associated with the specified key, false otherwise.
|
java.util.Set<java.util.Map.Entry<K,java.lang.Double>> |
entrySet()
The entry set for stored keys and values.
|
java.util.Map<K,java.lang.Double> |
getHashMap()
Returns the HashMap that backs this object.
|
java.util.Set<K> |
keySet()
The set of keys stored.
|
int |
size()
Returns the number of keys stored.
|
double |
v(K ind)
The current value associated with key ind.
|
java.util.Collection<java.lang.Double> |
valueSet()
The set of values stored.
|
protected java.util.HashMap<K,java.lang.Double> storage
protected double initialValue
public HashedAggregator()
public HashedAggregator(double initialValue)
initialValue
- the initial value associated with each key.public HashedAggregator(double initialValue, int capacity)
initialValue
- the initial value associated with each key.capacity
- the initial memory capacity of the storing tablepublic void add(K ind, double v)
ind
- the key indexv
- the value to add to the value associated with ind.public double v(K ind)
ind
- the key indexpublic int size()
public java.util.Set<K> keySet()
public java.util.Collection<java.lang.Double> valueSet()
public java.util.Set<java.util.Map.Entry<K,java.lang.Double>> entrySet()
public java.util.Map<K,java.lang.Double> getHashMap()
public boolean containsKey(K key)
key
- the key to check