Sequence Utility (#32)

A sequence is a set of integers (*)
This package supplies the following verbs:

:add (seq,f,t) => seq with [f..t] interval added
:remove (seq,f,t) => seq with [f..t] interval removed
:range (f,t) => sequence corresponding to [f..t]
{} => empty sequence
:includes (seq,n) => n in seq
:size (seq) => number of elements in seq
:first (seq) => first integer in seq or E_NONE
:firstn (seq,n) => first n integers in seq (as a sequence)
:last (seq) => last integer in seq or E_NONE
:lastn (seq,n) => last n integers in seq (as a sequence)

:complement(seq) => [-2147483648..2147483647] - seq
:union (seq,seq,...)

:extract(seq,array) => array[@seq]
:for([n,]seq,obj,verb,@args) => for s in (seq) obj:verb(s,@args); endfor

:tolist(seq) => list corresponding to seq
:tostr(seq) => contents of seq as a string
:from_list(list) => sequence corresponding to list
:from_sorted_list(list) => sequence corresponding to list (assumed sorted)
:from_string(string) => sequence corresponding to string

For boolean expressions, note that
the representation of the empty sequence is {} (boolean FALSE) and
all non-empty sequences are represented as nonempty lists (boolean TRUE).

The representation used works better than the usual list implementation for sets consisting of long uninterrupted ranges of integers.
For sparse sets of integers the representation is decidedly non-optimal (though it never takes more than double the space of the usual list representation).

(*) Actually what this package implements is sets of integers-mod-2^32, but this assumes the underlying machine on which the server runs has 32-bit integers. If not, you need to change this.maxneg to be the largest negative ("smallest"?) integer available.

You are not logged in.

[home | help | who | search | setup | code]