file name: alggen.hpp, alggen.cpp
classification: simulation
contents: struct SAsymInterval, several constants, several functions
use: provides some structures, constants and functions that
are needed by more than one synchronization algorithm
global items used:
structs:
struct SAsymInterval:
Represents an asymmetrical interval with three members of type double,
namely ref (the reference point), left (the left endpoint),
right
(the right endpoint).
global constants:
const INT32
Infinity: Contains the value representing infinite accuracy in UTCSU
format.
const INT32
HighestAccuracyBit: Contains the number of the highest bit in the
timestamp that is covered by the accuracy, as seen from the lsb of the
timestamp (lsb = -24, highest bit = -8).
const INT32
HighestAccuracyValue: Contains the highest value in the timestamp
that is covered by the accuracy.
const INT32
WidthOfChars: This value is only needed for debug output, it denotes
the number of characters used by ftoa() to print
values in %e format.
global functions:
EBool ApplyMarzullo
(SAsymInterval* input, SAsymInterval& output, INT32 size, int f):
Implements the Marzullo function, where size gives the number
of input interval and f the maximum number of faulty ones in input.
When the computation is successful, it returns True and hands back the
Marzullo interval in output, otherwise it returns False and output
remains unchanged. If input is NULL, an assert fails.
void SortArray
(double* unsortedArray, double* sortedArray, INT32 size): An array
unsortedArray
of size doubles is sorted in ascending order into another array
sortedArray. If either sortedArray or unsortedArray
is NULL, or if size <= 0, an assert fails.
EBool Intersect
(const SAsymInterval& In1, const SAsymInterval& In2, SAsymInterval&
Out): The functions returns True when the input intervals
In1
and In2 have a non-empty intersection, otherwise False. In the
non-empty case, interval Out hands back that intersection, where
the reference point is set to the midpoint. In the empty case, interval
Out
is not valid!
SExtendedTimestamp
IntervalToClock (CNtpTime point, double alpha_minus, double alpha_plus):
Converts
an interval given by point, alpha_minus,
alpha_plus
into type SExtendedTimestamp. In case of an accuracy interval
overflow, the according length is set to the limit of the accuracy value
encoded by Infinity.