-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial attempt at efficient range queries across multiple Set objects. #10
base: master
Are you sure you want to change the base?
Conversation
fstwrapper/src/set.rs
Outdated
@@ -146,13 +146,28 @@ pub extern "C" fn fst_set_make_opbuilder(ptr: *mut Set) -> *mut set::OpBuilder<' | |||
} | |||
make_free_fn!(fst_set_opbuilder_free, *mut set::OpBuilder); | |||
|
|||
#[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right! Nice catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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(ptr: *mut set::OpBuilder, set_ptr: *mut Set) { | ||
let set = ref_from_ptr!(set_ptr); | ||
let ob = mutref_from_ptr!(ptr); | ||
ob.push(set); | ||
} | ||
|
||
#[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)):