Sketch out indexes in Store
This commit is contained in:
parent
dae012daa7
commit
89305b6126
4 changed files with 82 additions and 32 deletions
|
|
@ -14,10 +14,14 @@ use crate::entry::{Entry, EntryDetailed};
|
|||
use crate::entry_header::{EntryHeaderWithDataSize, EntryHeader};
|
||||
use crate::store_header::StoreHeader;
|
||||
use crate::storage_engine::{Store, FilePosition, Column, Result, ROWS_FILE_NAME, GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME};
|
||||
use crate::index::Index;
|
||||
|
||||
|
||||
|
||||
// ===Concrete Cursors===
|
||||
pub struct ReadCursor<T> {
|
||||
pub struct ReadCursor<'a, T> {
|
||||
header: StoreHeader,
|
||||
indexes: Vec<Option<&'a Index<T, FilePosition>>>,
|
||||
file: File,
|
||||
data_type: PhantomData<T>,
|
||||
|
||||
|
|
@ -26,6 +30,7 @@ pub struct ReadCursor<T> {
|
|||
|
||||
pub struct WriteCursor<'a, T> {
|
||||
header: &'a mut StoreHeader,
|
||||
indexes: Vec<Option<&'a Index<T, FilePosition>>>,
|
||||
file: File,
|
||||
data_type: PhantomData<T>,
|
||||
|
||||
|
|
@ -224,9 +229,20 @@ pub trait CursorWithStoreHeader<T>: PrimitiveCursor<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait CursorWithAccessToIndex<T>: CursorWithStoreHeader<T> {
|
||||
fn indexes(&mut self) -> &[Option<&Index<T, FilePosition>>];
|
||||
|
||||
async fn find_in_index(&mut self, k: &T) -> Result<Option<FilePosition>>
|
||||
where T: Encode + Decode + Ord + Send + Sync
|
||||
{
|
||||
// let x = self.primary_index().lookup(k).await?;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// ===PrimitiveCursor===
|
||||
impl <T>PrimitiveCursor<T> for ReadCursor<T> {
|
||||
impl <T>PrimitiveCursor<T> for ReadCursor<'_, T> {
|
||||
fn file(&mut self) -> &mut File {
|
||||
&mut self.file
|
||||
}
|
||||
|
|
@ -247,7 +263,7 @@ impl <T>PrimitiveCursor<T> for WriteCursor<'_, T> {
|
|||
}
|
||||
|
||||
// ===CursorWithStoreHeader===
|
||||
impl <T>CursorWithStoreHeader<T> for ReadCursor<T> {
|
||||
impl <T>CursorWithStoreHeader<T> for ReadCursor<'_, T> {
|
||||
fn header(&self) -> &StoreHeader {
|
||||
&self.header
|
||||
}
|
||||
|
|
@ -259,9 +275,23 @@ impl <T>CursorWithStoreHeader<T> for WriteCursor<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl <T> ReadCursor<T> {
|
||||
pub async fn new(store: &Store<T>) -> Result<Self>
|
||||
where T: Send
|
||||
// ===CursorWithAccessToIndex===
|
||||
impl <T>CursorWithAccessToIndex<T> for ReadCursor<'_, T> {
|
||||
fn indexes(&mut self) -> &[Option<&Index<T, FilePosition>>] {
|
||||
&self.indexes
|
||||
}
|
||||
}
|
||||
|
||||
impl <T>CursorWithAccessToIndex<T> for WriteCursor<'_, T> {
|
||||
fn indexes(&mut self) -> &[Option<&Index<T, FilePosition>>] {
|
||||
&self.indexes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl <'cursor, T> ReadCursor<'cursor, T> {
|
||||
pub async fn new<'store: 'cursor>(store: &'store Store<T>) -> Result<Self>
|
||||
where T: Send + Sync
|
||||
{
|
||||
let path_to_rows = Path::new(&store.header.table_folder).join(ROWS_FILE_NAME);
|
||||
let file: File =
|
||||
|
|
@ -274,6 +304,7 @@ impl <T> ReadCursor<T> {
|
|||
header: store.header.clone(),
|
||||
file,
|
||||
data_type: store.data_type,
|
||||
indexes: todo!(),
|
||||
|
||||
eof_file_position: 0,
|
||||
};
|
||||
|
|
@ -284,13 +315,12 @@ impl <T> ReadCursor<T> {
|
|||
|
||||
Ok(cursor)
|
||||
}
|
||||
|
||||
pub async fn less_than_eq(&mut self, file_position0: FilePosition, file_position1: FilePosition) -> Result<bool> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl <'cursor, T> WriteCursor<'cursor, T> {
|
||||
impl <'cursor, T> WriteCursor<'cursor, T>
|
||||
// TODO: Consider adding this manually to wher eit is really needed
|
||||
where T: Sync
|
||||
{
|
||||
// 'store lives atleast as long as 'cursor
|
||||
pub async fn new<'store: 'cursor>(store: &'store mut Store<T>) -> Result<Self>
|
||||
where T: Send
|
||||
|
|
@ -307,6 +337,7 @@ impl <'cursor, T> WriteCursor<'cursor, T> {
|
|||
header: &mut store.header,
|
||||
file,
|
||||
data_type: store.data_type,
|
||||
indexes: todo!(),
|
||||
|
||||
eof_file_position: 0,
|
||||
};
|
||||
|
|
@ -332,6 +363,7 @@ impl <'cursor, T> WriteCursor<'cursor, T> {
|
|||
header,
|
||||
file,
|
||||
data_type: PhantomData::<T>,
|
||||
indexes: todo!(),
|
||||
|
||||
eof_file_position: 0,
|
||||
};
|
||||
|
|
@ -478,4 +510,20 @@ impl <'cursor, T> WriteCursor<'cursor, T> {
|
|||
// Afterwards we swap the files, and delete the garbage.
|
||||
todo!()
|
||||
}
|
||||
|
||||
// ===Indexing===
|
||||
async fn insert_to_index(&mut self, t: T, file_position: FilePosition) -> Result<Option<FilePosition>>
|
||||
where T: Encode + Decode + Ord + Send + Sync
|
||||
{
|
||||
// let x = self.primary_index.insert(t, file_position).await?;
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn delete_from_index(&mut self, t: T, file_position: FilePosition) -> Result<Option<FilePosition>>
|
||||
where T: Encode + Decode + Ord + Send + Sync
|
||||
{
|
||||
// let x = self.primary_index.delete(t, file_position).await?;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue