pub struct Hypervector { /* private fields */ }Expand description
Bit-packed hypervector: each bit represents a bipolar value (0 → -1, 1 → +1).
10,000 dims = 157 u64 words = 1,256 bytes (vs 10,000 bytes as Vec
Implementations§
Source§impl Hypervector
impl Hypervector
pub fn new(dims: usize) -> Self
pub fn get(&self, idx: usize) -> i8
Sourcepub fn set(&mut self, idx: usize, val: i8)
pub fn set(&mut self, idx: usize, val: i8)
Set bipolar value at index: -1 → clear bit, +1 → set bit.
Sourcepub fn dot(&self, other: &Hypervector) -> i64
pub fn dot(&self, other: &Hypervector) -> i64
M1: XOR + popcount dot product — 64× fewer iterations than element-wise. For bipolar {-1,+1}: dot = (matching_bits - differing_bits) = dims - 2*hamming_distance.
Sourcepub fn norm(&self) -> f64
pub fn norm(&self) -> f64
M3: Precomputed norm — for bipolar HVs, norm = sqrt(dims) ≈ constant. No per-call sum-of-squares needed.
Sourcepub fn cosine(&self, other: &Hypervector) -> f64
pub fn cosine(&self, other: &Hypervector) -> f64
Cosine similarity = dot / (norm_a * norm_b). For bipolar HVs: cosine = 1 - 2*hamming/dims.
Sourcepub fn bundle_into(&mut self, other: &Hypervector)
pub fn bundle_into(&mut self, other: &Hypervector)
Bundle: XOR-based majority vote for bipolar HVs. Sum via i32 accumulation, then sign → set/clear bit.
Trait Implementations§
Source§impl Clone for Hypervector
impl Clone for Hypervector
Source§impl Debug for Hypervector
impl Debug for Hypervector
Source§impl PartialEq for Hypervector
impl PartialEq for Hypervector
impl StructuralPartialEq for Hypervector
Auto Trait Implementations§
impl Freeze for Hypervector
impl RefUnwindSafe for Hypervector
impl Send for Hypervector
impl Sync for Hypervector
impl Unpin for Hypervector
impl UnsafeUnpin for Hypervector
impl UnwindSafe for Hypervector
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