Thinking about indexes
This commit is contained in:
parent
85ef52dfb4
commit
dbd2ba9946
2 changed files with 72 additions and 5 deletions
|
|
@ -4,13 +4,14 @@ use tokio::fs::{File, OpenOptions, DirBuilder};
|
|||
use std::path::Path;
|
||||
|
||||
use std::collections::{BTreeMap};
|
||||
use async_trait::async_trait;
|
||||
|
||||
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 crate::error::Error;
|
||||
|
||||
use std::mem::size_of;
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ 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.
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Index<K, V> {
|
||||
file: File,
|
||||
// None means index is asleep on disk.
|
||||
|
|
@ -28,11 +30,28 @@ pub struct Index<K, V> {
|
|||
value_type: PhantomData<V>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IndexHeader {
|
||||
}
|
||||
|
||||
use crate::storage_engine::FilePosition;
|
||||
|
||||
#[async_trait]
|
||||
pub trait SomethingSupportingLeq {
|
||||
async fn less_than_eq(&mut self, file_position0: FilePosition, file_position1: FilePosition) -> std::result::Result<bool, Error>;
|
||||
}
|
||||
|
||||
impl <K, V>Index<K, V> {
|
||||
pub async fn new(file_name: &str) -> Result<Index<K, V>> {
|
||||
// TODO: delete
|
||||
// pub async fn new<F, Fut, Store>(file_name: &str, less_than_eq: &F) -> Result<Index<K, V>>
|
||||
// where F: Fn(&mut Store, K, K) -> Fut,
|
||||
// Store: SomethingSupportingLeq,
|
||||
// Fut: Future<Output=std::result::Result<bool, Error>>,
|
||||
// {
|
||||
// todo!()
|
||||
// }
|
||||
pub async fn new(file_name: &str) -> Result<Index<K, V>>
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
@ -56,9 +75,11 @@ impl <K, V>Index<K, V> {
|
|||
todo!()
|
||||
}
|
||||
|
||||
pub async fn lookup(&mut self, k: K) -> Result<Option<V>>
|
||||
pub async fn lookup<Store>(&mut self, store: &mut Store, k: K) -> Result<Option<V>>
|
||||
where K: Encode + Decode,
|
||||
Store: SomethingSupportingLeq,
|
||||
{
|
||||
let x = store.less_than_eq(123, 123).await?;
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue