bitrush_index/bitmap_index/
bitmap.rs

1// This code is released under the
2// General Public License (GPL), version 3
3// http://www.gnu.org/licenses/gpl-3.0.en.html
4// (c) Lorenzo Vannucci
5
6//! # Bitmap
7//!
8//! A Trait that define the bitmap methods. If you want use you custom compressed-bitmap
9//! in [`bitrush_index`] you must implement this trait for your bitmap.
10//!
11//! [`bitrush_index`]: ../lib.rs
12
13use std::ops::BitAnd;
14use std::fmt::Debug;
15
16pub trait Bitmap
17where Self: Clone + Debug, for <'a> &'a Self: BitAnd<&'a Self,Output=Self> {
18
19    /// Return a new bitmap.
20    fn new() -> Self;
21
22    /// Set the ith bit (starting from zero).
23    fn set(&mut self, i: u32);
24
25    /// Return a Vec with all bit set positions. 
26    fn unroll_bitmap(&self) -> Vec<u32>;
27
28    /// Return the effective size to serialize the bitmap.
29    fn size(&self) -> usize;
30
31    /// Write bitamp content into buffer_out and return the numbers of bytes written.
32    /// Return a generic error if buffer_out size is less then bitmap size. 
33    fn write_to_buffer(&self, buffer_out: &mut [u8]) -> Result<usize, ()>;
34
35    /// Read bitmap content from buffer_in, buffer_in must have the effettive
36    /// bitmap content (the size returned from write_to_buffer method).
37    /// If `check_bitmap == false` bitmap content is readed without
38    /// any check on bitmap content integrity. Return a generic error an error occur.
39    fn read_from_buffer(&mut self, buffer_in: &[u8], check_bitmap: bool) -> Result<(), ()>;
40}
41