pub struct MmapBitVec {
pub mmap: MmapKind,
pub size: usize,
/* private fields */
}
Expand description
Bit vector backed by a mmap-ed file
§Examples
use mmap_bitvec::{BitVector, MmapBitVec};
let mut bv = MmapBitVec::from_memory(128).unwrap();
bv.set_range_bytes(2..12, &[0b10, 0b01101101]);
assert_eq!(bv.get_range(2..12), 0b1001101101);
Fields§
§mmap: MmapKind
The mmap we are using, either a mutable or read-only one
size: usize
Number of bits in the bitvector
Implementations§
Source§impl MmapBitVec
impl MmapBitVec
Sourcepub fn create<P: AsRef<Path>>(
filename: P,
size: usize,
magic: Option<[u8; 2]>,
header: &[u8],
) -> Result<Self, Error>
pub fn create<P: AsRef<Path>>( filename: P, size: usize, magic: Option<[u8; 2]>, header: &[u8], ) -> Result<Self, Error>
Creates a new MmapBitVec
file
The overall size of bit vector (in bits) and a fixed-size header must also be provided (although the header can be 0-length).
Sourcepub fn open<P>(
filename: P,
magic: Option<&[u8; 2]>,
read_only: bool,
) -> Result<Self, Error>
pub fn open<P>( filename: P, magic: Option<&[u8; 2]>, read_only: bool, ) -> Result<Self, Error>
Opens an existing MmapBitVec
file
If magic bytes are passed to indicate file type, they are checked against the file.
The header size must be specified (as it isn’t stored in the file to
allow the magic bytes to be set) and there is an optional read_only
property that will lock the underlying mmap from writing.
Sourcepub fn open_no_header<P>(filename: P, offset: usize) -> Result<Self, Error>
pub fn open_no_header<P>(filename: P, offset: usize) -> Result<Self, Error>
Opens a MmapBitVec
file that doesn’t have our “standard” file header format
TODO: what is the standard file header? if we put in the docstring on the struct we can say to refer to that here
Sourcepub fn from_memory(size: usize) -> Result<Self, Error>
pub fn from_memory(size: usize) -> Result<Self, Error>
Creates an in-memory MmapBitVec
(not backed by a file).
Note that unlike the create
and open
no header is set.
The MmapBitVec is also read/write by default.
Sourcepub fn save_to_disk<P: AsRef<Path>>(
&self,
filename: P,
magic: Option<[u8; 2]>,
header: &[u8],
) -> Result<(), Error>
pub fn save_to_disk<P: AsRef<Path>>( &self, filename: P, magic: Option<[u8; 2]>, header: &[u8], ) -> Result<(), Error>
Save in-memory mmap bitvector to disk. This is a no-op if the mmap is already file-backed.
Sourcepub fn get_range_bytes(&self, r: Range<usize>) -> Vec<u8> ⓘ
pub fn get_range_bytes(&self, r: Range<usize>) -> Vec<u8> ⓘ
Read/copy an unaligned chunk of the MmapBitVec
§Panics
Explicitly panics if the end location, r.end
, is outside the bounds
of the bit vector. A panic may also occur if r.start
is greater than
r.end
.
Sourcepub fn set_range_bytes(&mut self, r: Range<usize>, x: &[u8])
pub fn set_range_bytes(&mut self, r: Range<usize>, x: &[u8])
Set an unaligned range of bits in the bit vector from a byte slice.
Note this operation ORs the passed byteslice and the existing bitmask.
§Panics
Explicitly panics if the end location, r.end
, is outside the bounds
of the bit vector or if the byte slice passed in is a different size
from the range specified. A panic may also occur if r.start
is greater
than r.end
.
Trait Implementations§
Source§impl BitVector for MmapBitVec
impl BitVector for MmapBitVec
Source§fn get(&self, i: usize) -> bool
fn get(&self, i: usize) -> bool
Check a single value in the MmapBitVec
, returning its true/false status
§Panics
Panics if the location, i
, is outside the bounds of the bit vector
Source§fn set(&mut self, i: usize, x: bool)
fn set(&mut self, i: usize, x: bool)
Set a single bit in the bit vector
§Panics
Panics if the location, i
, is outside the bounds of the bit vector
Source§fn select(&self, n: usize, start: usize) -> Option<usize>
fn select(&self, n: usize, start: usize) -> Option<usize>
Return the position of the nth
set bit with start
treated as the 0th position, or None
if there is no set bit
Source§fn get_range(&self, r: Range<usize>) -> u128
fn get_range(&self, r: Range<usize>) -> u128
Read an unaligned chunk of the MmapBitVec
into a u128
§Panics
Explicitly panics if the end location, r.end
, is outside the bounds
of the bit vector or if the range specified is greater than 128 bits.
(Use get_range_bytes
instead if you need to read larger chunks) A panic
will also occur when r.start
is greater than r.end
.
Source§fn set_range(&mut self, r: Range<usize>, x: u128)
fn set_range(&mut self, r: Range<usize>, x: u128)
Set an unaligned range of bits using a u64
.
Note this operation ORs the passed u64 and the existing bitmask
§Panics
Explicitly panics if the end location, r.end
, is outside the bounds
of the bit vector. A panic will also occur when r.start
is greater than
r.end
.