From 7690d09fb82ee856dd711e2be666f667b9d45df0 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 21 Jan 2021 14:40:48 +0100 Subject: [PATCH] Bump M up to 32 --- Cargo.toml | 4 ++++ src/lib.rs | 2 +- src/types.rs | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 200b7a9..d1ee291 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ license = "MIT OR Apache-2.0" authors = ["Dirkjan Ochtman "] edition = "2018" +[features] +with-serde = ["serde", "serde-big-array"] + [dependencies] indicatif = { version = "0.15", optional = true } num_cpus = "1.13" @@ -13,6 +16,7 @@ parking_lot = "0.11" rand = { version = "0.8", features = ["small_rng"] } rayon = "1.5" serde = { version = "1.0.118", features = ["derive"], optional = true } +serde-big-array = { version = "0.3.1", optional = true } [dev-dependencies] bencher = "0.1.5" diff --git a/src/lib.rs b/src/lib.rs index af7ed2d..a59c068 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -675,4 +675,4 @@ pub trait Point: Clone + Sync { /// The parameter `M` from the paper /// /// This should become a generic argument to `Hnsw` when possible. -const M: usize = 12; +const M: usize = 32; diff --git a/src/types.rs b/src/types.rs index 4431342..fa94948 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,6 +7,8 @@ use rand::rngs::SmallRng; use rand::Rng; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "serde-big-array")] +use serde_big_array::big_array; use crate::{Hnsw, Point, M}; @@ -80,7 +82,12 @@ impl<'a> Layer for &'a [UpperNode] { #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Clone, Copy, Debug)] -pub(crate) struct ZeroNode(pub(crate) [PointId; M * 2]); +pub(crate) struct ZeroNode( + #[cfg_attr(feature = "serde", serde(with = "BigArray"))] pub(crate) [PointId; M * 2], +); + +#[cfg(feature = "serde-big-array")] +big_array! { BigArray; } impl ZeroNode { pub(crate) fn rewrite(&mut self, mut iter: impl Iterator) {