Package processing.data
Class FloatDict
java.lang.Object
processing.data.FloatDict
A simple class to use a String as a lookup for a float value. String "keys"
are associated with floating-point values.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFloatDict(int length) Create a new lookup with a specific size.FloatDict(BufferedReader reader) Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab.Constructor to allow (more intuitive) inline initialization, e.g.: -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd to a value.voidclear()Remove all entries from the data structure.copy()Returns a duplicate copy of this object.protected voidprotected voidcrop()voidDivide a value.entries()floatReturn a value for the specified key.floatSum all of the values in this dictionary, then return a new FloatDict of each key, divided by the total sum.booleanCheck if a key is a part of the data structure.intkey(int index) String[]keyArray()Return a copy of the internal keys array.String[]keys()Return the internal array being used to store the keys.intmaxIndex()Return the largest valuemaxKey()The key for a max value; null if empty or everything is NaN (no max).floatmaxValue()The max value.intminIndex()Return the smallest valueminKey()floatminValue()voidMultiply a value.voidprint()floatRemove a key/value pair.floatremoveIndex(int index) voidresize(int length) Resize the internal data, this can only be used to shrink the list.voidSave tab-delimited entries to a file (TSV format, UTF-8 encoding)voidCreate a new key/value pair or change the value of one.voidintsize()Returns the number of key/value pairs.protected voidsortImpl(boolean useKeys, boolean reverse, boolean stable) voidsortKeys()Sort the keys alphabetically (ignoring case).voidSort the keys alphabetically in reverse (ignoring case).voidSort by values in ascending order (largest value will be at [0]).voidsortValues(boolean stable) Set true to ensure that the order returned is identical.voidSort by values in descending order.voidsortValuesReverse(boolean stable) voidSubtract from a value.floatsum()doublevoidswap(int a, int b) toJSON()Return this dictionary as a String in JSON format.toString()floatvalue(int index) float[]The version of this method without a parameter creates a new array and copies each of the values into it.float[]valueArray(float[] array) Fill an already-allocated array with the values (more efficient than creating a new array each time).values()Return the internal array being used to store the values.voidwrite(PrintWriter writer) Write tab-delimited entries out to
-
Field Details
-
count
protected int countNumber of elements in the table -
keys
-
values
protected float[] values
-
-
Constructor Details
-
FloatDict
public FloatDict() -
FloatDict
public FloatDict(int length) Create a new lookup with a specific size. This is more efficient than not specifying a size. Use it when you know the rough size of the thing you're creating. -
FloatDict
Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab. -
FloatDict
-
FloatDict
Constructor to allow (more intuitive) inline initialization, e.g.:new FloatDict(new Object[][] { { "key1", 1 }, { "key2", 2 } });
-
-
Method Details
-
size
public int size()Returns the number of key/value pairs. -
resize
public void resize(int length) Resize the internal data, this can only be used to shrink the list. Helpful for situations like sorting and then grabbing the top 50 entries. -
clear
public void clear()Remove all entries from the data structure. -
entries
-
entryIterator
-
key
-
crop
protected void crop() -
keys
Return the internal array being used to store the keys. -
keyIterator
-
keyArray
Return a copy of the internal keys array. In contrast to the keys() method, this array can be modified. -
keyArray
-
value
public float value(int index) -
values
Return the internal array being used to store the values. -
valueIterator
-
valueArray
public float[] valueArray()The version of this method without a parameter creates a new array and copies each of the values into it. The version with the float[] parameters fills an already-allocated array with the values (more efficient than creating a new array each time). If 'array' is null, or not the same size as the number of values, a new array will be allocated and returned. -
valueArray
public float[] valueArray(float[] array) Fill an already-allocated array with the values (more efficient than creating a new array each time). If 'array' is null, or not the same size as the number of values, a new array will be allocated and returned. -
get
Return a value for the specified key. -
get
-
set
Create a new key/value pair or change the value of one. -
setIndex
-
hasKey
Check if a key is a part of the data structure. -
add
Add to a value. If the key does not exist, a new pair is initialized with the value supplied. -
sub
Subtract from a value. -
mult
Multiply a value. -
div
Divide a value. -
minIndex
public int minIndex()Return the smallest value -
minKey
-
minValue
public float minValue() -
maxIndex
public int maxIndex()Return the largest value -
maxKey
The key for a max value; null if empty or everything is NaN (no max). -
maxValue
public float maxValue()The max value. (Or NaN if no entries or they're all NaN.) -
sum
public float sum() -
sumDouble
public double sumDouble() -
index
-
create
-
remove
Remove a key/value pair. -
removeIndex
public float removeIndex(int index) -
swap
public void swap(int a, int b) -
sortKeys
public void sortKeys()Sort the keys alphabetically (ignoring case). Uses the value as a tie-breaker (only really possible with a key that has a case change). -
sortKeysReverse
public void sortKeysReverse()Sort the keys alphabetically in reverse (ignoring case). Uses the value as a tie-breaker (only really possible with a key that has a case change). -
sortValues
public void sortValues()Sort by values in ascending order (largest value will be at [0]). -
sortValues
public void sortValues(boolean stable) Set true to ensure that the order returned is identical. Slightly slower because the tie-breaker for identical values compares the keys.- Parameters:
stable-
-
sortValuesReverse
public void sortValuesReverse()Sort by values in descending order. The largest value will be at [0]. -
sortValuesReverse
public void sortValuesReverse(boolean stable) -
sortImpl
protected void sortImpl(boolean useKeys, boolean reverse, boolean stable) -
getPercent
Sum all of the values in this dictionary, then return a new FloatDict of each key, divided by the total sum. The total for all values will be ~1.0.- Returns:
- a FloatDict with the original keys, mapped to their pct of the total
-
copy
Returns a duplicate copy of this object. -
print
public void print() -
save
Save tab-delimited entries to a file (TSV format, UTF-8 encoding) -
write
Write tab-delimited entries out to- Parameters:
writer-
-
toJSON
Return this dictionary as a String in JSON format. -
toString
-