diff options
Diffstat (limited to 'database/src/indices')
| -rw-r--r-- | database/src/indices/mod.rs | 21 | ||||
| -rw-r--r-- | database/src/indices/rating.rs | 41 | ||||
| -rw-r--r-- | database/src/indices/reference.rs | 71 |
3 files changed, 0 insertions, 133 deletions
diff --git a/database/src/indices/mod.rs b/database/src/indices/mod.rs deleted file mode 100644 index 2d8642a..0000000 --- a/database/src/indices/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2026 metamuffin <metamuffin.org> -*/ - -use crate::{backends::WriteTransaction, table::RowNum}; -use anyhow::Result; -use jellycommon::jellyobject::Object; - -pub mod reference; -pub mod rating; - -pub trait Index { - fn add(&self, db: &mut dyn WriteTransaction, row: RowNum, val: Object) -> Result<()>; - fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum, val: Object) -> Result<()>; - fn compare(&self, before: Object, after: Object) -> bool { - let _ = (before, after); - false - } -} diff --git a/database/src/indices/rating.rs b/database/src/indices/rating.rs deleted file mode 100644 index 003d327..0000000 --- a/database/src/indices/rating.rs +++ /dev/null @@ -1,41 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2026 metamuffin <metamuffin.org> -*/ - -use crate::{ - backends::WriteTransaction, - indices::Index, - table::{RowNum, TableNum}, -}; -use anyhow::Result; -use bytemuck::NoUninit; -use jellycommon::jellyobject::{Object, Tag, TypedTag}; - -#[derive(Clone)] -pub struct RatingIndex { - id: TableNum, - tag: TypedTag<Object<'static>>, -} - -#[repr(C)] -#[derive(NoUninit, Clone, Copy)] -struct Key(TableNum, Tag, u32, u64, RowNum); - -impl RatingIndex { - pub fn new(id: TableNum, tag: TypedTag<Object<'static>>) -> Self { - Self { id, tag } - } -} -impl Index for RatingIndex { - fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> { - todo!() - } - fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> { - todo!() - } - fn compare(&self, before: Object, after: Object) -> bool { - todo!() - } -} diff --git a/database/src/indices/reference.rs b/database/src/indices/reference.rs deleted file mode 100644 index 66efa24..0000000 --- a/database/src/indices/reference.rs +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2026 metamuffin <metamuffin.org> -*/ - -use crate::{ - backends::{ReadTransaction, WriteTransaction}, - indices::Index, - prefix_iterator::PrefixIterator, - table::{RowNum, TableNum}, -}; -use anyhow::Result; -use bytemuck::{NoUninit, bytes_of}; -use jellycommon::jellyobject::{Object, TypedTag}; - -pub struct ReferenceIndex { - id: TableNum, - tag: TypedTag<RowNum>, -} - -#[repr(C)] -#[derive(NoUninit, Clone, Copy)] -pub struct Key(TableNum, RowNum, RowNum); - -impl ReferenceIndex { - pub fn new(id: TableNum, tag: TypedTag<RowNum>) -> Self { - Self { id, tag } - } - pub fn lookup<'a>( - &self, - db: &'a dyn ReadTransaction, - to: RowNum, - ) -> Result<PrefixIterator<'a>> { - let mut prefix = Vec::new(); - prefix.extend(self.id.to_be_bytes()); - prefix.extend(to.to_be_bytes()); - Ok(PrefixIterator { - inner: db.iter(&prefix, false)?, - prefix: prefix.into(), - }) - } -} -impl Index for ReferenceIndex { - fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> { - for to in val.iter(self.tag) { - db.set(bytes_of(&Key(self.id, to, id)), &[])?; - } - Ok(()) - } - fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> { - for to in val.iter(self.tag) { - db.del(bytes_of(&Key(self.id, to, id)))?; - } - Ok(()) - } - fn compare(&self, before: Object, after: Object) -> bool { - let mut before = before.iter(self.tag); - let mut after = after.iter(self.tag); - loop { - let b = before.next(); - let a = after.next(); - if a.is_none() && b.is_none() { - break true; - } - if a != b { - break false; - } - } - } -} |