Standard library - bitset

module bitset
  // since PR 1782
  type t = ...
  def empty : t
  def isEmpty : t -> bool
  def isNotEmpty : t -> bool
  def contains : number -> t -> bool
  def add : number -> t -> t
  def remove : number -> t -> t
  def singleton : number -> t
  def ofStream : stream(number) -> t
  def ofArray : array(number) -> t
  def toStream : t -> stream(number)
  def toArray : t -> array(number)
  def length : t -> number
  def equal : t -> t -> bool
  def isSubset : t -> t -> bool
  def union : t -> t -> t
  def intersection : t -> t -> t
  def difference : t -> t -> t
module end

Bitsets provide a moderately fast and moderately compact representation of sets of integers (including negative integers). It should be good for average use, in particular when you don’t know yet which operations on bitsets you’ll call. It is implemented as a search tree of vectors with 128 bits each.