Package processing.data
Class DoubleDict
java.lang.Object
processing.data.DoubleDict
A simple table class to use a String as a lookup for an double value.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDoubleDict(int length) Create a new lookup with a specific size.DoubleDict(BufferedReader reader) Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab.DoubleDict(Object[][] pairs) Constructor to allow (more intuitive) inline initialization, e.g.:DoubleDict(String[] keys, double[] values) DoubleDict(Map<String, Double> incoming) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclear()Remove all entries.copy()Returns a duplicate copy of this object.voidentries()doubleReturn a value for the specified key.doubleSum all of the values in this dictionary, then return a new FloatDict of each key, divided by the total sum.booleanintkey(int index) String[]keyArray()Return a copy of the internal keys array.String[]keys()intmaxIndex()maxKey()The key for a max value; null if empty or everything is NaN (no max).doublemaxValue()The max value.intminIndex()minKey()doubleminValue()voidvoidprint()doubledoubleremoveIndex(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)voidvoidintsize()voidsortKeys()Sort the keys alphabetically (ignoring case).voidvoidSort by values in descending order (largest value will be at [0]).voidsortValues(boolean stable) Set true to ensure that the order returned is identical.voidvoidsortValuesReverse(boolean stable) voiddoublesum()voidswap(int a, int b) toJSON()Return this dictionary as a String in JSON format.toString()doublevalue(int index) double[]Create a new array and copy each of the values into it.double[]valueArray(double[] array) Fill an already-allocated array with the values (more efficient than creating a new array each time).values()voidwrite(PrintWriter writer) Write tab-delimited entries out to
-
Constructor Details
-
DoubleDict
public DoubleDict() -
DoubleDict
public DoubleDict(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. -
DoubleDict
Read a set of entries from a Reader that has each key/value pair on a single line, separated by a tab. -
DoubleDict
-
DoubleDict
Constructor to allow (more intuitive) inline initialization, e.g.:new FloatDict(new Object[][] { { "key1", 1 }, { "key2", 2 } }); -
DoubleDict
-
-
Method Details
-
size
public int size()- In brief:
- 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.- In brief:
- Remove all entries
-
entries
-
entryIterator
-
key
-
keys
-
keyIterator
-
keyArray
Return a copy of the internal keys array. This array can be modified.- In brief:
- Return a copy of the internal keys array
-
keyArray
-
value
public double value(int index) -
values
- In brief:
- Return the internal array being used to store the values
-
valueIterator
-
valueArray
public double[] valueArray()Create a new array and copy each of the values into it.- In brief:
- Create a new array and copy each of the values into it
-
valueArray
public double[] valueArray(double[] 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.- In brief:
- Return a value for the specified key
-
get
-
set
- In brief:
- Create a new key/value pair or change the value of one
-
setIndex
-
hasKey
- In brief:
- Check if a key is a part of the data structure
-
add
- In brief:
- Add to a value
-
sub
- In brief:
- Subtract from a value
-
mult
- In brief:
- Multiply a value
-
div
- In brief:
- Divide a value
-
minIndex
public int minIndex()- In brief:
- Return the smallest value
-
minKey
-
minValue
public double minValue() -
maxIndex
public int maxIndex()- In brief:
- Return the largest value
-
maxKey
The key for a max value; null if empty or everything is NaN (no max). -
maxValue
public double maxValue()The max value. (Or NaN if no entries or they're all NaN.) -
sum
public double sum() -
index
-
remove
- In brief:
- Remove a key/value pair
-
removeIndex
public double 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).- In brief:
- Sort the keys alphabetically
-
sortKeysReverse
public void sortKeysReverse()- In brief:
- Sort the keys alphabetically in reverse
-
sortValues
public void sortValues()Sort by values in descending order (largest value will be at [0]).- In brief:
- Sort by values in ascending order
-
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()- In brief:
- Sort by values in descending order
-
sortValuesReverse
public void sortValuesReverse(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
-