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
impl SparseBitVector
Sourcepub fn from_indices(indices: Vec<u16>, capacity: u16) -> Self
pub fn from_indices(indices: Vec<u16>, capacity: u16) -> Self
Sourcepub fn intersection(&self, other: &Self) -> Self
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}Sourcepub fn jaccard_similarity(&self, other: &Self) -> f32
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.5Sourcepub fn hamming_distance(&self, other: &Self) -> u32
pub fn hamming_distance(&self, other: &Self) -> u32
Trait Implementations§
Source§impl Clone for SparseBitVector
impl Clone for SparseBitVector
Source§fn clone(&self) -> SparseBitVector
fn clone(&self) -> SparseBitVector
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseBitVector
impl Debug for SparseBitVector
Source§impl<'de> Deserialize<'de> for SparseBitVector
impl<'de> Deserialize<'de> for SparseBitVector
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl PartialEq for SparseBitVector
Source§impl Serialize for SparseBitVector
impl Serialize for SparseBitVector
impl Eq for SparseBitVector
impl StructuralPartialEq for SparseBitVector
Auto Trait Implementations§
impl Freeze for SparseBitVector
impl RefUnwindSafe for SparseBitVector
impl Send for SparseBitVector
impl Sync for SparseBitVector
impl Unpin for SparseBitVector
impl UnwindSafe for SparseBitVector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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