Change entry header. Expand api
This commit is contained in:
parent
2f23df1009
commit
cac34d95e0
6 changed files with 150 additions and 39 deletions
68
storage_engine/src/index.rs
Normal file
68
storage_engine/src/index.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
use std::marker::PhantomData;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt, AsyncSeekExt, SeekFrom};
|
||||
use tokio::fs::{File, OpenOptions, DirBuilder};
|
||||
use std::path::Path;
|
||||
|
||||
use std::collections::{BTreeMap};
|
||||
|
||||
use bincode;
|
||||
use bincode::{Decode, Encode};
|
||||
use crate::binary_coding::{encode, decode, encode_sequence, decode_sequence};
|
||||
use tokio::fs;
|
||||
|
||||
use crate::error::{Error, DecodeErrorKind};
|
||||
|
||||
use std::mem::size_of;
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
// Implements a persistant self-balancing Binary Search Tree. Nope.
|
||||
// We need fixed-size nodes. But we want to index Strings which are variable length.
|
||||
|
||||
pub struct Index<K, V> {
|
||||
file: File,
|
||||
// None means index is asleep on disk.
|
||||
in_memory: Option<BTreeMap<K, V>>,
|
||||
header: IndexHeader,
|
||||
key_type: PhantomData<K>,
|
||||
value_type: PhantomData<V>,
|
||||
}
|
||||
|
||||
pub struct IndexHeader {
|
||||
}
|
||||
|
||||
impl <I, V>Index<I, V> {
|
||||
pub async fn new(file_name: &str) -> Result<Index<I, V>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn connect(file_name: &str) -> Result<Index<I, V>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// Saves the in-memory index to disk and deallocates.
|
||||
pub async fn sleep() -> Result<Index<I, V>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// Loads the index into memory
|
||||
pub async fn wake() -> Result<Index<I, V>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn insert() -> Result<()>
|
||||
where I: Encode, V: Encode
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn lookup(&mut self, k: I) -> Result<Option<V>>
|
||||
where I: Encode + Decode,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn delete(&mut self, k: I) -> Result<Option<V>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue