Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
SortedBags


NAME

SortedBags - sorted collections

SYNOPSIS

CONST ascending = 0;  (* in ascending order *)
CONST descending = 1; (* in descending order *)
TYPE Order = Iterators.Mode; (* ascending, descending *)
TYPE Bag = POINTER TO BagRec;
TYPE BagRec = RECORD (Services.ObjectRec) END;


PROCEDURE Create(VAR bag: Bag; key: Keys.Key); PROCEDURE GetKey(bag: Bag; VAR key: Keys.Key); PROCEDURE Add(bag: Bag; object: Services.Object); PROCEDURE Remove(bag: Bag; object: Services.Object); PROCEDURE Card(bag: Bag): INTEGER; PROCEDURE GetEntries(bag: Bag; order: Order; from, to: Keys.Value; VAR it: Iterators.Iterator);

DESCRIPTION

SortedBags implements (on base of AVLTrees) sorted collections that do not require key values to be unique.

Create creates a sorted bag with key as sorting key. GetKey returns the key previously passed to Create.

Add adds object to bag. Note that it is a fatal error (assertion failed) if object does not support the sorting key of bag. Remove removes object from bag if it belongs to it. Card returns the number of objects stored in bag. GetEntries creates an iterator that returns all objects ranging from from to to in sorted order ascending or descending according to order. In case of identical key values the order is defined by the time of addition. Note that from and to may be NIL to specify the lowest or highest key of bag, respectively.

DIAGNOSTICS

SortedBags does not generate any diagnostics but asserts that objects passed to Add or Remove support the key of bag.

SEE ALSO

AVLTrees
works like this module but requires key values to be unique
Iterators
iteration of object lists
Keys
total order relations

Edited by: borchert, last change: 2000/04/01, revision: 1.1, converted to HTML: 2000/04/01

Oberon || Library || Module Index || Search Engine || Definition || Module