Check out the Issue Explorer
Looking to fund some work? You can submit a new Funded Issue here.
There is an implementation of a Boolean Bitfield here:
It (kinda) does the job for now, but it really needs some work done. If you spend some time looking at it I think you'll soon find out what I mean. As an example;
- There is a possibility of overflows: we return the number of bits as a `usize`, however there can theoretically be `usize` number of bytes meaning we can have `8 * usize` bits.
- It keeps track of the number of true bits as you flip bits on and off. I don't think this is ideal as most cases where we want to know the number of true bits, we'll be receiving some serialized bytes from somewhere else (e.g., p2p nodes) and will need to calculate it manually.
On top of these two points, there's likely many chances for optimization.
# Required Functionality
get(n: usize) -> Result
Get value at index `n`.
Error if bit out-of-bounds (OOB) of underlying bytes.
set(n: usize, val: bool) -> Result
Set bit at index `n`. Returns the previous value if successful.
Error if bit is OOB of underlying bytes.
## Highest Set Bit
highest_set_bit() -> Option
Returns the index of the highest set bit. `Some(n)` if a bit set set, `None` otherwise.
_Note: this is useful because we need to reject messages if an unnecessary bit is set (e.g. if there are 10 voters and the 11th bit is set_
## Number of Underlying Bytes
num_bytes() -> usize
Returns the length of the underlying bytes.
_Note: useful to reject bitfields that are larger than required (e.g., if there are eight voters and two bytes -- only one byte is necessary). _
## Number of Set Bits
num_set_bits() -> usize
Returns the total number of set bits (i.e., how many peeps voted).
_Note: I'm not 100% sure we'll use this but I suspect we will._