3 个版本 (稳定)
使用旧的Rust 2015
| 1.0.1 | 2018年4月30日 |
|---|---|
| 1.0.0 | 2018年3月2日 |
| 0.1.0 | 2018年2月25日 |
#16 in #set-bit
6KB
65 行
Bitmap4Rust
一个用于创建和操作位图的Rust库。
API
位图保存在适当大小的字节数组中。因此,它的类型应该是 Vec<u8>。
pub fn bitmap_create(bitmap_size: &mut u64) -> Vec<u8>
用于创建位图。由于位图以字节数组的形式维护,它必须是 Vec<u8> 类型。
pub fn clear_bit(bitmap: &mut Vec<u8>, bitno: u64) -> i32
用于清除位于 bitno 的位,即将其设置为0。如果 bitno 大于位图的大小,则返回 -1。
pub fn set_bit(bitmap: &mut Vec<u8>, bitno: u64) -> i32
用于设置位于 bitno 的位,即将其设置为1。如果 bitno 大于位图的大小,则返回 -1。
pub fn get_first_set_bit(bitmap: &mut Vec<u8>) -> i64
用于获取 bitmap 中第一个设置为1的位。如果没有设置为1的位,则返回 -1。
pub fn get_first_unset_bit(bitmap: &mut Vec<u8>) -> i64
用于获取 bitmap 中第一个设置为0的位。如果所有位都设置为1,则返回 -1。
pub fn check_bit(bitmap: &mut Vec<u8>, bitno: u64) -> i32
用于检查对应于 bitno 的位的值。
用法
- 在
Cargo.toml中添加依赖项bitmap4rust
[dependencies]
bitmap4rust = "1.0.1"
- 包含 crate
bitmap4rust
extern crate bitmap4rust;