Skip to content

Commit

Permalink
Merge pull request #52 from meilisearch/keep-source-index-in-merger
Browse files Browse the repository at this point in the history
Keep source index in Merger
  • Loading branch information
Kerollmops authored Apr 9, 2024
2 parents cb73ade + 5a7c10f commit f0db5f3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ impl<R, MF> Extend<ReaderCursor<R>> for MergerBuilder<R, MF> {

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 @@ impl<R: io::Read + io::Seek, MF> Merger<R, MF> {
/// 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

0 comments on commit f0db5f3

Please sign in to comment.