In addition to the tree itself, MULTOPS maintains a doubly-linked list of
pointers to nodes in the tree using prev
and next
in
Table
. Each time a new node is created in the tree, i.e., expansion
occurs, a pointer to that node is added at the end of the linked list. During
a cleanup, the list is traversed. A node (and all its children) is deleted
when the sum of all from-rates and the sum of all to-rates in that node are
both lower than the expand threshold. (Both sums are, by definition, stored as
from-rate and to-rate in the parent record of that node; hence the need for
the parent
pointer in Table
.) The root node is never deleted.
The list is either traversed backwards or forwards to avoid checking the same
nodes every time thereby causing starvation-like phenomena.
To avoid heavy memory fluctuations and to avoid spending too much time on a single cleanup, contraction stops when a certain fraction of all allocated memory has been freed. If none of the nodes can be deleted, but memory is at its imposed maximum, then some nodes must be deleted. In that case, the expand threshold is decreased by some factor and the cleanup starts again. This may have to be repeated multiple times until fraction of all memory has been freed.