petgraph / fixedbitset

A simple bitset container for Rust
https://docs.rs/fixedbitset/
Apache License 2.0
124 stars 47 forks source link

Make a version of the fixed bitset actually fixed at compile time #82

Closed EriKWDev closed 1 year ago

EriKWDev commented 1 year ago

I don't know what part of this implementation is "Fixed" since it seems like the bitsets can grow at will and is implemented using a Vec.

It would be cool to instead have the size be known at compile time which would allow allocation-less bitsets:

type Block = usize;
pub struct CTFixedBitSet<const BLOCKS: usize> {
    pub blocks: [Block; BLOCKS],
    pub length: usize,
}

While this would make the Api dependant on blocks instead of the number of bits which might be confusing to a new user, I feel like it could improve performance. Perhaps a macro could be used to calculate the value based on bits? Don't know if that's possible without a proc-macro though.

let mut my_bitset = bitset!(128); // Would create a CTFixedBitSet<4> on 32-bit platforms and CTFixedBitSet<2> on 64-bit if Block is usize
jrraymond commented 1 year ago

I think this is a useful idea, but if implemented it should belong in a separate crate.

EriKWDev commented 1 year ago

As I will be developing this for my own needs anyways I will post it as a crate once a bit further along. Any name-suggestions? xP

I feel like a fixed bitset should preferably have had the name of this crate instead and not the other way around...

jrraymond commented 1 year ago

I've heard that is one of the 2 hardest problems in computer science ....