HistogramsPrivate.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
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: BOOL ¬ TRUE,
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: BOOL ¬ FALSE],
twoD => [iFactor, jFactor: REAL ¬ 1.0, iOffset, jOffset: REAL ¬ 0.0, log: BoolPair ¬ ALL[FALSE]],
ENDCASE];
ShowData: TYPE ~ REF ShowDataPrivate;
ShowDataPrivate:
TYPE ~
RECORD [
format: ROPE ¬ NIL,
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:
BOOL ¬
FALSE]
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:
BOOL ¬
FALSE]
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:
BOOL ¬
FALSE]
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 ANY ¬ NIL];
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];
}.