Skip to content

Commit

Permalink
add Voyager interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
uzushino committed Dec 8, 2023
1 parent b8d2ab6 commit 223ab53
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ mod ffi {
pub fn init_index() -> *mut Index;
pub fn add_item(index: *mut Index, item: *const c_float, len: usize, size: c_uint);
pub fn dispose(index: *mut Index);

#[allow(clippy::all)]
#[allow(dead_code)]
pub fn query(
index: *mut Index,
input: *const c_float,
Expand All @@ -22,6 +25,32 @@ mod ffi {
}
}

pub struct Voyager(usize, *mut Index);

impl Voyager {
pub fn new(n: usize) -> Self {
let index = unsafe { ffi::init_index() };
Voyager(n, index)
}

pub fn add_item(&self, w: &[f32]) {
let len = w.len();
let size = self.0;

unsafe {
ffi::add_item(self.1, w.as_ptr(), len, size as c_uint);
}
}
}

impl Drop for Voyager {
fn drop(&mut self) {
unsafe {
ffi::dispose(self.1);
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 223ab53

Please sign in to comment.