ranged_bitmap 1.0.0

A high-performance bitmap library
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented14 out of 14 items with examples
  • Size
  • Source code size: 57.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Eugene-Usachev/ranged_bitmap
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Eugene-Usachev

Ranged Bitmap

A high-performance bitmap library.

Features

  • All functions are constant
  • Optimized range operations that work on multiple bits simultaneously
  • No_std compatibility for embedded and bare-metal environments

Performance

This library is designed with performance as a primary goal:

  • Range operations use precomputed lookup tables for optimal bit manipulation
  • Bulk operations on full blocks use memset-like operations for maximum speed
  • All functions are marked #[inline(always)] for aggressive inlining
  • Constant functions enable compile-time optimizations
  • Hardware-accelerated bit counting operations

Basic Usage

use ranged_bitmap::generate_fixed_bit_map_struct;

generate_fixed_bit_map_struct!(struct BitMap<256>); // Generates a 256-bit bitmap struct wrapper

// Create a 256-bit bitmap
let mut bitmap = BitMap::new();

// Set individual bits
bitmap.set(10);
bitmap.set(20);

// Gets individual bits
assert!(bitmap.get(10));
assert!(!bitmap.get(21));

// Set an entire range at once (much faster than individual operations)
bitmap.set_range(50, 100); // Set bits 50-149
bitmap.clear_range(0, 50); // Clear bits 0-49

// Check if a range is completely set or unset
assert!(bitmap.check_range_is_set(50, 100));
assert!(bitmap.check_range_is_unset(0, 50));

// Iterate over a range
for (index, value) in bitmap.iter_range(40, 20) {
    println!("Bit {}: {}", index, value);
}

// Count set bits
println!("Total set bits: {}", bitmap.count_ones());
println!("Total unset bits: {}", bitmap.count_zeros());

Range Operations

The library excels at a range of operations:

use ranged_bitmap::FixedBitMap;

let mut bitmap = FixedBitMap::<2>::new(); // 128 bits

// Efficiently set large ranges
bitmap.set_range(0, 64);   // Set first block
bitmap.set_range(64, 64);  // Set second block

// Check range status
assert!(bitmap.check_range_is_set(0, 128));

// Clear ranges efficiently
bitmap.clear_range(32, 64); // Clear middle portion

Performance Characteristics

Operation Complexity Notes
Individual bit get/set/clear O(1) Single memory access
Range operations (single block) O(1) Bitmask operations
Range operations (multi-block) O(n) n = number of affected blocks
Full block operations O(n) memset-like optimizations
Bit counting O(n) Hardware-accelerated

License

This project is licensed under the MIT License.