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

Keep source index in Merger #52

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

/// Add a source to merge, this function can be chained.
pub fn add(mut self, source: ReaderCursor<R>) -> Self {

Check warning on line 23 in src/merger.rs

View workflow job for this annotation

GitHub Actions / lint

method `add` can be confused for the standard trait method `std::ops::Add::add`
self.push(source);
self
}
Expand All @@ -44,13 +44,14 @@

struct Entry<R> {
cursor: ReaderCursor<R>,
source_index: usize,
}

impl<R> Ord for Entry<R> {
fn cmp(&self, other: &Entry<R>) -> Ordering {
let skey = self.cursor.current().map(|(k, _)| k);
let okey = other.cursor.current().map(|(k, _)| k);
skey.cmp(&okey).reverse()
skey.cmp(&okey).then(self.source_index.cmp(&other.source_index)).reverse()
}
}

Expand Down Expand Up @@ -87,9 +88,9 @@
/// Consumes this [`Merger`] and outputs a stream of the merged entries in key-order.
pub fn into_stream_merger_iter(self) -> Result<MergerIter<R, MF>, Error> {
let mut heap = BinaryHeap::new();
for mut source in self.sources {
for (index, mut source) in self.sources.into_iter().enumerate() {
if source.move_on_next()?.is_some() {
heap.push(Entry { cursor: source });
heap.push(Entry { cursor: source, source_index: index });
}
}

Expand Down Expand Up @@ -137,7 +138,7 @@
MF: for<'a> Fn(&[u8], &[Cow<'a, [u8]>]) -> Result<Cow<'a, [u8]>, U>,
{
/// Yield the entries in key-order where values have been merged when needed.
pub fn next(&mut self) -> Result<Option<(&[u8], &[u8])>, Error<U>> {

Check warning on line 141 in src/merger.rs

View workflow job for this annotation

GitHub Actions / lint

method `next` can be confused for the standard trait method `std::iter::Iterator::next`

Check warning on line 141 in src/merger.rs

View workflow job for this annotation

GitHub Actions / lint

very complex type used. Consider factoring parts into `type` definitions
let first_entry = match self.heap.pop() {
Some(entry) => entry,
None => return Ok(None),
Expand Down
Loading