These are more complex sequence functions. The step complexities of these functions are not necessarily .
sort(a) {[a] [a] :: (a in number)}
Sorts the input sequence.
rank(a) {[a] [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)] [(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)] [(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) 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 and an expected step
complexity of .
find(element, seq) {(a, [a]) 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]) [int] :: (a in any)}
Returns indices of all start positions in sequence where the
string specified by subseq appears.
remove_duplicates(s) {[a] [a] :: (a in any)}
Removes duplicates from a sequence. Elements are considered duplicates
if eql on them returns T.
mark_duplicates(s) {[a] [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]) [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]) [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] [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]] [[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.