mirror of
https://github.com/instant-labs/instant-distance.git
synced 2025-02-13 03:12:10 +00:00
Add optional serde support
This commit is contained in:
parent
6a040672d1
commit
02cfa606c7
@ -9,3 +9,4 @@ ahash = "0.6.1"
|
|||||||
ordered-float = "2.0"
|
ordered-float = "2.0"
|
||||||
rand = { version = "0.7.3", features = ["small_rng"] }
|
rand = { version = "0.7.3", features = ["small_rng"] }
|
||||||
rayon = "1.5"
|
rayon = "1.5"
|
||||||
|
serde = { version = "1.0.118", features = ["derive"], optional = true }
|
||||||
|
@ -6,7 +6,10 @@ use ahash::AHashSet as HashSet;
|
|||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use rand::rngs::SmallRng;
|
use rand::rngs::SmallRng;
|
||||||
use rand::{RngCore, SeedableRng};
|
use rand::{RngCore, SeedableRng};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct Hnsw<P> {
|
pub struct Hnsw<P> {
|
||||||
ef_search: usize,
|
ef_search: usize,
|
||||||
points: Vec<P>,
|
points: Vec<P>,
|
||||||
@ -400,6 +403,7 @@ trait Layer {
|
|||||||
fn nodes(&self) -> &[Self::Node];
|
fn nodes(&self) -> &[Self::Node];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
struct UpperNode {
|
struct UpperNode {
|
||||||
/// The nearest neighbors on this layer
|
/// The nearest neighbors on this layer
|
||||||
@ -424,6 +428,7 @@ impl Node for UpperNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
struct ZeroNode {
|
struct ZeroNode {
|
||||||
/// The nearest neighbors on this layer
|
/// The nearest neighbors on this layer
|
||||||
@ -523,6 +528,7 @@ struct Candidate {
|
|||||||
/// References a `Point` in the `Hnsw`
|
/// References a `Point` in the `Hnsw`
|
||||||
///
|
///
|
||||||
/// This can be used to index into the `Hnsw` to refer to the `Point` data.
|
/// This can be used to index into the `Hnsw` to refer to the `Point` data.
|
||||||
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct PointId(usize);
|
pub struct PointId(usize);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user