Package net.sourceforge.jiu.color.data
Class ArrayHistogram1D
java.lang.Object
net.sourceforge.jiu.color.data.ArrayHistogram1D
- All Implemented Interfaces:
Histogram1D
A one-dimensional histogram data class that stores its counters in memory.
Counters are stored in an
int array of length
getMaxValue() + 1 so that k
values will require k * 4 bytes.- Author:
- Marco Schmidt
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionArrayHistogram1D(int numValues) Creates a histogram with the argument's number of values, from0tonumValues - 1. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all counters to zero.intgetEntry(int index) Returns the counter value for the given index.intReturns the maximum allowed index.intReturns the number of used entries (those entries with a counter value larger than zero).voidincreaseEntry(int index) Increases the counter value of the given index by one.voidsetEntry(int index, int newValue) Sets one counter to a new value.
-
Field Details
-
data
private int[] data
-
-
Constructor Details
-
ArrayHistogram1D
public ArrayHistogram1D(int numValues) Creates a histogram with the argument's number of values, from0tonumValues - 1.- Parameters:
numValues- the number of counters in the histogram; must be one or larger- Throws:
IllegalArgumentException- if the argument is smaller than one
-
-
Method Details
-
clear
public void clear()Description copied from interface:Histogram1DSets all counters to zero.- Specified by:
clearin interfaceHistogram1D
-
getEntry
public int getEntry(int index) Description copied from interface:Histogram1DReturns the counter value for the given index.- Specified by:
getEntryin interfaceHistogram1D- Parameters:
index- the zero-based index of the desired counter value- Returns:
- the counter value
-
getMaxValue
public int getMaxValue()Description copied from interface:Histogram1DReturns the maximum allowed index. The minimum is always 0.- Specified by:
getMaxValuein interfaceHistogram1D- Returns:
- the maximum index value
-
getNumUsedEntries
public int getNumUsedEntries()Description copied from interface:Histogram1DReturns the number of used entries (those entries with a counter value larger than zero).- Specified by:
getNumUsedEntriesin interfaceHistogram1D- Returns:
- number of non-zero counter values
-
increaseEntry
public void increaseEntry(int index) Description copied from interface:Histogram1DIncreases the counter value of the given index by one. Same semantics assetEntry(index, getEntry(index) + 1);- Specified by:
increaseEntryin interfaceHistogram1D- Parameters:
index- index into the histogram
-
setEntry
public void setEntry(int index, int newValue) Description copied from interface:Histogram1DSets one counter to a new value.- Specified by:
setEntryin interfaceHistogram1D- Parameters:
index- index of the counter to be changednewValue- new value for that counter
-