ArraySort.def 1.1 KB

1234567891011121314151617181920212223242526
  1. DEFINITION MODULE ArraySort;
  2. (*
  3. Module: Array sorting module
  4. Author: Ceriel J.H. Jacobs
  5. Date: $Id$
  6. Interface is like the qsort() interface in C, so that an array of values
  7. can be sorted. This does not mean that it has to be an ARRAY, but it does
  8. mean that the values must be consecutive in memory, and the order is the
  9. "memory" order.
  10. The user has to define a comparison procedure of type CompareProc.
  11. This routine gets two pointers as parameters. These are pointers to the
  12. opbjects that must be compared. The sorting takes place in ascending order,
  13. so that f.i. if the result of the comparison is "less", the first argument
  14. comes in front of the second.
  15. *)
  16. FROM SYSTEM IMPORT ADDRESS; (* no generics in Modula-2, sorry *)
  17. TYPE CompareResult = (less, equal, greater);
  18. CompareProc = PROCEDURE(ADDRESS, ADDRESS): CompareResult;
  19. PROCEDURE Sort(base: ADDRESS; (* address of array *)
  20. nel: CARDINAL; (* number of elements in array *)
  21. size: CARDINAL; (* size of each element *)
  22. compar: CompareProc); (* the comparison procedure *)
  23. END ArraySort.