Change entry header. Expand api

This commit is contained in:
Yuriy Dupyn 2024-02-02 18:27:32 +01:00
parent 2f23df1009
commit cac34d95e0
6 changed files with 150 additions and 39 deletions

View 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!()
}
}