diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-02-08 01:18:59 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-02-08 01:18:59 +0100 |
| commit | 2ea9c54d755d808a8030602d667979e270381933 (patch) | |
| tree | 00deebad391259ff607042fbdb69e5743421684a /database/src/kv/mod.rs | |
| parent | e3d5e9d29a558173d5e6c499695480bed83008be (diff) | |
| download | jellything-2ea9c54d755d808a8030602d667979e270381933.tar jellything-2ea9c54d755d808a8030602d667979e270381933.tar.bz2 jellything-2ea9c54d755d808a8030602d667979e270381933.tar.zst | |
list index; generalize counters; count and none index
Diffstat (limited to 'database/src/kv/mod.rs')
| -rw-r--r-- | database/src/kv/mod.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/database/src/kv/mod.rs b/database/src/kv/mod.rs index ad1dcff..1a058a7 100644 --- a/database/src/kv/mod.rs +++ b/database/src/kv/mod.rs @@ -5,7 +5,6 @@ */ pub mod binning; -pub mod counters; pub mod helpers; pub mod index; pub mod index_key; @@ -18,6 +17,7 @@ use crate::{ Database, Query, RowIter, RowNum, Transaction, kv::{ helpers::{read_counter, write_counter}, + index::update_index, index_key::IndexKey, prefix_iterator::PrefixIterator, }, @@ -42,10 +42,10 @@ impl<T: jellykv::Store> Database for T { impl Transaction for &mut dyn jellykv::Transaction { fn insert(&mut self, entry: ObjectBuffer) -> Result<RowNum> { - let mut id_counter = read_counter(*self, T_ROW_COUNTER, 0)?; + let mut id_counter = read_counter(*self, &T_ROW_COUNTER.to_be_bytes(), 0)?; let row = id_counter; id_counter += 1; - write_counter(*self, T_ROW_COUNTER, id_counter)?; + write_counter(*self, &T_ROW_COUNTER.to_be_bytes(), id_counter)?; jellykv::Transaction::set( *self, @@ -55,13 +55,8 @@ impl Transaction for &mut dyn jellykv::Transaction { let ob = entry.as_object(); - let indices = PrefixIterator { - inner: jellykv::Transaction::iter(*self, &T_INDICES.to_be_bytes(), false)?, - prefix: Cow::Borrowed(&T_INDICES.to_be_bytes()), - }; - for i in indices { - let ik = IndexKey::from_bytes(&i?); - eprintln!("{ik:?}"); + for (is, ik) in list_indices(*self)? { + update_index(*self, is, ik, row, ob, false)?; } Ok(row) @@ -125,6 +120,21 @@ impl Transaction for &mut dyn jellykv::Transaction { } } +fn list_indices(txn: &dyn jellykv::Transaction) -> Result<Vec<(SubtreeNum, IndexKey)>> { + let indices = PrefixIterator { + inner: jellykv::Transaction::iter(txn, &T_INDICES.to_be_bytes(), false)?, + prefix: Cow::Borrowed(&T_INDICES.to_be_bytes()), + }; + let mut out = Vec::new(); + for i in indices { + let i = i?; + let ik = IndexKey::from_bytes(&i); + let is = read_counter(txn, &i, 0)? as SubtreeNum; + out.push((is, ik)); + } + Ok(out) +} + fn row_key(row: RowNum) -> Vec<u8> { let mut key = Vec::new(); key.extend(T_ROWS.to_be_bytes()); |