diff options
Diffstat (limited to 'database/src/kv')
| -rw-r--r-- | database/src/kv/index_key.rs | 48 | ||||
| -rw-r--r-- | database/src/kv/mod.rs | 13 |
2 files changed, 60 insertions, 1 deletions
diff --git a/database/src/kv/index_key.rs b/database/src/kv/index_key.rs index eab46c4..fae7d4a 100644 --- a/database/src/kv/index_key.rs +++ b/database/src/kv/index_key.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + /* 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. @@ -128,6 +130,52 @@ impl SortKey { } } +impl Display for IndexKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} | {}", self.0, self.1) + } +} +impl Display for Binning { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for (i, b) in self.0.iter().enumerate() { + if i > 0 { + write!(f, " ")?; + } + write!(f, "{b}")?; + } + Ok(()) + } +} +impl Display for BinningComponent { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + BinningComponent::Has(path) => write!(f, "H({path})"), + BinningComponent::Match(path) => write!(f, "M({path})"), + } + } +} +impl Display for SortKey { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SortKey::None => write!(f, "none"), + SortKey::Count => write!(f, "count"), + SortKey::Value(path, multi) => write!(f, "value({path}, {multi})"), + SortKey::Text(path) => write!(f, "text({path})"), + } + } +} +impl Display for MultiBehaviour { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + MultiBehaviour::First => "first", + MultiBehaviour::ForEach => "for_each", + MultiBehaviour::Max => "max", + MultiBehaviour::Min => "min", + MultiBehaviour::Count => "count", + }) + } +} + fn write_path(path: &Path, out: &mut Vec<u8>) { assert!(path.0.len() < 256); out.push(path.0.len() as u8); diff --git a/database/src/kv/mod.rs b/database/src/kv/mod.rs index f90f07e..257eec4 100644 --- a/database/src/kv/mod.rs +++ b/database/src/kv/mod.rs @@ -27,7 +27,7 @@ use crate::{ use anyhow::{Result, anyhow}; use jellyobject::ObjectBuffer; use log::{debug, info}; -use std::borrow::Cow; +use std::{borrow::Cow, fmt::Write}; pub type SubtreeNum = u32; @@ -132,6 +132,17 @@ impl Transaction for &mut dyn jellykv::Transaction { } Ok(total) } + + fn debug_info(&self) -> Result<String> { + let mut o = String::new(); + let rc = read_counter(*self, &T_ROW_COUNTER.to_be_bytes(), 0)?; + writeln!(o, "Row Counter: {rc}")?; + writeln!(o, "Indices:")?; + for (is, ik) in list_indices(*self)? { + writeln!(o, "\tIS={is} IK={ik}")?; + } + Ok(o) + } } fn get_or_create_index(txn: &mut dyn jellykv::Transaction, ik: &IndexKey) -> Result<SubtreeNum> { |