Skip to content

Commit

Permalink
Can initialize, yay
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Nov 3, 2019
1 parent 9e918f2 commit e05a9b3
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ ThirdParty/stxxl

.idea/*
build/*

Cargo.lock
target
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "mqf"
version = "0.1.0"
authors = ["Luiz Irber <[email protected]>"]
links = "libmqf"

[build-dependencies]
bindgen = "0.51"
cmake = "0.1.42"

[dependencies]
51 changes: 51 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::env;
use std::path::PathBuf;

extern crate cmake;
use cmake::Config;

fn main() {
let dst = Config::new(".")
.define("BUILD_STATIC_LIBS", "ON")
.define("CMAKE_BUILD_TYPE", "Release")
.build();

This comment has been minimized.

Copy link
@mr-eyes

mr-eyes Nov 4, 2019

Member

@luizirber I think you will just need to add:

.define("SUPRESS_BIN", "ON")
.define("SUPRESS_TESTS", "ON")

I hope it works.


let target = env::var("TARGET").unwrap();
if target.contains("apple") {
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else {
unimplemented!();
}

println!("cargo:rustc-link-search=native={}/build/src", dst.display());
println!(
"cargo:rustc-link-search=native={}/build/ThirdParty/stxxl/lib",
dst.display()
);

println!("cargo:rustc-link-lib=static=MQF");
println!("cargo:rustc-link-lib=static=stxxl");

let bindings = bindgen::Builder::default()
.clang_arg("-I./include")
//.clang_arg("-I./ThirdParty/stxxl/include/stxxl")
//.clang_arg("-I./ThirdParty/stxxl/include")
.clang_arg("-x")
.clang_arg("c++")
.clang_arg("-std=c++11")
.header("include/gqf.h")
.whitelist_type("QF")
.whitelist_function("qf_*")
.whitelist_function("qf_init")
.blacklist_type("std::*")
//.opaque_type("QF")
.generate()
.expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("couldn't write bindings!");
}
77 changes: 77 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(test)]
mod tests {
use super::*;
use std::ffi::CString;
use std::ptr;

#[test]
fn simple_counting_test() {
//except first item is inserted 5 times to full test _insert1
let mut qf: QF = QF {
mem: ptr::null_mut(),
metadata: ptr::null_mut(),
blocks: ptr::null_mut(),
};

let counter_size = 2;
let qbits = 5;
let num_hash_bits = qbits + 8;
let maximum_count = (1u64 << counter_size) - 1;
let mut count = 0;
let mut fixed_counter = 0;

let s = CString::new("").unwrap();

//INFO("Counter size = "<<counter_size<<" max count= "<<maximum_count);
unsafe {
qf_init(
&mut qf,
1u64 << qbits,
num_hash_bits,
0,
counter_size,
0,
true,
s.as_ptr(),
2038074761,
);
}

/*
for i in 0..=10 {
qf_insert(&qf, 100, 1, false, false);
count = qf_count_key(&qf, 100);
//fixed_counter=qf_get_fixed_counter(&qf,100);
dbg!((count, fixed_counter));
assert_eq!(count, 1 + i);
}
qf_insert(&qf,1500,50,false,false);
count = qf_count_key(&qf, 1500);
// fixed_counter=qf_get_fixed_counter(&qf,1500);
INFO("Counter = "<<count<<" fixed counter = "<<fixed_counter)
CHECK(count == (50));
qf_insert(&qf,1600,60,false,false);
count = qf_count_key(&qf, 1600);
// fixed_counter=qf_get_fixed_counter(&qf,1600);
INFO("Counter = "<<count<<" fixed counter = "<<fixed_counter)
CHECK(count == (60));
qf_insert(&qf,2000,4000,false,false);
count = qf_count_key(&qf, 2000);
// fixed_counter=qf_get_fixed_counter(&qf,2000);
INFO("Counter = "<<count<<" fixed counter = "<<fixed_counter)
CHECK(count == (4000));
*/
}
}

0 comments on commit e05a9b3

Please sign in to comment.