aboutsummaryrefslogtreecommitdiff
path: root/database/src/indices/order.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-06 19:10:37 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-06 19:10:37 +0100
commitffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b (patch)
tree79a03bc7ed938a3698ece0878f0ce5337ff6db23 /database/src/indices/order.rs
parentffbdb9ce397a6408d5a91cbdcbaf4e13b0c3ba0b (diff)
downloadjellything-ffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b.tar
jellything-ffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b.tar.bz2
jellything-ffa6b5c4ae2cdd3e07426ed0330f3f66e90ee57b.tar.zst
tag registry
Diffstat (limited to 'database/src/indices/order.rs')
-rw-r--r--database/src/indices/order.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/database/src/indices/order.rs b/database/src/indices/order.rs
index 9163681..911ec37 100644
--- a/database/src/indices/order.rs
+++ b/database/src/indices/order.rs
@@ -7,34 +7,35 @@
use crate::{
backends::WriteTransaction,
indices::Index,
- table::{RowNum, Table, TableNum},
+ table::{RowNum, TableNum},
};
use anyhow::Result;
use bytemuck::{NoUninit, bytes_of};
+use jellycommon::jellyobject::{Object, Tag};
-pub struct OrderIndex<T> {
+#[derive(Clone)]
+pub struct OrderIndex {
id: TableNum,
- value: fn(&T) -> [u8; 8],
+ key: Vec<Tag>,
}
#[repr(C)]
#[derive(NoUninit, Clone, Copy)]
struct Key(TableNum, [u8; 8], RowNum);
-impl<T: 'static> OrderIndex<T> {
- pub fn new(table: &mut Table<T>, id: TableNum, value: fn(&T) -> [u8; 8]) -> Self {
- table.indices.push(Box::new(Self { id, value }));
+impl OrderIndex {
+ pub fn new(id: TableNum, value: fn(Object) -> [u8; 8]) -> Self {
Self { id, value }
}
}
-impl<T: 'static> Index<T> for OrderIndex<T> {
- fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
+impl Index for OrderIndex {
+ fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
db.set(bytes_of(&Key(self.id, (self.value)(val), id)), &[])
}
- fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
+ fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
db.del(bytes_of(&Key(self.id, (self.value)(val), id)))
}
- fn compare(&self, before: &T, after: &T) -> bool {
+ fn compare(&self, before: Object, after: Object) -> bool {
(self.value)(before) == (self.value)(after)
}
}