Schedule.mesa
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reserved.
Bertrand Serlet April 15, 1987 4:24:55 pm PDT
Christian Le Cocq October 13, 1987 4:46:57 pm PDT
Schedule provides two sets of procs to deal with time oriented objects. One for lists of timed values, the other for lists of timed actions to do.
DIRECTORY
RedBlackTree;
Schedule: CEDAR DEFINITIONS
~ BEGIN
UNITS
ps: TYPE = REAL;  -- picosecond (1e-12 s)
History management package
History: TYPE = LIST OF HistoryPt; --the event data representation. An History is time ordered.
HistoryPt: TYPE = RECORD [t: ps, v: REAL];
CreateHistory: PROC [t: ps, v: REAL] RETURNS [newHistory: History];
creates a one HistoryPt History.
KillHistory: PROC [history: History];
destroys the history structure in order to improve GC.
AddToHistory: PROC [oldHistory: History, t: ps, v: REAL] RETURNS [newHistory: History];
adds a new HistoryPt to oldHistory, and erases any HistoryPt with larger t. If you add in the middle of an History the "old Future" is forgotten.
ForgetBeginings: PROC [oldHistory: History, t: ps] RETURNS [newHistory: History];
destroys any HistoryPt with time less than t.
FirstTimeOfHistory: PROC [history: History] RETURNS [t: ps];
returns the first time of history.
NextTimeOfHistory: PROC [history: History, t: ps] RETURNS [tnext: ps ← -1];
returns the time of the HistoryPt following t in history.
LastTimeOfHistory: PROC [history: History] RETURNS [t: ps];
returns the last time of history
LastValueOfHistory: PROC [history: History] RETURNS [v: REAL];
returns the last v of history
VFromHistory: PROC [history: History, t: ps] RETURNS [v: REAL];
returns the interpolated value at t from history. ERROR if t is before the first time of history.
EnumerateHistory: PROC [history: History, from, to: ps, action: HistoryProc] RETURNS [invalidEnumeration: BOOLFALSE];
applies action to each HistoryPt which time lies between from and to.
HistoryProc: TYPE = PROC [t: ps, v: REAL] RETURNS [quit: BOOLEANFALSE];
Schedule: PROC [hList: LIST OF History] RETURNS [lt: LIST OF ps];
returns the merged ordered list of all the times of all the History.
Agenda Gestion
Agenda: TYPE = REF AgendaRec;
AgendaRec: PRIVATE TYPE = MONITORED RECORD [
execute: ExecuteProc, --the proc to call for each event of the list
list: LIST OF Event, --the ordered list of refs to proceed
table: RedBlackTree.Table, --the tree of events to proceed
nbOfEvents: INT ← 0, --statistical purposes
data: REF ANY--whatever you want, I swear I won't touch it.
];
Event: TYPE = RECORD [
t: ps,
ref: REF ANY
];
ExecuteProc: TYPE = PROC [ref: REF ANY, t: ps, data: REF ANY];
CreateAgenda: PROC [execute: ExecuteProc, data: REF ANY] RETURNS [newAgenda: Agenda];
creates a new Agenda initialized with execute and data.
KillAgenda: PROC [agenda: Agenda];
destroys the agenda structure in order to improve GC.
InsertInAgenda: PROC [agenda: Agenda, ref: REF ANY, t: ps];
inserts a new event in place in the agenda. Avoids duplications. ERROR if t is before the first time of the event list, or if the agenda is NIL.
ExecuteAgenda: PROC [agenda: Agenda] RETURNS [lastTime: ps];
executes and consumes the agenda.list. Returns the time of the last event executed. Pass the data field of the agenda to the ExecuteProc.
END.