tov / bv-rs Goto Github PK
View Code? Open in Web Editor NEWBit-vectors and bit-slices for Rust
Home Page: https://tov.github.io/bv-rs/bv/
License: Apache License 2.0
Bit-vectors and bit-slices for Rust
Home Page: https://tov.github.io/bv-rs/bv/
License: Apache License 2.0
The lifetime annotations on BitSliceMut::from_slice
can lead to undefined behavior. The following example fails Miri.
extern crate bv;
use bv::{BitVec, BlockType, BitSliceMut, Bits, BitSlice};
fn main() {
let mut myvec: Vec<usize> = Vec::from([0, 1, 0, 1, 1, 0, 0, 1]);
let mut slice = &mut myvec[..];
let mut bitslice = BitSliceMut::from_slice(slice);
drop(slice); // This shouldn't be allowed
let bit = bitslice.get_bit(2);
println!("Bit at position 2: {}", bit);
}
The current signature of this function is
impl<'a, Block: BlockType> BitSliceMut<'a, Block> {
/// Creates a `BitSliceMut` from a mutable array slice of blocks.
///
/// The size is always a multiple of `Block::nbits()`. If you want a different size,
/// slice.
pub fn from_slice(blocks: &mut [Block]) -> Self {
This allows Self
to outlive the slice. If this were modified as:
impl<'a, Block: BlockType> BitSliceMut<'a, Block> {
/// Creates a `BitSliceMut` from a mutable array slice of blocks.
///
/// The size is always a multiple of `Block::nbits()`. If you want a different size,
/// slice.
pub fn from_slice(blocks: &'a mut [Block]) -> Self {
This would prevent the earlier example from compiling and ensure safety.
Hi, your library looks like it's largely suiting my needs to modify generic bitsets of arbitrary length, but I was just wondering if there was a way to set the first N bits of a BitsT : BitsMut
object. I could go with Default::default()
and set the first N bits in a loop but this approach seemed slow, especially in the case BitT
was a multiword bitset. set_bits()
seemed to be what I was looking by it's name but the value
argument was Block
, not bool
so this confused me as to it's usage. Any help appreciated.
i wanted to iterate over every value in the bitvec to append it to another bitvec (I have a HashMap of Value,BitVec)
but there is no way to iterate over each individual bit
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.