aboutsummaryrefslogtreecommitdiff
path: root/database/src/kv/index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'database/src/kv/index.rs')
-rw-r--r--database/src/kv/index.rs41
1 files changed, 30 insertions, 11 deletions
diff --git a/database/src/kv/index.rs b/database/src/kv/index.rs
index 522ae18..23b8349 100644
--- a/database/src/kv/index.rs
+++ b/database/src/kv/index.rs
@@ -4,17 +4,17 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use anyhow::Result;
-use jellyobject::Object;
-
use crate::{
- RowNum,
+ RowNum, Sort,
kv::{
SubtreeNum,
helpers::{read_counter, write_counter},
index_key::{IndexKey, SortKey},
+ prefix_iterator::PrefixIterator,
},
};
+use anyhow::Result;
+use jellyobject::Object;
pub fn update_index(
txn: &mut dyn jellykv::Transaction,
@@ -54,12 +54,31 @@ pub fn update_index(
Ok(())
}
-pub fn read_count_index(
- txn: &dyn jellykv::Transaction,
- is: SubtreeNum,
+pub fn read_count_index(txn: &dyn jellykv::Transaction, prefix: Vec<u8>) -> Result<u64> {
+ read_counter(txn, &prefix, 0)
+}
+
+pub fn iter_index<'a>(
+ txn: &'a dyn jellykv::Transaction,
prefix: Vec<u8>,
-) -> Result<u64> {
- let mut k = is.to_be_bytes().to_vec();
- k.extend(&prefix);
- read_counter(txn, &k, 0)
+ sort: &Sort,
+) -> Result<Box<dyn Iterator<Item = Result<(RowNum, Vec<u8>)>> + 'a>> {
+ Ok(match sort {
+ Sort::None => Box::new(
+ PrefixIterator {
+ inner: txn.iter(&prefix, false)?,
+ prefix: prefix.into(),
+ }
+ .map(|k| {
+ k.map(|k| {
+ (
+ RowNum::from_be_bytes(k[k.len() - 8..].try_into().unwrap()),
+ k[4..].to_vec(),
+ )
+ })
+ }),
+ ),
+ Sort::Value(value_sort) => todo!(),
+ Sort::TextSearch(path, _) => todo!(),
+ })
}