SparseBitVector

Struct SparseBitVector 

Source
pub struct SparseBitVector {
    pub indices: Vec<u16>,
    /* private fields */
}
Expand description

Sparse bit vector storing only active indices

Efficient representation for sparse binary vectors where only a small fraction of bits are set (active). Stores only the indices of active bits rather than the full bit array.

§Properties

  • Memory: O(k) where k is number of active bits
  • Set operations: O(k1 + k2) for intersection/union
  • Typical k: 200-500 active bits out of 10000+ total

§Example

use ruvector_nervous_system::SparseBitVector;

let mut sparse = SparseBitVector::new(10000);
sparse.set(42);
sparse.set(100);
sparse.set(500);

Fields§

§indices: Vec<u16>

Sorted list of active bit indices

Implementations§

Source§

impl SparseBitVector

Source

pub fn new(capacity: u16) -> Self

Create a new sparse bit vector with given capacity

§Arguments
  • capacity - Maximum number of bits (max index + 1)
§Example
use ruvector_nervous_system::SparseBitVector;

let sparse = SparseBitVector::new(10000);
Source

pub fn from_indices(indices: Vec<u16>, capacity: u16) -> Self

Create from a list of active indices

§Arguments
  • indices - Vector of active bit indices
  • capacity - Total capacity
§Example
use ruvector_nervous_system::SparseBitVector;

let sparse = SparseBitVector::from_indices(vec![10, 20, 30], 10000);
Source

pub fn set(&mut self, index: u16)

Set a bit to active

§Arguments
  • index - Bit index to set
§Panics

Panics if index >= capacity

Source

pub fn is_set(&self, index: u16) -> bool

Check if a bit is active

§Arguments
  • index - Bit index to check
§Returns

true if bit is set, false otherwise

Source

pub fn count(&self) -> usize

Get number of active bits

Source

pub fn capacity(&self) -> u16

Get capacity

Source

pub fn intersection(&self, other: &Self) -> Self

Compute intersection with another sparse bit vector

§Arguments
  • other - Other sparse bit vector
§Returns

New sparse bit vector containing intersection

§Example
use ruvector_nervous_system::SparseBitVector;

let a = SparseBitVector::from_indices(vec![1, 2, 3], 100);
let b = SparseBitVector::from_indices(vec![2, 3, 4], 100);
let intersection = a.intersection(&b);
assert_eq!(intersection.count(), 2); // {2, 3}
Source

pub fn union(&self, other: &Self) -> Self

Compute union with another sparse bit vector

§Arguments
  • other - Other sparse bit vector
§Returns

New sparse bit vector containing union

Source

pub fn jaccard_similarity(&self, other: &Self) -> f32

Compute Jaccard similarity with another sparse bit vector

Jaccard similarity = |A ∩ B| / |A ∪ B|

§Arguments
  • other - Other sparse bit vector
§Returns

Similarity in range [0.0, 1.0]

§Example
use ruvector_nervous_system::SparseBitVector;

let a = SparseBitVector::from_indices(vec![1, 2, 3], 100);
let b = SparseBitVector::from_indices(vec![2, 3, 4], 100);
let sim = a.jaccard_similarity(&b);
assert!((sim - 0.5).abs() < 0.001); // 2/4 = 0.5
Source

pub fn hamming_distance(&self, other: &Self) -> u32

Compute Hamming distance with another sparse bit vector

Hamming distance = number of positions where bits differ

§Arguments
  • other - Other sparse bit vector
§Returns

Hamming distance (number of differing bits)

Trait Implementations§

Source§

impl Clone for SparseBitVector

Source§

fn clone(&self) -> SparseBitVector

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 SparseBitVector

Source§

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

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

impl<'de> Deserialize<'de> for SparseBitVector

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for SparseBitVector

Source§

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

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for SparseBitVector

Source§

impl StructuralPartialEq for SparseBitVector

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,