Kerollmops / sdset

Set theory applied on sorted and deduplicated slices.
https://docs.rs/sdset
MIT License
46 stars 3 forks source link

[Feature] Streaming set operations via .from_iters() and .to_iter() functions #19

Open tzcnt opened 2 years ago

tzcnt commented 2 years ago

Needs

I'd like to create from_iters() and to_iter() versions of each operation. This would lazily evaluate/produce each member of the sequences. This would not be as performant as the current exponential-search version when it comes to working slice-to-slice, but would allow for a few additional use cases:

Proposed implementation details:

They should be compatible with the existing slices -> slice API. This means introducing 3 new dataflow paths: slices -> iter, iters -> slice, and iter -> iter.

Proposed Syntax:

let a: SetBuf<i32> = SetBuf::new_unchecked((0..1_000_000).collect());
let b: SetBuf<i32> = SetBuf::new_unchecked((0..1_000_000).collect());

// slices -> slice (current syntax)
let inter: SetBuf<i32> = sdset::duo::OpBuilder::new(&a, &b).intersection().into_set_buf();

// slices -> iter
let inter: SetBuf<i32> = sdset::duo::OpBuilder::new(&a, &b).intersection().into_iter();

// iters -> slice
let inter: SetBuf<i32> = sdset::duo::OpBuilder::from_iters(&a.iter(), &b.iter()).intersection().into_set_buf();

// iters -> iter
let inter: SetBuf<i32> = sdset::duo::OpBuilder::from_iters(&a.iter(), &b.iter()).intersection().into_iter();

To implement this, the existing Union/Intersection/Difference/SymmetricDifference types would need to be extended with an into_iter() function that would lazily consume the input slice. This would then cover the slices -> slice and slices -> iter case.

New types UnionOfIters/IntersectionOfIters/DifferenceOfIters/SymmetricDifferenceOfIters would need to be created whose a and b input fields are &'a mut dyn Iterator<T>. These would then have the into_set_buf() and into_iter() functions implemented, covering the iters -> slice and iters -> iter case.

Kerollmops commented 2 years ago

I just sent you an invitation to help me maintain this repository, you can accept it, it should be in your inbox 😃