Package net.sourceforge.jiu.color.data
Class OnDemandHistogram3D
java.lang.Object
net.sourceforge.jiu.color.data.OnDemandHistogram3D
- All Implemented Interfaces:
Histogram3D
A data class for a three-dimensional histogram, creating counters on demand only,
not allocating counters for all possible entries at the beginning.
The creation on demand happens to save space.
Note: Rewrote from scratch for version 0.15.0 to use hash tables instead of int arrays. New version creates and throws away a lot of objects, which had been a problem with early JVMs but should be OK these days.
- Author:
- Marco Schmidt
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOnDemandHistogram3D(int max1, int max2, int max3) Creates a new histogram, internally creates the hash table for triplet values. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all counters to zero.private Histogram3DNodecreateNode(int v1, int v2, int v3) intgetEntry(int index1, int index2, int index3) Returns the counter value of (index1, index2, index3).intgetMaxValue(int index) Returns the maximum index value for one of the three indexes.intReturns the number of used entries (those entries with a counter value larger than zero).voidincreaseEntry(int index1, int index2, int index3) Increases the counter value of (index1, index2, index3) by one.voidsetEntry(int index1, int index2, int index3, int newValue) Sets the counter value of (index1, index2, index3) to newValue.
-
Field Details
-
hash
-
numUniqueValues
private int numUniqueValues -
maxValue1
private final int maxValue1 -
maxValue2
private final int maxValue2 -
maxValue3
private final int maxValue3
-
-
Constructor Details
-
OnDemandHistogram3D
public OnDemandHistogram3D(int max1, int max2, int max3) Creates a new histogram, internally creates the hash table for triplet values.
-
-
Method Details
-
clear
public void clear()Description copied from interface:Histogram3DSets all counters to zero.- Specified by:
clearin interfaceHistogram3D
-
createNode
-
getEntry
public int getEntry(int index1, int index2, int index3) Description copied from interface:Histogram3DReturns the counter value of (index1, index2, index3).- Specified by:
getEntryin interfaceHistogram3D- Parameters:
index1- first of the three values forming the threedimensional indexindex2- second of the three values forming the threedimensional indexindex3- three of the three values forming the threedimensional index- Returns:
- the counter value of the desired index
-
getMaxValue
Description copied from interface:Histogram3DReturns the maximum index value for one of the three indexes.- Specified by:
getMaxValuein interfaceHistogram3D- Throws:
IllegalArgumentException- if the index formed by the arguments is invalid
-
getNumUsedEntries
public int getNumUsedEntries()Description copied from interface:Histogram3DReturns the number of used entries (those entries with a counter value larger than zero).- Specified by:
getNumUsedEntriesin interfaceHistogram3D- Returns:
- number of non-zero counter values
-
increaseEntry
public void increaseEntry(int index1, int index2, int index3) Description copied from interface:Histogram3DIncreases the counter value of (index1, index2, index3) by one. This method can be implemented by the one-linersetEntry(index1, index2, index3, getEntry(index1, index2, index3) + 1);However, implementations of this method may take advantage of implementation details to provide a more efficient approach.- Specified by:
increaseEntryin interfaceHistogram3D- Parameters:
index1- first of the three values forming the threedimensional indexindex2- second of the three values forming the threedimensional indexindex3- three of the three values forming the threedimensional index
-
setEntry
public void setEntry(int index1, int index2, int index3, int newValue) Description copied from interface:Histogram3DSets the counter value of (index1, index2, index3) to newValue.- Specified by:
setEntryin interfaceHistogram3D- Parameters:
index1- first of the three values forming the threedimensional indexindex2- second of the three values forming the threedimensional indexindex3- three of the three values forming the threedimensional indexnewValue- the counter value that is assigned to the argument index
-