HistogramsPrivate.mesa
Last tweaked by Mike Spreitzer on June 28, 1988 3:33:27 pm PDT
DIRECTORY Histograms, IO, Real, RealFns, Rope;
HistogramsPrivate: CEDAR DEFINITIONS
IMPORTS Real, RealFns
= {OPEN Histograms;
DataRef: TYPE = REF Data;
Data: TYPE = RECORD [counts: SEQUENCE length:NAT OF Count];
Count: TYPE = CARDINAL;
IntPair: TYPE ~ RECORD [i, j: INTEGER];
Histogram: TYPE = REF HistogramRep;
HistogramRep: TYPE = MONITORED RECORD [
dimensionality: [1 .. 2],
BinNamer: BinNameProc,
data: DataRef,
nI, nJ: INT ← 0,
iFactor, iOffset, jFactor, jOffset: REAL,
x0, y0, xChg, yChg: REAL,
log: BoolPair,
maxCount: Count ← 0,
maxValid: BOOLTRUE,
noters: NoterList ← NIL,
clientData: REF ANY
];
NoterList: TYPE ~ LIST OF Noter;
CreateData: TYPE ~ REF CreateDataPrivate;
CreateDataPrivate: TYPE ~ RECORD [variant: SELECT kind: * FROM
oneD => [factor: REAL ← 1.0, offset: REAL ← 0.0, log: BOOLFALSE],
twoD => [iFactor, jFactor: REAL ← 1.0, iOffset, jOffset: REAL ← 0.0, log: BoolPair ← ALL[FALSE]],
ENDCASE];
ShowData: TYPE ~ REF ShowDataPrivate;
ShowDataPrivate: TYPE ~ RECORD [
format: ROPENIL,
width: NAT ← 0,
base: REAL ← 0.0
];
ReadSpecs: PROC [from: IO.STREAM] RETURNS [create: CreateData ← NIL, show: ShowData ← NIL];
InvertI: PROC [h: Histogram, x: REAL] RETURNS [INTEGER]
~ INLINE {RETURN [Real.Round[((IF h.log[X] THEN RealFns.Ln[x] ELSE x)-h.iOffset)/h.iFactor]]};
InvertJR: PROC [h: Histogram, y: REAL, log: BOOLFALSE] RETURNS [REAL]
~ INLINE {RETURN [((IF h.log[Y]=log THEN y ELSE IF log THEN RealFns.Exp[y] ELSE RealFns.Ln[y])-h.jOffset)/h.jFactor]};
Invert2: PROC [h: Histogram, x, y: REAL] RETURNS [IntPair]
~ INLINE {RETURN [[
i: Real.Round[((IF h.log[X] THEN RealFns.Ln[x] ELSE x)-h.iOffset)/h.iFactor],
j: Real.Round[((IF h.log[Y] THEN RealFns.Ln[y] ELSE y)-h.jOffset)/h.jFactor]
]]};
ExvertI: PROC [h: Histogram, i: REAL, log: BOOLFALSE] RETURNS [x: REAL]
~ INLINE {
x ← i*h.iFactor + h.iOffset;
IF h.log[X]=log THEN NULL ELSE IF log THEN x ← RealFns.Ln[x] ELSE x ← RealFns.Exp[x]};
ExvertJ: PROC [h: Histogram, j: REAL, log: BOOLFALSE] RETURNS [y: REAL]
~ INLINE {
y ← j*h.jFactor + h.jOffset;
IF h.log[Y]=log THEN NULL ELSE IF log THEN y ← RealFns.Ln[y] ELSE y ← RealFns.Exp[y]};
MaybeEx: PROC [x: REAL, log: BOOL] RETURNS [REAL] ~ INLINE {
IF log THEN RETURN RealFns.Exp[x] ELSE RETURN [x]};
Ensure1: PROC [old: DataRef, n: INT] RETURNS [new: DataRef];
Noter: TYPE ~ RECORD [
Note: PROC [REF ANY, Histogram, ChangeNote],
data: REF ANYNIL];
The Note proc is called under the Histogram's monitor.
ChangeKind: TYPE ~ {add, set};
ChangeNote: TYPE ~ RECORD [
range: Range2,
change: SELECT kind: ChangeKind FROM
add => [dn: INTEGER],
set => [n: CARDINAL],
ENDCASE];
AddNoter: PROC [Histogram, Noter];
RemNoter: PROC [Histogram, Noter];
}.