sort.sort-by-key

function

Library: Sorting (OMSORT)
Import : omsort.xmd

Declaration
export function 
   sort-by-key modifiable integer shelf-to-sort
or
export function 
   sort-by-key modifiable stream shelf-to-sort
or
export function 
   sort-by-key modifiable string shelf-to-sort
or
export function 
   sort-by-key modifiable switch shelf-to-sort

Argument definitions

shelf-to-sort
is a keyed shelf of integers, streams, strings, or switches


Purpose

Use sort.sort-by-key to sort shelf-to-sort according to its keys in ascending order. shelf-to-sort can have type integer, stream, string, or switch.

Requirements

shelf-to-sort must have a key for every item, otherwise error 6052 will be thrown).

If shelf-to-sort is a stream shelf, then it must

Example

The following program sorts a list of integers by their keys:

  import "omsort.xmd" prefixed by sort.
  
  process
     local integer integer-test-shelf variable initial { 1 with key "a", 
                                                         2 with key "c", 
                                                         3 with key "b"}
  
     sort.sort-by-key integer-test-shelf
     
     repeat over integer-test-shelf
        output "key " || key of integer-test-shelf 
           ||  "; item " || "%d(integer-test-shelf)%n"
     again

Other Library Functions