2022-12-24 10:11:06 -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
|
|
|
|
|
|
|
|
|
|
use std::ops::Bound;
|
2022-12-24 14:48:57 -05:00
|
|
|
use std::sync::Arc;
|
2022-12-24 10:11:06 -05:00
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use bytes::Bytes;
|
|
|
|
|
use crossbeam_skiplist::SkipMap;
|
2022-12-24 14:48:57 -05:00
|
|
|
use ouroboros::self_referencing;
|
2022-12-24 10:11:06 -05:00
|
|
|
|
2022-12-24 18:25:41 -05:00
|
|
|
use crate::iterators::StorageIterator;
|
2022-12-24 10:11:06 -05:00
|
|
|
use crate::table::SsTableBuilder;
|
|
|
|
|
|
|
|
|
|
/// A basic mem-table based on crossbeam-skiplist
|
|
|
|
|
pub struct MemTable {
|
|
|
|
|
map: SkipMap<Bytes, Bytes>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MemTable {
|
|
|
|
|
/// Create a new mem-table.
|
|
|
|
|
pub fn create() -> Self {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get a value by key.
|
2022-12-24 17:13:52 -05:00
|
|
|
pub fn get(&self, key: &[u8]) -> Option<Bytes> {
|
2022-12-24 10:11:06 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Put a key-value pair into the mem-table.
|
2022-12-24 17:13:52 -05:00
|
|
|
pub fn put(&self, key: &[u8], value: &[u8]) {
|
2022-12-24 10:11:06 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get an iterator over a range of keys.
|
2022-12-24 17:13:52 -05:00
|
|
|
pub fn scan(&self, lower: Bound<&[u8]>, upper: Bound<&[u8]>) -> MemTableIterator {
|
2022-12-24 10:11:06 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Flush the mem-table to SSTable.
|
|
|
|
|
pub fn flush(&self, builder: &mut SsTableBuilder) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SkipMapRangeIter<'a> =
|
|
|
|
|
crossbeam_skiplist::map::Range<'a, Bytes, (Bound<Bytes>, Bound<Bytes>), Bytes, Bytes>;
|
|
|
|
|
|
|
|
|
|
/// An iterator over a range of `SkipMap`.
|
2022-12-24 14:48:57 -05:00
|
|
|
#[self_referencing]
|
|
|
|
|
pub struct MemTableIterator {
|
|
|
|
|
map: Arc<SkipMap<Bytes, Bytes>>,
|
|
|
|
|
#[borrows(map)]
|
|
|
|
|
#[not_covariant]
|
|
|
|
|
iter: SkipMapRangeIter<'this>,
|
|
|
|
|
item: (Bytes, Bytes),
|
2022-12-24 10:11:06 -05:00
|
|
|
}
|
|
|
|
|
|
2022-12-24 14:48:57 -05:00
|
|
|
impl StorageIterator for MemTableIterator {
|
2022-12-24 10:11:06 -05:00
|
|
|
fn value(&self) -> &[u8] {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn key(&self) -> &[u8] {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_valid(&self) -> bool {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 09:00:53 -08:00
|
|
|
#[cfg(test)]
|
2022-12-24 10:11:06 -05:00
|
|
|
mod tests;
|