Skip to content

Commit

Permalink
feat: w2d7, skip checksum (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben1009 authored Apr 18, 2024
1 parent 271de6b commit 4b7c683
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mini-lsm-starter/src/lsm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,21 @@ impl LsmStorageInner {
}

/// Write a batch of data into the storage. Implement in week 2 day 7.
pub fn write_batch<T: AsRef<[u8]>>(&self, _batch: &[WriteBatchRecord<T>]) -> Result<()> {
unimplemented!()
pub fn write_batch<T: AsRef<[u8]>>(&self, batch: &[WriteBatchRecord<T>]) -> Result<()> {
for record in batch {
match record {
WriteBatchRecord::Del(key) => {
self.delete(key.as_ref())?;
}
WriteBatchRecord::Put(key, value) => {
self.put(key.as_ref(), value.as_ref())?;
}
}
}

Ok(())
}

/// Put a key-value pair into the storage by writing into the current memtable.
/// As our memtable implementation only requires an immutable reference for put,
/// you ONLY need to take the read lock on state in order to modify the memtable.
Expand Down

0 comments on commit 4b7c683

Please sign in to comment.