Skip to main content

Graph

Struct Graph 

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

Per-layer graph used while constructing an index.

Inspect a live index through crate::HnswIndex::graph or the index’s read-only accessors. The graph stored on an index cannot be replaced, and mutation methods here are crate-private so external callers cannot desync adjacency from vectors.

Adjacency lists are directed. Insertion adds both directed edges atomically (a reverse-edge failure undoes the forward write), then reverse links are pruned on the neighbor only, so a dropped A → B edge can leave B → A in place.

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

Empty construction graph: no nodes and no layers.

Source

pub fn edges(&self, level: u8, node_index: NodeIndex) -> &[NodeIndex] ⓘ

Outgoing neighbors of node_index at level.

Empty when the node is missing or node.level < level. The slice is sorted and unique. Adjacency is directed: reverse-link prune drops an outgoing edge on one node and leaves the peer’s reverse edge in place, so edges(level, a) containing b does not imply the reverse.

Source

pub fn node_count(&self) -> NodeIndex

Number of nodes in the construction graph.

After a successful insert the value is exact and at most u32::MAX (indices 0..=u32::MAX - 1). If the u32 cap is bypassed, this saturates at u32::MAX instead of panicking.

Source

pub fn layer_count(&self) -> u8

Number of allocated layers (highest assigned node level plus one).

0 on an empty graph.

Source

pub fn node(&self, node_index: NodeIndex) -> Option<NodeMeta>

Metadata for a dense internal node, if node_index exists.

Source

pub fn has_edge( &self, level: u8, source: NodeIndex, destination: NodeIndex, ) -> bool

Whether a directed edge exists from source to destination at level.

This is a membership test on Graph::edges. A dropped reverse link can make the relation one-sided.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

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

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

impl Default for Graph

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.