| Crates.io | indexed-bitmap |
| lib.rs | indexed-bitmap |
| version | 1.0.0 |
| created_at | 2025-10-25 19:52:31.028985+00 |
| updated_at | 2025-10-25 19:52:31.028985+00 |
| description | A (perhaps) obvious indexed bitmap in Rust. |
| homepage | https://github.com/aegistudio/indexed-bitmap |
| repository | |
| max_upload_size | |
| id | 1900555 |
| size | 27,090 |
A (perhaps) obvious indexed bitmap in Rust.
This bitmap is indexed for accelerating the operations related to pinpointing zeroes and ones.
The indexed bitmap works in the following way:
bitmap layer, which stores the zeroes and ones and fulfils the responsibility of an ordinary bitmap. Physically, the bitmap is implemented by a Vec<u128>, where every cell of u128 is called a page.indexes. Again, every index is also implemented by Vec<u128>, where every cell of u128 is also called a page. The responsibility of every index is to summarize the status of pages from the bitmap or the previous index layer.0b11, a page of mixture of zeroes and ones will be summarized into 0b01, and a page of all zeroes will be summarized into 0b00.0b01 field corresponding to that page, and thus a mixture of zeroes and ones. In this way, we are able to use the index layers as a "telescope".To see how such an indexing will help, consider the case of finding the first zero:
The core APIs of the indexed-bitmap are:
usize to zero initially. That is, for any bit untouched by any operation, it is initially zero.bitget, bitset: Ordinary bitmap operations.lowest_zero, lowest_one: Locate the first zero or one bit.highest_one, size: The highest_one locates the last one bit. The size locates the first zero bit after the last one bit. (The highest_zero does not make sense, due to our way of conceptually defining the indexed bitmap, it will be usize::MAX if usize::MAX-th bit is not set or not exist if usize::MAX-th bit is set. If you want one, you gotta see if size fulfils your need.)this_one_or_next_one, next_one: Locate the next one bit after the specified bit.shrink_to, shrink_to_fit: Shrink the underlying containers of the bitmap.count_ones / count_zeroes: Although we can skip many pages utilizing the index, the worst case degrades to linearly scanning the bitmap, that is, $O(N)$. However, this can be implemented in $O(1)$ by simply maintaining a counter. Maintaining such a counter will add to the size and book-keeping works, and those who don't need this functionality will really grudge.highest_zero: Do you mean size?This project is licensed under the MIT license.