GithubHelp home page GithubHelp logo

bitmaps's People

Contributors

bodil avatar crlf0710 avatar dependabot-preview[bot] avatar fadeevab avatar jeehoonkang avatar vorner 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  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  avatar  avatar

bitmaps's Issues

question

How do I serialize bitmaps (to bytes)? If I use bincode. I can't implement the Serialize interface for it.
thanks

is_full() panics with Bitmap of size 32

checking for is_full with Bitmap of size 32 and all bits set to true, always panics.

 let mut bitmap = Bitmap::<32>::mask(32);

    let z = bitmap.is_full();
    println!("Yes full {:?}", z);
thread 'main' panicked at 'attempt to shift left with overflow', /Users/kumargu/.cargo/registry/src/github.com-1ecc6299db9ec823/bitmaps-3.2.0/src/types.rs:550:1

The Iter implementation is wrong.

as long as the SIZE bit is set (which is out of bound), it will appears in iter result.

related to: #22 #18

    #[test]
    fn test_invert_iter() {
        let bitmap = Bitmap::<7>::from_value(0b11111010);
        assert_eq!(bitmap.into_iter().collect::<Vec<_>>(), vec![1, 3, 4, 5, 6]);
    }

Undefined behaviour with bool storage type

This is because boolean values don't support all bit patterns.

An object with the boolean type has a size and alignment of 1 each. The value false has the bit pattern 0x00 and the value true has the bit pattern 0x01. It is undefined behavior for an object with the boolean type to have any other bit pattern.

https://doc.rust-lang.org/reference/types/boolean.html

Both these tests fail when run with Miri:

#[test]
fn test1() {
    let _ = Bitmap::<1>::try_from([0xff].as_slice());
}

#[test]
fn test2() {
    let mut bm = Bitmap::<1>::new();
    bm.as_mut()[0] = 0xff;
    let _ = bm.into_value();
}
test test1 ... error: Undefined Behavior: constructing invalid value at .value: encountered 0xff, but expected a boolean
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/bitmaps-3.2.1/src/bitmap.rs:144:27
    |
144 |                     data: data.assume_init(),
    |                           ^^^^^^^^^^^^^^^^^^ constructing invalid value at .value: encountered 0xff, but expected a boolean
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
    = note: BACKTRACE on thread `test1`:
    = note: inside `<bitmaps::Bitmap<1> as std::convert::TryFrom<&[u8]>>::try_from` at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/bitmaps-3.2.1/src/bitmap.rs:144:27: 144:45
test test2 ... error: Undefined Behavior: constructing invalid value at .data: encountered 0xff, but expected a boolean
 --> lib.rs:9:10
  |
9 |     let _ = bm.into_value();
  |             ^^ constructing invalid value at .data: encountered 0xff, but expected a boolean
  |
  = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
  = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
  = note: BACKTRACE on thread `test2`:
  = note: inside `test2` at lib.rs:9:10: 9:12

last_[false_]index support, next_index / prev_index

For all uXXX there's leading_zeroes and trailing_zeroes, but this last operation is not useable in bitmaps.

I'd like to use these operations for getting the last entry of the bitmap, but this is currently impossible to do in this manner. Finding the last entry is difficult.

Similarly, for iterating over the entries in the bitmap, it would be tremendously helpful if either an iterator were implemented for Bitmap, or a set of operations next_index / prev_index would be implemented.

next_index(after: usize) can technically be derived from (mask(index).invert() & map).first_index(), but that's a waste of cycles making, inverting and applying the mask, if this same operation could be done efficiently on the bitmap store itself.
For prev_index (next_index but now backwards) I could not determine an efficient method for determining a previous index based on some offset, due to the lack of last_index-support.

Add as_value() method

Hello,

Would it be possible to have a method as_value() on Bitmap ?

I guess the implementation would simply be:

    pub fn as_value(&self) -> &Size::Store {
        &self.data
    }

Besides, the reason I am trying to get the underlying value is to be able to implement PartialOrd, Eq, Ord, and Hash on a custom type that uses a Bitmap.
Is there any reason why those implementations are not available out of the box even though the underlying value implement them ?

BUG: iterator out of range

The following test failes for the last assert. The iterator yields 0,1,2,3 which is out of range.

#[test]
fn iterate_in_range() {
    let mut m = bitmaps::Bitmap::<3>::new();
    m.invert();
    let mut iter = m.into_iter();
    assert_eq!(iter.next(), Some(0));
    assert_eq!(iter.next(), Some(1));
    assert_eq!(iter.next(), Some(2));
    // assert_eq!(iter.next(), Some(3));
    assert_eq!(iter.next(), None);
}

Invalid Index after inverting a bitmap

When using .invert() on a Bitmap<SIZE> and then iterating over the indices, SIZE appears as an index.
Minimal working example:

use bitmaps::{
	Bitmap,
};
fn main() {

    let mut my_map: Bitmap<4> = Bitmap::new();
    my_map.set(0,true);
    my_map.set(2,true);
    println!("== TRUE =============");
    for index in &my_map{
        println!("index: {}", index);
        //println!("value: {}", my_map.get(index));
    }

    my_map.invert();
    println!("== FALSE ============");
    for index in &my_map{
        println!("index: {}", index);
        //println!("value: {}", my_map.get(index));
    }
}

Expected Output:

== TRUE =============
index: 0
index: 2
== FALSE ============
index: 1
index: 3

Actual Output:

== TRUE =============
index: 0
index: 2
== FALSE ============
index: 1
index: 3
index: 4

This becomes especially dramatic when you un-comment lines 12 and 19 as it results in the program panicking.

Cargo.toml:

[Dependencies]
bitmaps = "3.2.0"

Need a method

I want build a bitmap from a array of u8. Like this:

let data = [u8; 1024];
//read data from file

let bmap = BitMpa::from(data)

Support booleans with symbolic names?

I'm unnerved by passing around naked booleans, for fear the sense will be misinterpreted, incompatible boolean parameters silently swapped, etc.

Could there be a sensible way to allow symbolic values to be used in a bitmap?

In my case, to represent whether a pushbutton key is pressed or not, I defined:

pub enum KeyPosition {
    Up,
    Down,
}

But to use this in a bitmap I have to keep converting to and from bool. Could bitmap be extended to hold something like my enum? (Or is this possible already and I don't spot it?)

Thanks,

-kb

invalid license in crate metadata: MPL-2.0+

This was noticed due to a complete audit of all source code licenses shipped as part of Fedora Linux.

The package.license field in Cargo.toml is interpreted as an "SPDX 2.1 license expression", and must contain only values from the "SPDX license list 3.11" according to the cargo reference docs:

https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields

This crate specifies its license as MPL-2.0+ (I assume this is supposed to mean "MPL-2.0 or any later version"), but this is not a valid SPDX identifier.

The official list of all valid identifiers is available here: https://spdx.org/licenses/

This list does not contain a variant of MPL-2.0 that also accepts any later versions.

Would it be possible to change the specified license to just "MPL-2.0"? It is the closest valid match.

Thank you!

Mask assertion

Please correct me if I'm wrong, but isn't the assertion of mask() slightly wrong

debug_assert!(bits < SIZE);

and should be correctly debug_assert!(bits <= SIZE); instead?

As I understand it, the assertions currently prevent the masking of the complete Bitset as the last index cannot be included.

Looking forward to your opinion.

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.