/* 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 */ use crate::{ backends::WriteTransaction, indices::Index, table::{RowNum, TableNum}, }; use anyhow::Result; use bytemuck::{NoUninit, bytes_of}; use jellycommon::jellyobject::{Object, Tag}; #[derive(Clone)] pub struct OrderIndex { id: TableNum, key: Vec, } #[repr(C)] #[derive(NoUninit, Clone, Copy)] struct Key(TableNum, [u8; 8], RowNum); impl OrderIndex { pub fn new(id: TableNum, value: fn(Object) -> [u8; 8]) -> Self { Self { id, value } } } 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: Object) -> Result<()> { db.del(bytes_of(&Key(self.id, (self.value)(val), id))) } fn compare(&self, before: Object, after: Object) -> bool { (self.value)(before) == (self.value)(after) } }