src/necsus/util/bits

Types

Bits = ref object
A bitset without a limit on the number of bits that can be set.
BitsFilter = ref object
Uses bitsets to determine whether another bit set 'matches' a set of conditions

Procs

proc `$`(bitset: Bits): string {....raises: [], tags: [], forbids: [].}
proc `+`(a, b: Bits): Bits {....raises: [], tags: [], forbids: [].}
Union of two sets
proc `+=`(a: var Bits; b: Bits) {....raises: [], tags: [], forbids: [].}
Union of two sets
proc `-`(a, b: Bits): Bits {....raises: [], tags: [], forbids: [].}
Remove elements of set b from set a and return the new value
proc `<`(a, b: Bits): bool {....raises: [], tags: [], forbids: [].}
Returns whether a is a strict subset of b. Nim derives > from this automatically, which gives back a strict superset check
proc `<=`(a, b: Bits): bool {....raises: [], tags: [], forbids: [].}
Returns whether a is a subset of b
proc `==`(a, b: Bits): bool {....raises: [], tags: [], forbids: [].}
Returns whether two sets contain the exact same set of values
proc `==`(a, b: BitsFilter): bool {....raises: [], tags: [], forbids: [].}
proc acceptsAll(filter: BitsFilter): bool {....raises: [], tags: [], forbids: [].}
Whether this filter lets through every possible set of bits
proc anyIntersect(a, b: Bits): bool {....raises: [], tags: [], forbids: [].}
Returns whether any of the bits overlap
proc card(bitset: Bits): int {....raises: [], tags: [], forbids: [].}
The number of bits that have been set -- the cardinality
proc combine(source, attach, remove: Bits): Bits {....raises: [], tags: [],
    forbids: [].}
(source + attach) - remove in a single pass. Either attach or remove may be nil, meaning there is nothing to add or nothing to take away.
proc contains(bitset: Bits; value: uint16): bool {....raises: [], tags: [],
    forbids: [].}
Returns whether any of the bits overlap
proc hash(bitset: Bits): Hash {....raises: [], tags: [], forbids: [].}
proc hash(filter: BitsFilter): Hash {....raises: [], tags: [], forbids: [].}
proc incl(bitset: var Bits; value: uint16) {....raises: [], tags: [], forbids: [].}
Add a value to this set
proc intersect(a, b: Bits): Bits {....raises: [], tags: [], forbids: [].}
The bits the two sets have in common
proc isEmpty(bitset: Bits): bool {....raises: [], tags: [], forbids: [].}
Whether no bits at all are set
proc isSubsetOfUnion(a, b, c: Bits): bool {....raises: [], tags: [], forbids: [].}
Whether a is a subset of b + c, without building the union to find out
proc matches(filter: BitsFilter; all: Bits): bool {....raises: [], tags: [],
    forbids: [].}
Whether a target matches a filter
proc matches(filter: BitsFilter; all: Bits; optional: Bits): bool {....raises: [],
    tags: [], forbids: [].}
Whether a target matches a filter, disregarding any optional components
proc mentioned(filter: BitsFilter): Bits {....raises: [], tags: [], forbids: [].}
Every component a filter asks after, whether it insists on one or rules it out. A caller that wants to know which components a filter can tell apart wants this
proc newBits(values: varargs[uint16]): Bits {....raises: [], tags: [], forbids: [].}
Create a new bit set
proc newFilter(mustContain, mustExclude: Bits): BitsFilter {....raises: [],
    tags: [], forbids: [].}
Creates a new filter
proc withoutRequired(filter: BitsFilter; component: uint16): BitsFilter {.
    ...raises: [], tags: [], forbids: [].}
The same filter, minus one component it requires. Useful where a caller has already established that component is present and would rather not pay to confirm it

Iterators

iterator items(bitset: Bits): uint16 {....raises: [], tags: [], forbids: [].}
Returns the index of every bit that has been set, from lowest to highest
iterator required(filter: BitsFilter): uint16 {....raises: [], tags: [],
    forbids: [].}
Yields every component a filter insists on being present. A set missing any one of these can never match, which makes them usable as a cheap precondition