docs: add comments & hints for day one starter and reference code (#18)
* feat(docs): Improve/Add comments & some hints for day one starter code * feat(docs): Add comments for day one solution code * feat(docs): Add figure for block storage format in starter code (block.rs)
This commit is contained in:
@@ -30,11 +30,13 @@ impl BlockBuilder {
|
||||
#[must_use]
|
||||
pub fn add(&mut self, key: &[u8], value: &[u8]) -> bool {
|
||||
assert!(!key.is_empty(), "key must not be empty");
|
||||
// The overhead here is `key_len` + `val_len` + `offset`, each is of type `u16`
|
||||
if self.estimated_size() + key.len() + value.len() + SIZEOF_U16 * 3 > self.block_size
|
||||
&& !self.is_empty()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// The offsets should be updated at first, to maintain the correct offset
|
||||
self.offsets.push(self.data.len() as u16);
|
||||
self.data.put_u16(key.len() as u16);
|
||||
self.data.put(key);
|
||||
|
||||
Reference in New Issue
Block a user