aboutsummaryrefslogtreecommitdiff
path: root/database/src/sort/none.rs
diff options
context:
space:
mode:
Diffstat (limited to 'database/src/sort/none.rs')
-rw-r--r--database/src/sort/none.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/database/src/sort/none.rs b/database/src/sort/none.rs
new file mode 100644
index 0000000..b17cb29
--- /dev/null
+++ b/database/src/sort/none.rs
@@ -0,0 +1,50 @@
+/*
+ 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,
+ filter::binning::Binning,
+ sort::Index,
+ table::{RowNum, TableNum},
+};
+use anyhow::Result;
+use jellycommon::jellyobject::Object;
+
+pub struct UnsortedIndex {
+ id: TableNum,
+ binning: Binning,
+}
+
+impl UnsortedIndex {
+ pub fn new(id: TableNum, binning: Binning) -> Self {
+ Self { id, binning }
+ }
+ fn keys(&self, id: RowNum, ob: Object) -> Vec<Vec<u8>> {
+ let mut keys = vec![self.id.to_be_bytes().to_vec()];
+ self.binning.apply(ob, &mut keys);
+ for k in &mut keys {
+ k.extend(id.to_ne_bytes());
+ }
+ keys
+ }
+}
+impl Index for UnsortedIndex {
+ fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, ob: Object) -> Result<()> {
+ for key in self.keys(id, ob) {
+ db.set(&key, &[])?;
+ }
+ Ok(())
+ }
+ fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, ob: Object) -> Result<()> {
+ for key in self.keys(id, ob) {
+ db.del(&key)?;
+ }
+ Ok(())
+ }
+ fn compare(&self, before: Object, after: Object) -> bool {
+ self.keys(0, before) == self.keys(0, after)
+ }
+}