Fix serde support for larger ZeroNodes

This commit is contained in:
Dirkjan Ochtman 2021-01-12 14:33:31 +01:00
parent 04094ce06f
commit 27d5e9b522
2 changed files with 9 additions and 0 deletions

View File

@ -5,6 +5,9 @@ license = "MIT OR Apache-2.0"
authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"] authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"]
edition = "2018" edition = "2018"
[features]
with-serde = ["serde", "serde-big-array"]
[dependencies] [dependencies]
ahash = "0.6.1" ahash = "0.6.1"
indicatif = { version = "0.15", optional = true } indicatif = { version = "0.15", optional = true }
@ -13,3 +16,4 @@ ordered-float = "2.0"
rand = { version = "0.8", features = ["small_rng"] } rand = { version = "0.8", features = ["small_rng"] }
rayon = "1.5" rayon = "1.5"
serde = { version = "1.0.118", features = ["derive"], optional = true } serde = { version = "1.0.118", features = ["derive"], optional = true }
serde-big-array = { version = "0.3.1", optional = true }

View File

@ -12,6 +12,8 @@ use rand::{Rng, SeedableRng};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator}; use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "serde")]
use serde_big_array::big_array;
/// Parameters for building the `Hnsw` /// Parameters for building the `Hnsw`
#[derive(Default)] #[derive(Default)]
@ -622,9 +624,12 @@ struct ZeroNode {
/// The nearest neighbors on this layer /// The nearest neighbors on this layer
/// ///
/// This is always kept in sorted order (near to far). /// This is always kept in sorted order (near to far).
#[serde(with = "BigArray")]
nearest: [PointId; M * 2], nearest: [PointId; M * 2],
} }
big_array! { BigArray; }
impl Default for ZeroNode { impl Default for ZeroNode {
fn default() -> ZeroNode { fn default() -> ZeroNode {
ZeroNode { nearest: [PointId::invalid(); M * 2] } ZeroNode { nearest: [PointId::invalid(); M * 2] }