Initial attempt at efficient range queries across multiple Set objects.#10
Initial attempt at efficient range queries across multiple Set objects.#10davidblewett wants to merge 6 commits intojbaiter:masterfrom
Conversation
fstwrapper/src/set.rs
Outdated
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn fst_set_make_opstreambuilder(ptr: *mut set::Stream) -> *mut set::OpBuilder<'static> { | ||
| let stream = ref_from_ptr!(ptr); |
There was a problem hiding this comment.
@davidblewett I think you want stream to be a set::Stream here, but it looks like it's a &set::Stream. In particular, this requires passing ownership of the stream into this function, so I imagine you want something like let stream = unsafe { *Box::from_raw(ptr) };. Similarly for the function below.
I haven't audited this code thoroughly, but I might be concerned about memory leaks here. e.g., What's responsible for freeing the memory of an opbuilder?
There was a problem hiding this comment.
https://github.com/jbaiter/python-rust-fst/blob/master/rust_fst/set.py#L60-L61 :
# NOTE: No need for `ffi.gc`, since the struct will be free'd
# once we call union/intersection/difference
@jbaiter how do I wire up fst_set_opstreambuilder_free ?
There was a problem hiding this comment.
@BurntSushi I tried updating to use *mut &set::Stream, but the result didn't change:
Compiling fst-wrapper v0.3.0 (file:///home/dblewett/src/python-rust-fst/fstwrapper)
error[E0277]: the trait bound `for<'a> &fst::set::Stream<'_>: fst::Streamer<'a>` is not satisfied
--> src/set.rs:152:36
|
152 | let ob = set::OpBuilder::new().add(stream);
| ^^^ the trait `for<'a> fst::Streamer<'a>` is not implemented for `&fst::set::Stream<'_>`
|
= help: the following implementations were found:
<fst::set::Stream<'s, A> as fst::Streamer<'a>>
error[E0277]: the trait bound `for<'a> &fst::set::Stream<'_>: fst::Streamer<'a>` is not satisfied
--> src/set.rs:168:8
|
168 | ob.push(stream);
| ^^^^ the trait `for<'a> fst::Streamer<'a>` is not implemented for `&fst::set::Stream<'_>`
|
= help: the following implementations were found:
<fst::set::Stream<'s, A> as fst::Streamer<'a>>
error: aborting due to 2 previous errors
error: Could not compile `fst-wrapper`.
fstwrapper/src/set.rs
Outdated
| } | ||
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn fst_set_opbuilder_push_stream(ptr: *mut set::OpBuilder, stream_ptr: *mut &set::Stream) { |
There was a problem hiding this comment.
This should be *mut set::Stream, not *mut &set::Stream.
|
@BurntSushi @jbaiter However, now I'm getting segfaults in trying to test the functionality: The API signature is a little awkward and should probably get some more thought, but I was just trying to test the plumbing without luck. |
|
Can you add a unit test for the |
* Supports range queries across multiple sets: a = Set.from_iter(["bar", "foo"]) b = Set.from_iter(["baz", "foo"]) list(UnionSet(a, b)['ba':'bb']) ['bar', 'baz'] * Add StreamBuilder, to correspond with the Rust library's abstraction * Update OpBuilder to support constructing operations against multiple underlying types (Set and StreamBuilder for now)
* difference, intersection, symmetric_difference, union
4fe60f7 to
5b1a20e
Compare
|
@jbaiter @BurntSushi Sorry this got delayed so long. I have this working now. |
|
The tests pass for me (cPython 3.7, Ubuntu 18.04.1): |
|
@jbaiter, @BurntSushi what do you think of this? I wasn't sure about the |
33e7553 to
3488ff7
Compare
BurntSushi
left a comment
There was a problem hiding this comment.
From a quick skim, this all looks reasonable to me! Nice work!
|
@jbaiter is there interest in including this in this package? If not the entire PR, maybe the supporting C functions? it would be cumbersome to do completely outside this package. |
This is not compiling yet (using rustc 1.24.0-nightly (0a3761e63 2018-01-03)):