public class ArrayHistogram1D extends java.lang.Object implements Histogram1D
int
array of length
getMaxValue()
+ 1
so that k
values will require k * 4
bytes.Modifier and Type | Field and Description |
---|---|
private int[] |
data |
Constructor and Description |
---|
ArrayHistogram1D(int numValues)
Creates a histogram with the argument's number of values, from
0 to numValues - 1 . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Sets all counters to zero.
|
int |
getEntry(int index)
Returns the counter value for the given index.
|
int |
getMaxValue()
Returns the maximum allowed index.
|
int |
getNumUsedEntries()
Returns the number of used entries (those entries with
a counter value larger than zero).
|
void |
increaseEntry(int index)
Increases the counter value of the given index by one.
|
void |
setEntry(int index,
int newValue)
Sets one counter to a new value.
|
public ArrayHistogram1D(int numValues)
0
to numValues - 1
.numValues
- the number of counters in the histogram; must be one or largerjava.lang.IllegalArgumentException
- if the argument is smaller than onepublic void clear()
Histogram1D
clear
in interface Histogram1D
public int getEntry(int index)
Histogram1D
getEntry
in interface Histogram1D
index
- the zero-based index of the desired counter valuepublic int getMaxValue()
Histogram1D
getMaxValue
in interface Histogram1D
public int getNumUsedEntries()
Histogram1D
getNumUsedEntries
in interface Histogram1D
public void increaseEntry(int index)
Histogram1D
setEntry(index, getEntry(index) + 1);
increaseEntry
in interface Histogram1D
index
- index into the histogrampublic void setEntry(int index, int newValue)
Histogram1D
setEntry
in interface Histogram1D
index
- index of the counter to be changednewValue
- new value for that counter