prataprc / xorfilter

Rust library implementing xor-filters
Apache License 2.0
137 stars 18 forks source link

Allow arbitrary value types #3

Closed mre closed 4 years ago

mre commented 4 years ago

Are you planning to add support for arbitrary value types like strings? Would be helpful to have a similar interface to HashSet or cuckoofilter eventually.

Use-case: I'm interested in testing XOR-filters as a search datastructure for tinysearch.

prataprc commented 4 years ago

Arbitrary value types ? Are you proposing something like:

populate<T: Hash>(keys: &Vec<T>) -> Box<Xor8>

Would be helpful to have a similar interface to HashSet or cuckoofilter eventually.

Xor8 Filter is immutable data structure, hence it is not possible to implement add() or delete() methods.

mre commented 4 years ago

Xor8 Filter is immutable data structure, hence it is not possible to implement add() or delete() methods.

That's true. Was thinking of a builder pattern to provide the same API:

let mut builder = Xor8Builder::new();
builder.insert("A Dance With Dragons".to_string());
let books = builder.build() // This creates the immutable datastructure

insert would be generic over T:

pub fn insert(&mut self, value: T) -> bool {
  todo!()
}

Using Xor filters instead of HashSet would then require minimal code changes, but I could understand if that design doesn't align with your goals for the crate.

prataprc commented 4 years ago

I am open to pull request. We can create a separate Builder type and implement a method into_xor8() to obtain the immutable Xor8 value.

uijin commented 4 years ago

IMHO, any type which implement Hash trait could get u64 hash value, used as key for Xor filters.

Would like to know the feasibility of this solution.

prataprc commented 4 years ago

Yes it is feasible ! Please check with @mre if you did like to take up this implementation.

mre commented 4 years ago

Hey @uijin, if you want to give it a shot, go ahead. I like your idea lot.

prataprc commented 4 years ago

Almost all of the feature requested is implemented. Documentation is added to publicly exposed API. Feel free to open separate issues for fixes and corrections.

Closing it.