pub struct BitIndex(/* private fields */);Expand description
A value a BitSet can actually hold: non-negative, and small enough that
the word vector backing it stays a real allocation.
This is the only route from a user-supplied Int to a bit position (RT-07),
so the range check happens where the value enters, once. A negative member
and one whose word vector the host could not serve are both unrepresentable
rather than merely unreached.
Implementations§
Source§impl BitIndex
impl BitIndex
Sourcepub const MAX: i64
pub const MAX: i64
The largest member a BitSet accepts: 2^32 - 1, whose word vector is
512 MiB. A cap rather than “anything a usize holds”, for the same
reason GridExtent::MAX_CELLS
is one — a Vec request the host cannot serve is not an error the
process survives.
Sourcepub const MAX_WORDS: usize
pub const MAX_WORDS: usize
The most words a BitSet can ever hold, which is
MAX/64 + 1.
This bound is what lets generated code omit the range test
(ADR-118 part 2). bs.contains(x) inline is word = (x as u64) >> 6; if word >= words.len() { false } else { … }, with no separate check
that x is a member BitIndex::new would accept — because for every
i64 outside 0..=MAX the unsigned shift already lands at or above
this number, and the word count never reaches it:
x < 0→x as u64 >= 2^63→word >= 2^57;x > MAX→x as u64 >= 2^32→word >= 2^26 == MAX_WORDS;- and
BitSetPayload::insertresizes toword + 1for aBitIndex, sowords.len() <= MAX_WORDSalways.
So word >= words.len() subsumes the range test, exactly, for every
value of the type. the_word_probe_generated_code_emits_answers_contains
is that claim checked against contains rather than argued, in the
module that owns the range — small_int’s
the_unsigned_range_test_generated_code_emits_answers_index_of in its
second place.