RawVectorMapper

Struct RawVectorMapper 

Source
pub struct RawVectorMapper<'a> { /* private fields */ }
Expand description

An immutable memory-mapped RawVector.

This is compatible with the serialization format of RawVector.

§Examples

use simple_sds_sbwt::raw_vector::{RawVector, RawVectorMapper, AccessRaw, PushRaw};
use simple_sds_sbwt::serialize::{MemoryMap, MemoryMapped, MappingMode};
use simple_sds_sbwt::serialize;
use std::fs;

let filename = serialize::temp_file_name("raw-vector-mapper");
let width = 29;
let mut original = RawVector::new();
unsafe {
    original.push_int(123, width);
    original.push_int(456, width);
    original.push_int(789, width);
}
serialize::serialize_to(&original, &filename);

let map = MemoryMap::new(&filename, MappingMode::ReadOnly).unwrap();
let mapper = RawVectorMapper::new(&map, 0).unwrap();
assert_eq!(mapper.len(), 3 * width);
unsafe {
    assert_eq!(mapper.int(0, width), 123);
    assert_eq!(mapper.int(width, width), 456);
    assert_eq!(mapper.int(2 * width, width), 789);
}

drop(mapper); drop(map);
fs::remove_file(&filename);

Implementations§

Source§

impl<'a> RawVectorMapper<'a>

Source

pub fn len(&self) -> usize

Returns the length of the vector in bits.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector is empty.

Source

pub fn count_ones(&self) -> usize

Counts the number of ones in the bit array.

Trait Implementations§

Source§

impl<'a> AccessRaw for RawVectorMapper<'a>

Available on non-target_family=wasm only.
Source§

fn bit(&self, bit_offset: usize) -> bool

Reads a bit from the array. Read more
Source§

unsafe fn int(&self, bit_offset: usize, width: usize) -> u64

Reads an integer from the container. Read more
Source§

fn word(&self, index: usize) -> u64

Reads a 64-bit word from the container. Read more
Source§

unsafe fn word_unchecked(&self, index: usize) -> u64

Unsafe version of AccessRaw::word without bounds checks. Read more
Source§

fn is_mutable(&self) -> bool

Returns true if the underlying data is mutable. Read more
Source§

fn set_bit(&mut self, _: usize, _: bool)

Writes a bit to the container. Read more
Source§

unsafe fn set_int(&mut self, _: usize, _: u64, _: usize)

Writes an integer to the container. Read more
Source§

impl<'a> AsRef<MappedSlice<'a, u64>> for RawVectorMapper<'a>

Available on non-target_family=wasm only.
Source§

fn as_ref(&self) -> &MappedSlice<'a, u64>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> AsRef<RawVectorMapper<'a>> for IntVectorMapper<'a>

Available on non-target_family=wasm only.
Source§

fn as_ref(&self) -> &RawVectorMapper<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Debug for RawVectorMapper<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> MemoryMapped<'a> for RawVectorMapper<'a>

Available on non-target_family=wasm only.
Source§

fn new(map: &'a MemoryMap, offset: usize) -> Result<Self>

Returns an immutable memory-mapped structure corresponding to an interval in the file. Read more
Source§

fn map_offset(&self) -> usize

Returns the starting offset in the file.
Source§

fn map_len(&self) -> usize

Returns the length of the interval corresponding to the structure.
Source§

impl<'a> PartialEq for RawVectorMapper<'a>

Source§

fn eq(&self, other: &RawVectorMapper<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for RawVectorMapper<'a>

Source§

impl<'a> StructuralPartialEq for RawVectorMapper<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RawVectorMapper<'a>

§

impl<'a> RefUnwindSafe for RawVectorMapper<'a>

§

impl<'a> Send for RawVectorMapper<'a>

§

impl<'a> Sync for RawVectorMapper<'a>

§

impl<'a> Unpin for RawVectorMapper<'a>

§

impl<'a> UnwindSafe for RawVectorMapper<'a>

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.