Histograms.Mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by: Spreitzer, May 24, 1985 3:38:32 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>, where their bounds are specified at creation time. Again, all counters are allocated, so keep bounds reasonable.
DIRECTORY Rope, IO, ViewerClasses;
Histograms: CEDAR DEFINITIONS =
BEGIN
ROPE: TYPE = Rope.ROPE;
Histogram: TYPE = REF HistogramRep;
HistogramRep: TYPE;
NewHistogram: PROCEDURE--makes a 1D histogram
[
factor: REAL ← 1, --x = I*factor + offset
offset: REAL ← 0]
RETURNS [Histogram];
Make a new one. All counters start at zero.
Create2D: PROC
[
iMin, iMax, jMin, jMax: INT, --bounds are inclusive on both ends
iFactor, jFactor: REAL ← 1, --x = I*iFactor + iOffset
iOffset, jOffset: REAL ← 0] --y = J*jFactor + jOffset
RETURNS [Histogram];
Increment: PROCEDURE [h: Histogram, i: CARDINAL] =
INLINE {Change[h, i, 1]};
increment counter number i.
Decrement: PROCEDURE [h: Histogram, i: CARDINAL] =
INLINE {Change[h, i, -1]};
decrement counter number i:
Change: PROCEDURE [h: Histogram, who: CARDINAL, howMuch: INTEGER];
change counter number who
IncrementTransformed: PROCEDURE [h: Histogram, xmin, xmax, x: REAL];
Inverse Transform x by factor & offset, Round, and Increment
ChangeTransformed: PROC [h: Histogram, x: REAL, y: REAL ← 0, delta: INTEGER ← 1];
Works for 1D or 2D Histograms.
ClearAll: PROC [h: Histogram];
Sets all counters to 0.
WriteTo: PROCEDURE [h: Histogram, to: IO.STREAM];
list non-zero counters
Show: PROCEDURE [
h: Histogram,
viewerInit: ViewerClasses.ViewerRec ← [],
format: ROPENIL, --NIL means "%d"
width: CARDINAL ← 0, --max number of chars produced when formatting
iFreq: CARDINAL ← 0, --label every iFreq'th bin
paint: BOOLTRUE] RETURNS [ViewerClasses.Viewer];
display it in a viewer
END.