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()
Histogram1Dclear in interface Histogram1Dpublic int getEntry(int index)
Histogram1DgetEntry in interface Histogram1Dindex - the zero-based index of the desired counter valuepublic int getMaxValue()
Histogram1DgetMaxValue in interface Histogram1Dpublic int getNumUsedEntries()
Histogram1DgetNumUsedEntries in interface Histogram1Dpublic void increaseEntry(int index)
Histogram1DsetEntry(index, getEntry(index) + 1);increaseEntry in interface Histogram1Dindex - index into the histogrampublic void setEntry(int index,
int newValue)
Histogram1DsetEntry in interface Histogram1Dindex - index of the counter to be changednewValue - new value for that counter