Expand description
§grit-bitvec
This crate provides variants of BitVec
data structure, a vector that can store data elements of fixed-size bit widths
that do not fall into the 8/16/32/64/128 size categories. For example, rather than storing a vector of bool
s in one
byte each, you can store them each as one bit. Another example would be storing unsigned integers that are always in the
range 0-3 as exactly 2 bits, 0-7 as 3 bits, 0-15 as 4 bits, or even a signed integer in the range -1024 to 1023 as 11 bits
or a struct with 4 bools and 1 u8 in the range of 0-7 as a total of 7 bits.
RawBitVec
: the base structure that all other variants wrap. Requires aBitProto
to be passed to every function, and is UNSAFE if the sameBitProto
isnt used for all method calls on the sameRawBitVec
instanceCProtoBitVec<BIT_WIDTH>
: a wrapper that takes the neededBitProto
and stores it in a monomorphized constant for every separate<BIT_WIDTH>
SProtoBitVec
: a wrapper that keeps a static reference to the neededBitProto
in every instanceLProtoBitVec
: a wrapper that keeps a full copy of theBitProto
in every instanceTypedBitVec<T: TypedBitElem>
: a wrapper that not only stores theBitProto
in a monomorphized constant, but the needed functions to translate the raw returned bits into type<T>
All versions use usize
as the underlying data block type to take advantage of any possible arithmetic optimizations on
native-size words, meaning that the maximum bit-width supported is the same as usize::BITS
This allows considerable gains in memory usage for applications where the number of elements may be non-trivial, at the cost of processing time to access the elements.
The additional processing cost is not terrible in most cases, as it is mostly performed with bitwise shifts and simple
arithmetic, and is further reduced by using constant propogation when applcable to reduce many bitwise math functions
to their easiest possible form. However they are not free, and operations that insert or remove elements in the middle
of the BitVec
may be even more costly due to the need to run those checks and shifts on every element rather than using
ptr::copy()
like Vec
does internally
By default the small_int_impls
feature is enabled, providing simple TypedBitElem
implementations for bool
and
integer types smaller than 16 bits (for example u8_as_u3
or i16_as_i11
), and the large_int_impls
feature can
be activated to get similar implementations for bit widths less than usize::BITS
§Tested Functions
- new()
- with_capacity()
- len()
- cap()
- free()
- clear()
- grow_exact_for_total_elements_if_needed()
- grow_exact_for_additional_elements_if_needed()
- grow_for_total_elements_if_needed()
- grow_for_additional_elements_if_needed
- push()
- pop()
- insert()
- remove()
- insert_bitvec()
- insert_iter()
- remove_range()
- trim_range()
- swap()
- swap_pop()
- shrink_excess_capacity()
- append_bitvec()
- append_iter()
- get()
- set()
- replace()
- drain()
- into_iter()
- discard_from_end()
This crate currently has incomplete documentation and is very much in the “unstable” phase. The API may change in the future
Structs§
- BitProto
- CProto
BitVec CProtoBitVec
: “Constant Prototype Bitwise Vector”- CProto
BitVec Drain - CProto
BitVec Iter - IdxProxy
- LProto
BitVec LProtoBitVec
: “Local Prototype Bitwise Vector”- LProto
BitVec Drain - LProto
BitVec Iter - RawBit
Vec RawBitVec
: “Raw Bitwise Vector”- RawBit
VecDrain - RawBit
VecIter - SProto
BitVec SProtoBitVec
: “Static Prototype Bitwise Vector”- SProto
BitVec Drain - SProto
BitVec Iter - Typed
BitVec TypedBitVec
: “Typed Bitwise Vector”- Typed
BitVec Drain - Typed
BitVec Iter - i8_
as_ i1 - i8_
as_ i2 - i8_
as_ i3 - i8_
as_ i4 - i8_
as_ i5 - i8_
as_ i6 - i8_
as_ i7 - i16_
as_ i9 - i16_
as_ i10 - i16_
as_ i11 - i16_
as_ i12 - i16_
as_ i13 - i16_
as_ i14 - i16_
as_ i15 - u8_
as_ u1 - u8_
as_ u2 - u8_
as_ u3 - u8_
as_ u4 - u8_
as_ u5 - u8_
as_ u6 - u8_
as_ u7 - u16_
as_ u9 - u16_
as_ u10 - u16_
as_ u11 - u16_
as_ u12 - u16_
as_ u13 - u16_
as_ u14 - u16_
as_ u15