6.6.1.1 Replay-Set Operations

Method: empty? (replay-set)  rs

Returns true iff rs is empty. O(1).

Method: size (replay-set)  rs

Returns the number of elements in rs. O(1).

Method: arb (replay-set)  rs

Returns an arbitrary element of rs. Specifically, on a nonempty replay set, returns two values: an arbitrary element and true; on an empty one, returns two false values. O(1).

Method: first (replay-set)  rs

If rs is nonempty, returns its first element (the first one added to it) and a true second value; otherwise, nil and false. O(1).

Method: last (replay-set)  rs

If trs is nonempty, returns its last element (the one most recently added to it) and a true second value; otherwise, nil and false. O(1).

Method: index (replay-set)  rs x

Returns the index of x within the ordering of rs, or nil if it is not found. NOTE: O(n).

Method: at-index (replay-set)  rs idx

Returns the element at index idx within the ordering of rs. Signals an error if idx is out of bounds. O(log n).

Method: contains? (replay-set)  rs x

Returns true iff x is an element of rs. O(log n).

Method: lookup (replay-set)  rs x

If rs contains x, returns two values, true and the element found; else false and nil. (This is useful for canonicalizing instances; the element found may be a different instance from x.) O(log n).

Method: with (replay-set)  rs x

Returns a replay set, of the same class and organization as s, that contains all elements of s and also x. If s did not already contain x, x is appended to the set’s ordering. O(log n).

Macro: includef rs x

A modify macro that expands to with. If place rs (which must be setf-able) holds a replay set, updates it to contain x.

Method: less (replay-set)  rs x

Returns a set, of the same class and organization as rs, that contains all elements of rs except x. NOTE: O(n).

Macro: excludef rs x

A modify macro that expands to less. If place rs (which must be setf-able) holds a replay set, updates it not to contain x.

Method: union (replay-set set)  rs s

Iterates over s, adding each of its elements to rs, and returning the final value of rs. That is, if s is itself a replay set, its elements that are not already in rs will be added in order to the end of rs. O(size(s) log size(rs)).

Method: intersection (replay-set set)  rs s

Iterates over rs, retaining each of its elements that is also in s. That is, the result contains the elements that are in both sets, in the order in which they appear in rs. O(size(rs) log size(s)).

Method: iterator (replay-set)  s

Returns a stateful iterator over the set, in replay order (the order in which elements were first added). The :get operation returns two values: if there is another element remaining, returns it and a true second value, else nil and false. Creating an iterator takes O(log n) time; the :get operation is amortized O(1).

Method: fun-iterator (replay-set)  s

Returns a functional iterator over the set, in replay order (the order in which elements were first added). The :first operation returns two values: if the iterator is not empty, returns the first element and a true second value, else nil and false. Creating an iterator takes O(log n) time; the :first operation is O(1), and :rest is amortized O(1).