Histograms.Mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on June 28, 1988 3:26:49 pm PDT
A Histogram is a simple 1D or 2D data collector.
A 1D Histogram:
is a sequence of counters addressed by an integer I in the range [0..IMax). IMax is automatically maintained to be about as big as needed. IMax cells are actually allocated, so keep IMax within reason.
A 2D Histogram:
is a 2D array of counters addressed by two integers <I, J> in the range [0..IMax) and [0..JMax), where IMax and JMax are automatically maintained. IMax*JMax cells are actually allocated, so keep IMax*JMax within reason.
See the DF file for other interfaces dealing with Histograms.
DIRECTORY IO, Rope;
Histograms: CEDAR DEFINITIONS = {
Error: ERROR [msg: ROPE];
ROPE: TYPE = Rope.ROPE;
Dim: TYPE ~ {X, Y};
BoolPair: TYPE ~ ARRAY Dim OF BOOL;
RealRange1: TYPE ~ RECORD [min, max: REAL];
RealRange2: TYPE ~ ARRAY Dim OF RealRange1;
Range1: TYPE = RECORD [min, max: INT];
Range2: TYPE = ARRAY Dim OF Range1;
nullRange1: Range1 = [INT.LAST, INT.FIRST];
fullRange1: Range1 = [INT.FIRST, INT.LAST];
nullRange2: Range2 = ALL[nullRange1];
fullRange2: Range2 = ALL[fullRange1];
Histogram: TYPE = REF HistogramRep;
HistogramRep: TYPE;
Create1D: PROC--makes a 1D histogram
[
factor: REAL ¬ 1.0,
offset: REAL ¬ 0.0,
logarithmic: BOOL ¬ FALSE,
BinNamer: BinNameProc ¬ NIL,
clientData: REF ANY ¬ NIL]
RETURNS [Histogram];
Make a new one. All counters start at zero. If logarithmic, then center x of bin I is offset*factor^i; otherwise it is offset+factor*I.
Create2D: PROC
[
iFactor, jFactor: REAL ¬ 1.0,
iOffset, jOffset: REAL ¬ 0.0,
logI, logJ: BOOL ¬ FALSE,
BinNamer: BinNameProc ¬ NIL,
clientData: REF ANY ¬ NIL]
RETURNS [Histogram];
BinNameProc: TYPE ~ PROC [clientData: REF ANY, i, j: NATURAL] RETURNS [ROPE];
For giving bin names.
Increment: PROC [h: Histogram, i: NATURAL] =
INLINE {Change[h, i, 1]};
increment counter number i.
Decrement: PROC [h: Histogram, i: NATURAL] =
INLINE {Change[h, i, -1]};
decrement counter number i:
Change: PROC [h: Histogram, i: NATURAL, howMuch: INTEGER];
Change counter number i. Works only for 1D histograms.
IncrementTransformed: PROC [h: Histogram, xmin, xmax, x: REAL];
Force x inside [xmin .. xmax], inverse transform by factor & offset, round, and Increment.
ChangeTransformed: PROC [h: Histogram, x: REAL, y: REAL ¬ 0.0, delta: INTEGER ¬ 1];
Works for 1D or 2D Histograms.
Change1DTransformed: PROC [h: Histogram, x: REAL, delta: INTEGER ¬ 1];
Works only for 1D Histograms.
ClearAll: PROC [h: Histogram];
Sets all counters to 0.
AddFrom: PROC [h: Histogram, from: IO.STREAM];
}.