bbhash_sys/
lib.rs

1pub mod boomphf {
2    use std::os::raw::c_void;
3
4    pub type Mphf = c_void;
5    pub type MphfMutPtr = *mut Mphf;
6
7    #[link(name = "bbhashadapter", kind = "static")]
8    extern "C" {
9        #[link_name = "mphf_new"]
10        pub fn new_mphf(nelem: u64, kmers: *const u64, num_thread: i32, gamma: f64) -> MphfMutPtr;
11
12        #[link_name = "mphf_lookup"]
13        pub fn lookup(this: MphfMutPtr, element: u64) -> u64;
14
15        #[link_name = "mphf_save"]
16        pub fn save(this: MphfMutPtr, path: *const u8, path_size: u64);
17
18        #[link_name = "mphf_load"]
19        pub fn load(path: *const u8, path_size: u64) -> MphfMutPtr;
20    }
21
22}
23
24#[cfg(test)]
25mod tests {
26    use tempfile::NamedTempFile;
27
28    use crate::boomphf::{load, lookup, new_mphf, save};
29
30    #[test]
31    fn it_works() {
32        unsafe {
33            let mphf = new_mphf(10, vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9].as_ptr(), 1, 1.0);
34
35            assert_eq!(lookup(mphf, 9), 8);
36
37            let file = NamedTempFile::new().unwrap();
38            let path = file.path().to_str().unwrap();
39
40            save(mphf, path.as_ptr(), path.len() as u64);
41
42            let loaded_mphf = load(path.as_ptr(), path.len() as u64);
43            assert_eq!(lookup(loaded_mphf, 9), 8);
44        }
45    }
46}