IntVector

Struct IntVector 

Source
pub struct IntVector { /* private fields */ }
Expand description

A contiguous growable and mutable bit-packed array of fixed-width integers.

This structure contains RawVector, which is in turn contains Vec. Each item consists of the lowest 1 to 64 bits of a u64 value, as specified by parameter width. The maximum length of the vector is usize::MAX / width items.

A default constructed IntVector has width == 64. IntVector can be built from an iterator over u8, u16, u32, u64, or usize values.

IntVector implements the following simple_sds traits:

§Notes

  • IntVector never panics from I/O errors.

Implementations§

Source§

impl IntVector

Source

pub fn new(width: usize) -> Result<IntVector, &'static str>

Creates an empty vector with specified width.

Returns Err if the width is invalid.

§Examples
use simple_sds_sbwt::int_vector::IntVector;
use simple_sds_sbwt::ops::Vector;

let v = IntVector::new(13).unwrap();
assert!(v.is_empty());
assert_eq!(v.width(), 13);
Source

pub fn with_len( len: usize, width: usize, value: u64, ) -> Result<IntVector, &'static str>

Creates an initialized vector of specified length and width.

Returns Err if the width is invalid.

§Arguments
  • len: Number of items in the vector.
  • width: Width of each item in bits.
  • value: Initialization value.
§Examples
use simple_sds_sbwt::int_vector::IntVector;
use simple_sds_sbwt::ops::{Vector, Access};

let v = IntVector::with_len(4, 13, 1234).unwrap();
assert_eq!(v.len(), 4);
assert_eq!(v.width(), 13);
for i in 0..v.len() {
    assert_eq!(v.get(i), 1234);
}
§Panics

May panic if the vector would exceed the maximum length.

Source

pub fn with_capacity( capacity: usize, width: usize, ) -> Result<IntVector, &'static str>

Creates an empty vector with enough capacity for at least the specified number of items of specified width.

Returns Err if the width is invalid.

§Arguments
  • capacity: Minimum capacity of the vector in items.
  • width: Width of each item in bits.
§Examples
use simple_sds_sbwt::int_vector::IntVector;
use simple_sds_sbwt::ops::{Vector, Resize};

let v = IntVector::with_capacity(4, 13).unwrap();
assert!(v.is_empty());
assert_eq!(v.width(), 13);
assert!(v.capacity() >= 4);
§Panics

May panic if the capacity would exceed the maximum length.

Source

pub fn size_by_params(capacity: usize, width: usize) -> usize

Returns the size of a serialized vector with the given parameters in u64 elements.

§Arguments
  • capacity: Minimum capacity of the vector in items.
  • width: Width of each item in bits.
§Examples
use simple_sds_sbwt::int_vector::IntVector;

assert_eq!(IntVector::size_by_params(12, 31), 10);
§Panics

May panic if the vector would exceed the maximum length.

Trait Implementations§

Source§

impl<'a> Access<'a> for IntVector

Source§

type Iter = AccessIter<'a, IntVector>

Iterator over the items in the vector.
Source§

fn get(&self, index: usize) -> <Self as Vector>::Item

Returns an item from the vector. Read more
Source§

fn iter(&'a self) -> Self::Iter

Returns an iterator over the items in the vector. Read more
Source§

fn is_mutable(&self) -> bool

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

fn set(&mut self, index: usize, value: <Self as Vector>::Item)

Sets an item in the vector. Read more
Source§

fn get_or( &self, index: usize, value: <Self as Vector>::Item, ) -> <Self as Vector>::Item

Returns an item from the vector or the provided value if index is invalid. Read more
Source§

impl AsRef<RawVector> for IntVector

Source§

fn as_ref(&self) -> &RawVector

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

impl Clone for IntVector

Source§

fn clone(&self) -> IntVector

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IntVector

Source§

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

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

impl Default for IntVector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Extend<u16> for IntVector

Source§

fn extend<I: IntoIterator<Item = u16>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u32> for IntVector

Source§

fn extend<I: IntoIterator<Item = u32>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u64> for IntVector

Source§

fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u8> for IntVector

Source§

fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<usize> for IntVector

Source§

fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<IntVector> for RawVector

Source§

fn from(source: IntVector) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u16>> for IntVector

Source§

fn from(v: Vec<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u32>> for IntVector

Source§

fn from(v: Vec<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u64>> for IntVector

Source§

fn from(v: Vec<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for IntVector

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<usize>> for IntVector

Source§

fn from(v: Vec<usize>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<u16> for IntVector

Source§

fn from_iter<I: IntoIterator<Item = u16>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<u32> for IntVector

Source§

fn from_iter<I: IntoIterator<Item = u32>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<u64> for IntVector

Source§

fn from_iter<I: IntoIterator<Item = u64>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<u8> for IntVector

Source§

fn from_iter<I: IntoIterator<Item = u8>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<usize> for IntVector

Source§

fn from_iter<I: IntoIterator<Item = usize>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl IntoIterator for IntVector

Source§

type Item = <IntVector as Vector>::Item

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Pack for IntVector

Source§

fn pack(&mut self)

Try to store the items of the vector more space-efficiently.
Source§

impl PartialEq for IntVector

Source§

fn eq(&self, other: &IntVector) -> 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 Pop for IntVector

Source§

fn pop(&mut self) -> Option<<Self as Vector>::Item>

Removes and returns the last item from the vector. Read more
Source§

impl Push for IntVector

Source§

fn push(&mut self, value: <Self as Vector>::Item)

Appends an item to the vector. Read more
Source§

impl Resize for IntVector

Source§

fn resize(&mut self, new_len: usize, value: <Self as Vector>::Item)

Resizes the vector to a specified length. Read more
Source§

fn clear(&mut self)

Clears the vector without freeing the data.
Source§

fn capacity(&self) -> usize

Returns the number of items that the vector can store without reallocations.
Source§

fn reserve(&mut self, additional: usize)

Reserves space for storing at least self.len() + additional items in the vector. Read more
Source§

impl Serialize for IntVector

Source§

fn serialize_header<T: Write>(&self, writer: &mut T) -> Result<()>

Serializes the header to the writer. Read more
Source§

fn serialize_body<T: Write>(&self, writer: &mut T) -> Result<()>

Serializes the body to the writer. Read more
Source§

fn load<T: Read>(reader: &mut T) -> Result<Self>

Loads the struct from the reader. Read more
Source§

fn size_in_elements(&self) -> usize

Returns the size of the serialized struct in u64 elements. Read more
Source§

fn serialize<T: Write>(&self, writer: &mut T) -> Result<()>

Serializes the struct to the writer. Read more
Source§

fn size_in_bytes(&self) -> usize

Returns the size of the serialized struct in bytes. Read more
Source§

impl Vector for IntVector

Source§

type Item = u64

The type of the items in the vector.
Source§

fn len(&self) -> usize

Returns the number of items in the vector.
Source§

fn width(&self) -> usize

Returns the width of of an item in bits.
Source§

fn max_len(&self) -> usize

Returns the maximum length of the vector.
Source§

fn is_empty(&self) -> bool

Returns true if the vector is empty.
Source§

impl Eq for IntVector

Source§

impl StructuralPartialEq for IntVector

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.