Git Product home page Git Product logo

bv-rs's People

Contributors

aeyakovenko avatar mrmaxmeier avatar tov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bv-rs's Issues

Potential Undefined Behavior due to `BitSliceMut::from_slice`

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.

Creating new "Bits" with the first N bits set

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.

no `iter`?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.