E
- the type of elements maintained by this weighted mappublic final class HashWeightedMap<E> extends Object implements WeightedMap<E>
Constructor and Description |
---|
HashWeightedMap()
Create a new weighted map with the default initial capacity
and load factor.
|
HashWeightedMap(int initialCapacity)
Create a new weighted map with the specified initial capacity
and default load factor.
|
HashWeightedMap(int initialCapacity,
float loadFactor)
Create a new weighted map with the specified initial capacity
and load factor.
|
HashWeightedMap(WeightedMap<? extends E> weightedMap)
Create a new weighted map with the elements and weights
in the specified weighted map (copy constructor).
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object o) |
boolean |
containsValue(Object o) |
Set<Map.Entry<E,Double>> |
entrySet() |
Double |
get(Object o) |
boolean |
isEmpty() |
Set<E> |
keySet() |
int |
maximumRank()
Return the maximum rank in this weighted map.
|
Double |
normalizedWeight(E e)
Return the normalized weight for the specified
element in this weighted map.
|
Double |
put(E e,
Double w) |
void |
putAll(Map<? extends E,? extends Double> t) |
int |
rank(E e)
Return an integer rank for the specified element in this
weighted map based on its weight.
|
Double |
remove(Object o) |
E |
sample()
Randomly sample an element from this weighted map according
to its normalized weight.
|
void |
setRandom(Random random)
Set the source of randomness for this weighted map to
random . |
int |
size() |
Double |
totalWeight()
Return the sum of the weights in this weighted map.
|
Collection<Double> |
values() |
Double |
weight(E e)
Return the weight for the specified element in
this weighted map.
|
public HashWeightedMap()
public HashWeightedMap(int initialCapacity)
initialCapacity
- initial capacitypublic HashWeightedMap(int initialCapacity, float loadFactor)
initialCapacity
- initial capacityloadFactor
- load factorpublic HashWeightedMap(WeightedMap<? extends E> weightedMap)
weightedMap
- weighted map to copy, must not be nullpublic void setRandom(Random random)
random
.random
- source of randomness, must not be nullpublic boolean containsKey(Object o)
containsKey
in interface Map<E,Double>
public boolean containsValue(Object o)
containsValue
in interface Map<E,Double>
public E sample()
sample
in interface WeightedMap<E>
null
if this weighted
map is empty or if the total weight is zeroWeightedMap.totalWeight()
,
WeightedMap.normalizedWeight(E)
public Double weight(E e)
get(E e)
.weight
in interface WeightedMap<E>
e
- elementnull
if this weighted map is emptypublic Double normalizedWeight(E e)
normalizedWeight
in interface WeightedMap<E>
e
- elementnull
if this weighted map is emptypublic Double totalWeight()
totalWeight
in interface WeightedMap<E>
public int rank(E e)
rank
in interface WeightedMap<E>
e
- element-1
if this
weighted map is empty or if e
is not an element
in this weighted mappublic int maximumRank()
maximumRank
in interface WeightedMap<E>
-1
if this weighted map is emptyCopyright (c) 2005-2013 held jointly by the individual authors. Licensed under the GNU Lesser General Public License (LGPL).