ob@IFI.UIB.NO (Ole Bjorn Tuftedal) (04/04/91)
DEFINITION MODULE GenericSorting;
(* $SEG:=9; *)
(* Richard S. Wiener, SIGPLAN Notices, V19 #3, March 1984, pp 66-72. *)
(* Reference: Wiener, R.S., Sincovec, R.F., "Programming in Ada",
pp 294-297, John Wiley and Sons. *)
(*
Richard S. Wiener,
Department of Computer Science,
University of Colorado at Colorado Springs
Colorado Springs, Colorado 80907, U S A.
*)
(* Related modules: IMPLEMENTATION MODULE GenericSorting,
file name GENERICS.MOD
MODULE TstGenSorting;
file name TSTGENSO.MOD *)
FROM SYSTEM IMPORT WORD;
EXPORT QUALIFIED (* proc *) GenericSort;
TYPE UserProc = PROCEDURE(ARRAY OF WORD, ARRAY OF WORD): BOOLEAN;
(* The client program must supply a procedure that compares
two words of the type to be sorted. *)
PROCEDURE GenericSort(VAR ObjectArray: ARRAY OF WORD;
object1, object2: ARRAY OF WORD;
GreaterThan: UserProc); (* greater *)
(* GenericSort inputs an array of objects and returns the sorted
array of objects. The sorting is performed in-place, using
blocks of word, and the result is returned to the client program's
array of objects.
The first, reference, parameter is an array of objects.
The purpose of object1 and object2 is to provide workspace of the
correct word size.
The last parameter is a procedure parameter that enables a comparison
to be performed between two objects of the type being sorted.
The client program's object comparison procedure must exactly match
the specification given, i.e. it must have two ARRAY OF WORD parameters
and return a boolean result. *)
END GenericSorting.
Ole-Bjorn Tuftedal
University of Bergen, Norway
Internet: tuftedal@ifi.uib.no
Bitnet: sinot@nobergen