Skip to content
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

Ordered stream utils #2517

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

jmorag
Copy link

@jmorag jmorag commented Nov 15, 2021

This adds utility functions for merge and diff operations on sorted streams in constant space. I had a problem at work where I needed to diff a sorted stream of database items with the keys of a bunch of s3 buckets. The generic versions of those functions seem generic enough to merit inclusion here.

@jmorag jmorag requested a review from taiki-e as a code owner November 15, 2021 20:31
fn gen_index(n: usize) -> usize {
pub fn gen_index(n: usize) -> usize {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed an rng for the 'delayed streams' tests. pub(crate) didn't seem to work for that, I guess because this is in futures-util and the tests are all in futures.

Comment on lines +56 to +64
// For reference
// diff :: Ord a => [a] -> [a] -> [a]
// diff (x : xs) (y : ys)
// | x == y = diff xs ys
// | x < y = x : diff xs (y : ys)
// | x > y = diff (x : xs) ys
// diff xs [] = xs
// diff [] _ = []

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prototyped the actual algorithm in Haskell. Happy to delete this if it's not helpful.

@jmorag
Copy link
Author

jmorag commented Jan 5, 2022

Fixed the rest of the CI failures. Please let me know if you'd like me to squash everything from 4e01c51 on.

@anacrolix

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants