aboutsummaryrefslogtreecommitdiff
path: root/database/src/indices
diff options
context:
space:
mode:
Diffstat (limited to 'database/src/indices')
-rw-r--r--database/src/indices/key.rs26
-rw-r--r--database/src/indices/mod.rs11
-rw-r--r--database/src/indices/order.rs21
3 files changed, 30 insertions, 28 deletions
diff --git a/database/src/indices/key.rs b/database/src/indices/key.rs
index ab38d71..2790220 100644
--- a/database/src/indices/key.rs
+++ b/database/src/indices/key.rs
@@ -8,18 +8,18 @@ use crate::{
backends::{ReadTransaction, WriteTransaction},
indices::Index,
prefix_iterator::PrefixIterator,
- table::{RowNum, Table, TableNum},
+ table::{RowNum, TableNum},
};
use anyhow::Result;
+use jellycommon::jellyobject::{Object, Tag};
-pub struct KeyIndex<T> {
+pub struct KeyIndex {
id: TableNum,
- key: fn(&T) -> &[u8],
+ key: Vec<Tag>,
}
-impl<T: 'static> KeyIndex<T> {
- pub fn new(table: &mut Table<T>, id: TableNum, key: fn(&T) -> &[u8]) -> Self {
- table.indices.push(Box::new(Self { id, key }));
+impl KeyIndex {
+ pub fn new(id: TableNum, key: Vec<Tag>) -> Self {
Self { id, key }
}
pub fn key(&self, id: RowNum, key: &[u8]) -> Vec<u8> {
@@ -43,15 +43,15 @@ impl<T: 'static> KeyIndex<T> {
})
}
}
-impl<T: 'static> Index<T> for KeyIndex<T> {
- fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
- db.set(&self.key(id, (self.key)(val)), &[])
+impl Index for KeyIndex {
+ fn add(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
+ // db.set(&self.key(id, (self.key)(val)), &[])
}
- fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: &T) -> Result<()> {
- db.del(&self.key(id, (self.key)(val)))
+ fn remove(&self, db: &mut dyn WriteTransaction, id: RowNum, val: Object) -> Result<()> {
+ // db.del(&self.key(id, (self.key)(val)))
}
- fn compare(&self, before: &T, after: &T) -> bool {
- (self.key)(before) == (self.key)(after)
+ fn compare(&self, before: Object, after: Object) -> bool {
+ // (self.key)(before) == (self.key)(after)
}
}
diff --git a/database/src/indices/mod.rs b/database/src/indices/mod.rs
index ab37589..ad3d00f 100644
--- a/database/src/indices/mod.rs
+++ b/database/src/indices/mod.rs
@@ -6,14 +6,15 @@
use crate::{backends::WriteTransaction, table::RowNum};
use anyhow::Result;
+use jellycommon::jellyobject::Object;
-pub mod order;
pub mod key;
+pub mod order;
-pub trait Index<T> {
- fn add(&self, db: &mut dyn WriteTransaction, row: RowNum, val: &T) -> Result<()>;
- fn remove(&self, db: &mut dyn WriteTransaction, row: RowNum, val: &T) -> Result<()>;
- fn compare(&self, before: &T, after: &T) -> bool {
+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);
true
}
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)
}
}