Skip to content

Commit 47ad080

Browse files
authored
docs: clarify MergeIterator heap rationale and ouroboros usage (#149)
1 parent 05d5d42 commit 47ad080

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

mini-lsm-book/src/week1-02-merge-iterator.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ In this chapter, you will:
1212
* Implement merge iterator.
1313
* Implement LSM read path `scan` for memtables.
1414

15-
1615
To copy the test cases into the starter code and run them,
1716

1817
```
@@ -58,7 +57,7 @@ pub struct MemtableIterator { // <- with lifetime 'this
5857

5958
Then the problem is solved! You can do this with the help of some third-party libraries like `ouroboros`. It provides an easy way to define self-referential structure. It is also possible to do this with unsafe Rust (and indeed, `ouroboros` itself uses unsafe Rust internally...)
6059

61-
We have already defined the self-referential `MemtableIterator` fields for you, and you will need to implement `MemtableIterator` and the `Memtable::scan` API.
60+
We have leveraged [`ouroboros`](https://docs.rs/ouroboros/latest/ouroboros/attr.self_referencing.html) to define the self-referential `MemtableIterator` fields for you. You will need to implement the `MemtableIterator` logic and the `Memtable::scan` API based on this provided structure.
6261

6362
## Task 2: Merge Iterator
6463

@@ -70,7 +69,7 @@ src/iterators/merge_iterator.rs
7069

7170
Now that you have multiple memtables and you will create multiple memtable iterators. You will need to merge the results from the memtables and return the latest version of each key to the user.
7271

73-
`MergeIterator` maintains a binary heap internally. You'll see that the ordering of the binary heap is such that the iterator with the lowest head key value is first. When multiple iterators have the same head key value, the newest one is first. Note that you will need to handle errors (i.e., when an iterator is not valid) and ensure that the latest version of a key-value pair comes out.
72+
`MergeIterator` maintains a binary heap internally. Consider the challenge of merging `n` sorted sequences (our iterators) into a single sorted output; a binary heap is a natural fit here, as it efficiently helps identify which sequence currently holds the overall smallest element. You'll see that the ordering of the binary heap is such that the iterator with the lowest head key value is first. When multiple iterators have the same head key value, the newest one is first. Note that you will need to handle errors (i.e., when an iterator is not valid) and ensure that the latest version of a key-value pair comes out.
7473

7574
For example, if we have the following data:
7675

0 commit comments

Comments
 (0)