Histogram1D
public class ArrayHistogram1D extends Object implements Histogram1D
int
array of length
getMaxValue()
+ 1
so that k
values will require k * 4
bytes.Modifier and Type | Field | Description |
---|---|---|
private int[] |
data |
Constructor | Description |
---|---|
ArrayHistogram1D(int numValues) |
Creates a histogram with the argument's number of values, from
0 to numValues - 1 . |
Modifier and Type | Method | 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 largerIllegalArgumentException
- 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