next up previous contents index
Next: Functions on Any Type Up: Sequence Functions Previous: Nesting Sequences

Other Sequence Functions

These are more complex sequence functions. The step complexities of these functions are not necessarily tex2html_wrap_inline10525 .

sort(a) {[a] tex2html_wrap_inline10527 [a] :: (a in number)}
  Sorts the input sequence.

rank(a) {[a] tex2html_wrap_inline10529 [int] :: (a in number)}
  Returns the rank of each element of the sequence a. The rank of an element is the position it would appear in if the sequence were sorted. A sort of a sequence a can be implemented as permute(a, rank(a)). The rank is stable.

collect(key_value_pairs) {[(b, a)] tex2html_wrap_inline10531 [(b, [a])] :: (a in any; b in any)}
  Takes a sequence of (key, value) pairs, and collects each set of values that have the same key together into a sequence. The function returns a sequence of (key, value-sequence) pairs. Each key will only appear once in the result and the value-sequence corresponding to the key will contain all the values that had that key in the input.

int_collect(key_value_pairs) {[(int, a)] tex2html_wrap_inline10533 [(int, [a])] :: (a in any)}
  Version of collect that works when the keys are integers. As well as collecting, the subsequences are returned with the keys in sorted order.

kth_smallest(s, k) {([a], int) tex2html_wrap_inline10535 a :: (a in ordinal)}
  Returns the kth smallest element of a sequence s (k is 0 based). It uses the quick-select algorithm and therefore has expected work complexity of tex2html_wrap_inline10537 and an expected step complexity of tex2html_wrap_inline10539 .

find(element, seq) {(a, [a]) tex2html_wrap_inline10541 int :: (a in any)}
  Returns the index of the first place that element is found in seq. If element does not appear in the sequence, then -1 is returned.

search_for_subseqs(subseq, sequence) {([a], [a]) tex2html_wrap_inline10543 [int] :: (a in any)}
  Returns indices of all start positions in sequence where the string specified by subseq appears.

remove_duplicates(s) {[a] tex2html_wrap_inline10545 [a] :: (a in any)}
  Removes duplicates from a sequence. Elements are considered duplicates if eql on them returns T.

mark_duplicates(s) {[a] tex2html_wrap_inline10547 [bool] :: (a in any)}
  Marks the duplicates such that only one instance of each value in a sequence is marked with a true flag. Elements are considered duplicates if eql on them returns T.

union(a, b) {([a], [a]) tex2html_wrap_inline10549 [a] :: (a in any)}
  Given two sequences each which has no duplicates, union will return the union of the elements in the sequences.

intersection(a, b) {([a], [a]) tex2html_wrap_inline10551 [a] :: (a in any)}
  Given two sequences each which has no duplicates, intersection will return the intersection of the elements in the sequences.

name(a) {[a] tex2html_wrap_inline10553 [int] :: (a in any)}
  This function assigns an integer label to each unique value of the sequence a. Equal values will always be assigned the same label and different values will always be assigned different labels. All the labels will be in the range [0..#a) and will correspond to the position in a of one of the elements with the same value. The function remove_duplicates(a) could be implemented as {s in a; i in [0:#a]; r in name(a) | r == i}.

transpose(a) {[[a]] tex2html_wrap_inline10555 [[a]] :: (a in any)}
  Transposes a nested sequence. For example transpose([[2,3,4],[5,6,7]]) would return [[2,5],[3,6],[4,7]]. All the subsequence must be the same length.



next up previous contents index
Next: Functions on Any Type Up: Sequence Functions Previous: Nesting Sequences



Jonathan Hardwick
Tue Nov 28 13:57:00 EST 1995