(*
    Title: 	Sort - Definitions
    LastEdit:	"Mon Sep 17 14:30:11 1984"
    Author: 	Mick Jordan
		Acorn Research Centre

    General purpose sorting package
*)
DEFINITION MODULE Sort;

FROM SYSTEM IMPORT WORD;

EXPORT QUALIFIED
    Comparator, Sort, INTEGERComparator, CARDINALComparator;

TYPE
    Comparator = PROCEDURE (WORD, WORD): BOOLEAN;


PROCEDURE Sort(VAR data: ARRAY OF WORD; length: CARDINAL; 
                Precedes: Comparator);

(*  'data' must be an unpacked array of UserObjectType,
    where a UserObjectType must be either a basic type or a pointer
    type.  The first data element is assumed to be at the
    low index of the array.

    Beware of ARRAY OF CHAR, which is always packed,
    and does not map to ARRAY OF WORD in the way expected by
    this package.
    
    The 'Precedes' procedure should return TRUE if
    its first argument should precede the second argument in the
    sorted array.
*)


PROCEDURE INTEGERComparator(l, r: WORD): BOOLEAN;
PROCEDURE CARDINALComparator(l, r: WORD): BOOLEAN;
(* pre-defined Comparators which treat their arguments
   as INTEGER and CARDINAL respectively.
*)

END Sort.
