6.4.4 WB-Bag Operations

These operations make use of the ordering of the bag, as determined by its comparison function. They are not defined on CHAMP bags.

Method: rank (wb-bag)  s x

If s contains x, returns the rank of x in the ordering defined by the comparison function of s, and a true second value. If x is not in the bag, the second value is false, and the first value is the rank that x would have if it were added. Note that if there are values that are unequal but equivalent to x, an arbitrary order will be imposed on them for this purpose; but another collection that is equal? but not eq to this one will in general order them differently. Multiplicities are ignored for this purpose. O(log n).

Method: at-rank (wb-bag)  s rank

Returns the element whose rank is rank. rank must be in [0 .. size(m)). Note that if there are values that are unequal but equivalent in s, an arbitrary order will be imposed on them for this purpose; but another collection that is equal? but not eq to this one will in general order them differently. Multiplicities are ignored for this purpose. O(log n).

Method: least (wb-bag)  s

If s is nonempty, returns the element at rank 0 and a true second value; otherwise, nil and false.

Method: greatest (wb-bag)  s

If s is nonempty, returns the element with the largest rank and a true second value; otherwise, nil and false.

Method: split-from (wb-bag)  s x

Returns the subbag of s with elements greater than or equal to x. O(log n).

Method: split-above (wb-bag)  s x

Returns the subbag of s with elements strictly greater than x. O(log n) in general; O(1) if x is the result of (arb s).

Method: split-through (wb-bag)  s x

Returns the subbag of s with elements less than or equal to x. O(log n).

Method: split-below (wb-bag)  s x

Returns the subbag of s with elements strictly less than x. O(log n) in general; O(1) if x is the result of (arb s).