pub struct BitsetDomain { /* private fields */ }Expand description
A domain backed by a 128-bit bitmask.
Values must be non-negative integers in the range 0..128.
All operations are O(1) via bitwise arithmetic and popcount.
Isomorphic to the Python BitsetDomain.
Implementations§
Source§impl BitsetDomain
impl BitsetDomain
Sourcepub fn new(values: impl IntoIterator<Item = u32>) -> Self
pub fn new(values: impl IntoIterator<Item = u32>) -> Self
Create a new bitset domain from an iterator of values.
§Panics
Panics if any value is >= 128. This is a release-mode assert!,
not a debug_assert! (R7): a bare 1u128 << v with v >= 128 does not
fault in release — Rust masks the shift to v % 128, silently aliasing
out-of-range values onto valid bits. Since new/range are reachable
from the published py/wasm bindings with caller-supplied values, the
0..128 invariant must fail loudly in every build. Both are
construction-time (not hot), so the branch is free; see add for the
hot-path rationale.
Sourcepub fn range(n: u32) -> Self
pub fn range(n: u32) -> Self
Create a domain containing 0..n.
§Panics
Panics if n > 128 (release-mode; see BitsetDomain::new for the R7
rationale — (1u128 << n) - 1 masks n to n % 128 in release,
silently truncating the range).
Sourcepub fn union_with(&mut self, other: &Self)
pub fn union_with(&mut self, other: &Self)
Union with another bitset domain.
Sourcepub fn intersect_with(&mut self, other: &Self)
pub fn intersect_with(&mut self, other: &Self)
Intersection with another bitset domain.
Sourcepub fn difference_with(&mut self, other: &Self)
pub fn difference_with(&mut self, other: &Self)
Difference: remove all values present in other.
Sourcepub fn iter(&self) -> BitsetIter ⓘ
pub fn iter(&self) -> BitsetIter ⓘ
Iterate over set bits, yielding each value.
Trait Implementations§
Source§impl Clone for BitsetDomain
impl Clone for BitsetDomain
Source§fn clone(&self) -> BitsetDomain
fn clone(&self) -> BitsetDomain
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BitsetDomain
impl Debug for BitsetDomain
Source§impl Domain for BitsetDomain
impl Domain for BitsetDomain
Source§fn restrict_to(&mut self, val: &u32) -> impl Iterator<Item = u32> + use<>
fn restrict_to(&mut self, val: &u32) -> impl Iterator<Item = u32> + use<>
O(1) restrict: clear every bit but val’s in one bitwise AND,
instead of the trait default’s O(domain size) iterate-and-clear
loop. Returns a BitsetIter (zero-alloc) over the cleared bits.
Source§fn remove(&mut self, val: &u32) -> bool
fn remove(&mut self, val: &u32) -> bool
true if the value was present.