diff options
Diffstat (limited to 'database/src/sort')
| -rw-r--r-- | database/src/sort/mod.rs | 32 | ||||
| -rw-r--r-- | database/src/sort/none.rs | 9 | ||||
| -rw-r--r-- | database/src/sort/value.rs | 9 |
3 files changed, 35 insertions, 15 deletions
diff --git a/database/src/sort/mod.rs b/database/src/sort/mod.rs index e87630c..58d8eff 100644 --- a/database/src/sort/mod.rs +++ b/database/src/sort/mod.rs @@ -4,20 +4,34 @@ Copyright (C) 2026 metamuffin <metamuffin.org> */ -use crate::table::RowNum; +use crate::{ + query::{MultiBehaviour, Sort}, + table::IndexKey, +}; use anyhow::Result; use jellykv::WriteTransaction; -use jellyobject::Object; +use jellyobject::{Object, Path}; pub mod none; pub mod value; -pub trait Index: Send + Sync + 'static { - fn add(&self, db: &mut dyn WriteTransaction, row: RowNum, val: Object) -> Result<()>; - fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum, val: Object) -> Result<()>; - /// Might return true if objects are identical for this index; false if not or uncertain - fn compare(&self, before: Object, after: Object) -> bool { - let _ = (before, after); - false +#[derive(Hash, PartialEq, Eq)] +pub enum SortKey { + None, + Value(Path, MultiBehaviour), + Text(Path), +} + +impl Sort { + pub fn key(&self) -> SortKey { + match self { + Sort::None => SortKey::None, + Sort::Value(vs) => SortKey::Value(vs.path.clone(), vs.multi), + Sort::TextSearch(p, _) => SortKey::Text(p.to_owned()), + } } } + +pub fn index_add(txn: &mut dyn WriteTransaction, ik: &IndexKey, ob: &Object) -> Result<()> { + +} diff --git a/database/src/sort/none.rs b/database/src/sort/none.rs index 65454a2..efaa7f8 100644 --- a/database/src/sort/none.rs +++ b/database/src/sort/none.rs @@ -6,11 +6,11 @@ use crate::{ filter::binning::Binning, - sort::Index, - table::{RowNum, TableNum}, + query::Sort, + table::{RowIter, RowNum, TableNum}, }; use anyhow::Result; -use jellykv::WriteTransaction; +use jellykv::{ReadTransaction, WriteTransaction}; use jellyobject::Object; pub struct UnsortedIndex { @@ -47,4 +47,7 @@ impl Index for UnsortedIndex { fn compare(&self, before: Object, after: Object) -> bool { self.keys(0, before) == self.keys(0, after) } + fn query(&self, txn: &mut dyn ReadTransaction, _sort: &Sort) -> Result<RowIter> { + todo!() + } } diff --git a/database/src/sort/value.rs b/database/src/sort/value.rs index 79bdc0b..6e42fd7 100644 --- a/database/src/sort/value.rs +++ b/database/src/sort/value.rs @@ -6,12 +6,12 @@ use crate::{ filter::binning::Binning, - query::{MultiBehaviour, ValueSort}, + query::{MultiBehaviour, Sort, ValueSort}, sort::Index, - table::{RowNum, TableNum}, + table::{RowIter, RowNum, TableNum}, }; use anyhow::Result; -use jellykv::WriteTransaction; +use jellykv::{ReadTransaction, WriteTransaction}; use jellyobject::Object; pub struct ValueIndex { @@ -50,6 +50,9 @@ impl Index for ValueIndex { fn compare(&self, before: Object, after: Object) -> bool { self.keys(0, before) == self.keys(0, after) } + fn query(&self, txn: &mut dyn ReadTransaction, sort: &Sort) -> Result<RowIter> { + todo!() + } } impl ValueSort { fn apply(&self, ob: Object, keys: &mut Vec<Vec<u8>>) { |