Struct MmapBitVec

Source
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

Source

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).

Source

pub fn open<P>( filename: P, magic: Option<&[u8; 2]>, read_only: bool, ) -> Result<Self, Error>
where P: AsRef<Path>,

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.

Source

pub fn open_no_header<P>(filename: P, offset: usize) -> Result<Self, Error>
where P: AsRef<Path>,

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

Source

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.

Source

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.

Source

pub fn header(&self) -> &[u8]

Returns the header

Source

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.

Source

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

Source§

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)

Set a single bit in the bit vector

§Panics

Panics if the location, i, is outside the bounds of the bit vector

Source§

fn size(&self) -> usize

Returns the length (in bits) of the bit vector

Source§

fn rank(&self, r: Range<usize>) -> usize

Return the number of set bits in the range r

Source§

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

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)

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.

Source§

fn clear_range(&mut self, r: Range<usize>)

Sets all the bit in the given range to false
Source§

impl Drop for MmapBitVec

Drop is implemented for BitVec to explicitly flush any changes to the file before the memory map is closed.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.