| 
									
										
										
										
											2022-12-23 18:44:59 -05:00
										 |  |  | #![allow(unused_variables)] // TODO(you): remove this lint after implementing this mod
 | 
					
						
							|  |  |  | #![allow(dead_code)] // TODO(you): remove this lint after implementing this mod
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | mod builder;
 | 
					
						
							|  |  |  | mod iterator;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pub use builder::BlockBuilder;
 | 
					
						
							| 
									
										
										
										
											2023-07-11 12:05:34 +08:00
										 |  |  | /// You may want to check `bytes::BufMut` out when manipulating continuous chunks of memory
 | 
					
						
							| 
									
										
										
										
											2022-12-24 10:11:06 -05:00
										 |  |  | use bytes::Bytes;
 | 
					
						
							| 
									
										
										
										
											2022-12-23 18:44:59 -05:00
										 |  |  | pub use iterator::BlockIterator;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-11 12:05:34 +08:00
										 |  |  | /// A block is the smallest unit of read and caching in LSM tree.
 | 
					
						
							|  |  |  | /// It is a collection of sorted key-value pairs.
 | 
					
						
							|  |  |  | /// The `actual` storage format is as below (After `Block::encode`):
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// ----------------------------------------------------------------------------------------------------
 | 
					
						
							|  |  |  | /// |             Data Section             |              Offset Section             |      Extra      |
 | 
					
						
							|  |  |  | /// ----------------------------------------------------------------------------------------------------
 | 
					
						
							|  |  |  | /// | Entry #1 | Entry #2 | ... | Entry #N | Offset #1 | Offset #2 | ... | Offset #N | num_of_elements |
 | 
					
						
							|  |  |  | /// ----------------------------------------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2022-12-23 23:45:09 -05:00
										 |  |  | pub struct Block {
 | 
					
						
							|  |  |  |     data: Vec<u8>,
 | 
					
						
							|  |  |  |     offsets: Vec<u16>,
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2022-12-23 18:44:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | impl Block {
 | 
					
						
							| 
									
										
										
										
											2023-07-11 12:05:34 +08:00
										 |  |  |     /// Encode the internal data to the data layout illustrated in the tutorial
 | 
					
						
							|  |  |  |     /// Note: You may want to recheck if any of the expected field is missing from your output
 | 
					
						
							| 
									
										
										
										
											2022-12-23 18:44:59 -05:00
										 |  |  |     pub fn encode(&self) -> Bytes {
 | 
					
						
							|  |  |  |         unimplemented!()
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-11 12:05:34 +08:00
										 |  |  |     /// Decode from the data layout, transform the input `data` to a single `Block`
 | 
					
						
							| 
									
										
										
										
											2022-12-23 18:44:59 -05:00
										 |  |  |     pub fn decode(data: &[u8]) -> Self {
 | 
					
						
							|  |  |  |         unimplemented!()
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[cfg(test)]
 | 
					
						
							|  |  |  | mod tests;
 |