pub struct HNSWNode {
pub id: u32,
pub level: u8,
pub neighbor_counts: [u8; 8],
/* private fields */
}Expand description
HNSW node with cache-optimized layout
Hot data (first 64 bytes = 1 cache line):
- Node ID (4 bytes)
- Level (1 byte)
- Neighbor counts per level (8 bytes for 8 levels max)
- Padding to 64 bytes
Cold data stored separately:
- Neighbors (only fetched when traversing)
- Vector data (only fetched when computing distances)
Fields§
§id: u32Node ID (u32 = 4 bytes, supports 4 billion vectors)
level: u8Current level (0 to max_level)
neighbor_counts: [u8; 8]Neighbor counts per level (u8 = 1 byte per level, max 8 levels)
neighbor_counts[i] = number of neighbors at level i
Implementations§
Source§impl HNSWNode
impl HNSWNode
Sourcepub fn neighbor_count(&self, level: u8) -> usize
pub fn neighbor_count(&self, level: u8) -> usize
Get number of neighbors at a given level
Sourcepub fn set_neighbor_count(&mut self, level: u8, count: usize)
pub fn set_neighbor_count(&mut self, level: u8, count: usize)
Set number of neighbors at a given level
Note: Allows setting neighbor counts at ANY level, not just levels <= node.level. This is necessary because bidirectional edges can create connections at layers higher than the node’s originally assigned level.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HNSWNode
impl<'de> Deserialize<'de> for HNSWNode
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
Auto Trait Implementations§
impl Freeze for HNSWNode
impl RefUnwindSafe for HNSWNode
impl Send for HNSWNode
impl Sync for HNSWNode
impl Unpin for HNSWNode
impl UnwindSafe for HNSWNode
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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