|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectecologylab.generic.Debug
ecologylab.collections.FloatWeightSet<E>
public class FloatWeightSet<E extends FloatSetElement>
Provides the facility of efficient weighted random selection from a set elements, each of whicn includes a characterizing floating point weight.
Works in cooperation w FloatSetElements; requiring that
user object to keep an integer index slot, which only we should be
accessing. This impure oo style is an adaption to Java's lack of
multiple inheritance.
Gotta be careful to be thread safe. Seems no operations can safely occur concurrently. There are a bunch of synchronized methods to affect this.
| Field Summary | |
|---|---|
static int |
EXTRA_ALLOCATION
Allocate this many extra slots, to avoid needing to alloc due to synch issues between insert & prune. |
protected int |
extraAllocation
This many extra slots will be allocated in the set, to enable insertions() prior to a prune(), without reallocation. |
protected float[] |
incrementalSums
Used to maintain a sequential set of areas by weight, in order to implement fast weighted randomSelect(). |
protected java.util.ArrayList<E> |
maxArrayList
When there is more than one maximum found by maxSelect(), this ArrayList holds the tied elements. |
protected int |
pruneSize
Maximum size to let this grow to, before needPrune() will return true. |
protected FloatSetElement |
SENTINEL
Used as a boundary condition for fast implementations of sort. |
protected float |
setSum
|
protected int |
size
size of last used element in array |
| Fields inherited from interface ecologylab.collections.BasicFloatSet |
|---|
NO_RECOMPUTE, PARTIAL_RECOMPUTE, RECOMPUTE_ALL |
| Constructor Summary | |
|---|---|
FloatWeightSet(int initialSize)
Create a set, with data structures to support the stated initial size. |
|
FloatWeightSet(int initialSize,
boolean supportWeightedRandomSelect)
|
|
FloatWeightSet(int initialSize,
int extraAllocation,
ThreadMaster threadMaster,
boolean supportWeightedRandomSelect)
Create a set, with data structures to support the stated initial size, and a threadMaster that may pause use before expensive operations. |
|
FloatWeightSet(int initialSize,
ThreadMaster threadMaster)
Create a set, with data structures to support the stated initial size, and a threadMaster that may pause use before expensive operations. |
|
FloatWeightSet(int initialSize,
ThreadMaster threadMaster,
boolean supportWeightedRandomSelect)
|
|
| Method Summary | |
|---|---|
void |
clear(boolean doRecycleElements)
Delete all the elements in the set, as fast as possible. |
boolean |
contains(E element)
|
void |
decrement(E el)
|
void |
delete(E el,
int recompute)
Delete an element from the set. |
FloatSetElement[] |
elements()
|
E |
findElement(E element)
|
E |
get(int i)
Get the ith element in the set. |
int |
getPruneSize()
Get the maximum size this should grow to before pruning. |
float[] |
incrementalSums()
|
int |
indexOf(E element)
|
void |
initializeStructure(int size)
|
void |
insert(E el)
|
boolean |
isEmpty()
Check to see if the set has any elements. |
protected boolean |
isOversize(int sizeThreshold)
Return true if the size of this is greater than the threshold passed in. |
E |
lastElement()
Get the last element in the set, or null if the set is empty. |
static void |
main(java.lang.String[] a)
|
protected void |
maxArrayListClear()
Clear the ArrayList of tied elements from the last maxSelect(). |
E |
maxSelect()
|
E |
maxSelect(int desiredSize)
Prune to the specified desired size, if necessary, then do a maxSelect(). |
float |
mean()
|
float |
meanByIteration()
|
int |
numSlots()
|
void |
prune(int numToKeep)
Delete lowest-weighted elements, in case this collection has grown too big. |
E |
pruneAndMaxSelect()
Prune to the set's specified maxSize, if necessary, then do a maxSelect(). |
E |
pruneAndWeightedRandomSelect()
Prune to the set's specified maxSize, if necessary, then do a weightedRandomSelect(). |
boolean |
pruneIfNeeded()
|
void |
setElements(FloatSetElement[] newElements)
|
void |
setIncrementalSums(float[] newIncrementalSums)
|
void |
setNumSlots(int newNumSlots)
|
void |
setPruneSize(int maxSize)
Set the maximum size this should grow to before pruning. |
void |
setSize(int newSize)
|
java.lang.String |
shortString()
|
int |
size()
|
boolean |
syncRecompute()
|
java.util.ArrayList<E> |
tiedForMax()
If there was a tie in the last maxSelect() calculation, the others will be here. |
java.lang.String |
toString()
|
E |
weightedRandomSelect()
weighted randomSelect() with no recompute to update the data structure. |
E |
weightedRandomSelect(int desiredSize)
Prune to the specified desired size, if necessary, then do a weightedRandomSelect(). |
| Methods inherited from class ecologylab.generic.Debug |
|---|
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, warning, warning, weird, weird |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected float[] incrementalSums
protected float setSum
protected final FloatSetElement SENTINEL
protected final int extraAllocation
public static final int EXTRA_ALLOCATION
protected int size
protected int pruneSize
protected java.util.ArrayList<E extends FloatSetElement> maxArrayList
| Constructor Detail |
|---|
public FloatWeightSet(int initialSize)
public FloatWeightSet(int initialSize,
boolean supportWeightedRandomSelect)
public FloatWeightSet(int initialSize,
ThreadMaster threadMaster)
public FloatWeightSet(int initialSize,
ThreadMaster threadMaster,
boolean supportWeightedRandomSelect)
public FloatWeightSet(int initialSize,
int extraAllocation,
ThreadMaster threadMaster,
boolean supportWeightedRandomSelect)
| Method Detail |
|---|
public void clear(boolean doRecycleElements)
doRecycleElements - TODOpublic void insert(E el)
public void delete(E el,
int recompute)
delete in interface BasicFloatSet<E extends FloatSetElement>el - The FloatSetElement element to delete.recompute - -1 for absolutely no recompute.
0 for recompute upwards from el.
1 for recompute all.public boolean pruneIfNeeded()
protected boolean isOversize(int sizeThreshold)
sizeThreshold -
public E pruneAndMaxSelect()
public E maxSelect(int desiredSize)
desiredSize -
protected void maxArrayListClear()
public E maxSelect()
public java.util.ArrayList<E> tiedForMax()
public void prune(int numToKeep)
numToKeep - -- size for the set after pruning is done.public float mean()
public float meanByIteration()
public int size()
size in interface LinearAccess<E extends FloatSetElement>public java.lang.String toString()
toString in class Debugpublic java.lang.String shortString()
public boolean isEmpty()
isEmpty in interface BasicFloatSet<E extends FloatSetElement>isEmpty in interface LinearAccess<E extends FloatSetElement>public E get(int i)
get in interface BasicFloatSet<E extends FloatSetElement>get in interface LinearAccess<E extends FloatSetElement>i -
public E lastElement()
lastElement in interface BasicFloatSet<E extends FloatSetElement>public boolean syncRecompute()
public E pruneAndWeightedRandomSelect()
public E weightedRandomSelect(int desiredSize)
desiredSize -
public E weightedRandomSelect()
public E findElement(E element)
public int indexOf(E element)
public boolean contains(E element)
public static void main(java.lang.String[] a)
public FloatSetElement[] elements()
public void setElements(FloatSetElement[] newElements)
public float[] incrementalSums()
public void setIncrementalSums(float[] newIncrementalSums)
public int numSlots()
public void setNumSlots(int newNumSlots)
public void setSize(int newSize)
public void initializeStructure(int size)
public void setPruneSize(int maxSize)
maxSize - The maxSize to set.public int getPruneSize()
public void decrement(E el)
decrement in interface BasicFloatSet<E extends FloatSetElement>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||