diff --git a/examples/mnist.rs b/examples/mnist.rs index 01838c3..3ebebe4 100644 --- a/examples/mnist.rs +++ b/examples/mnist.rs @@ -47,8 +47,8 @@ fn main() { .into_iter() .map(|v| v as f32) .collect::>(); - - let v: [f32; 28*28] = img_to_vec.try_into().unwrap(); + + let v: [f32; 28 * 28] = img_to_vec.try_into().unwrap(); ann.add_item(v, None); if i % 1_000 == 0 { @@ -74,7 +74,7 @@ fn main() { .map(|v| v as f32) .collect::>(); - let v: [f32; 28*28] = img_to_vec.try_into().unwrap(); + let v: [f32; 28 * 28] = img_to_vec.try_into().unwrap(); let (result, _distance) = ann.query(v, 1, None); let actual = result .into_iter() @@ -89,4 +89,4 @@ fn main() { println!("{}\n{}", trn, tst); } } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 220fe5e..b8d3e46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ +use libc::{c_float, c_int, c_uint, c_void}; use std::ffi::CString; use std::path::Path; -use libc::{c_float, c_int, c_uint, c_void}; pub enum Index {} @@ -42,8 +42,8 @@ mod ffi { } } -pub struct Voyager { - ix: *mut Index +pub struct Voyager { + ix: *mut Index, } impl Voyager { @@ -54,7 +54,9 @@ impl Voyager { Voyager { ix: index } } - pub const fn dimension() -> usize { N } + pub const fn dimension() -> usize { + N + } pub fn add_item(&self, w: [f32; N], id: Option) { let len = w.len(); @@ -116,6 +118,12 @@ impl Drop for Voyager { } } +impl Default for Voyager { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod test { use super::*;