Module intsets

The intsets module implements an efficient int set implemented as a sparse bit set. Note: Since Nim currently does not allow the assignment operator to be overloaded, = for int sets performs some rather meaningless shallow copy; use assign to get a deep copy.


hashes, math, sequtils, algorithm


IntSet = object
  elems: int
  counter, max: int
  head: PTrunk
  data: TrunkSeq
  a: array[0 .. 33, int]
an efficient set of 'int' implemented as a sparse bit set


proc contains(s: IntSet; key: int): bool {.raises: [], tags: [].}
returns true iff key is in s.
proc incl(s: var IntSet; key: int) {.raises: [], tags: [].}
includes an element key in s.
proc excl(s: var IntSet; key: int) {.raises: [], tags: [].}
excludes key from the set s.
proc containsOrIncl(s: var IntSet; key: int): bool {.raises: [], tags: [].}
returns true if s contains key, otherwise key is included in s and false is returned.
proc initIntSet(): IntSet {.raises: [], tags: [].}
creates a new int set that is empty.
proc clear(result: var IntSet) {.raises: [], tags: [].}
proc isNil(x: IntSet): bool {.inline, raises: [], tags: [].}
proc assign(dest: var IntSet; src: IntSet) {.raises: [], tags: [].}
copies src to dest. dest does not need to be initialized by initIntSet.
proc `$`(s: IntSet): string {.raises: [], tags: [].}
The $ operator for int sets.
proc empty(s: IntSet): bool {.inline, deprecated, raises: [], tags: [].}
returns true if s is empty. This is safe to call even before the set has been initialized with initIntSet. Note this never worked reliably and so is deprecated.


iterator items(s: IntSet): int {.inline, raises: [], tags: [].}
iterates over any included element of s.

© 2006–2017 Andreas Rumpf
Licensed under the MIT License.