From 207287ae9dc3d3b305e5b9bc09447ea15cae9160 Mon Sep 17 00:00:00 2001 From: Filippo Neysofu Costa Date: Wed, 14 Aug 2024 16:15:55 +0200 Subject: [PATCH] New method DeltaReader::get_smallest[_async] (#17) Signed-off-by: Filippo Costa --- src/cache/delta_reader.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cache/delta_reader.rs b/src/cache/delta_reader.rs index 1b7937a..7b5fbe3 100644 --- a/src/cache/delta_reader.rs +++ b/src/cache/delta_reader.rs @@ -56,6 +56,24 @@ impl DeltaReader { tokio::task::block_in_place(|| self.get(key)) } + /// Get the value of the smallest key written value for given [`Schema`]. + pub fn get_smallest(&self) -> anyhow::Result> { + let mut iterator = self.iter::()?; + if let Some((key, value)) = iterator.next() { + let key = S::Key::decode_key(&key)?; + let value = S::Value::decode_value(&value)?; + return Ok(Some((key, value))); + } + Ok(None) + } + + /// Async version of [`DeltaReader::get_smallest`]. + pub async fn get_smallest_async( + &self, + ) -> anyhow::Result> { + tokio::task::block_in_place(|| self.get_smallest::()) + } + /// Get a value of the largest key written value for given [`Schema`]. pub fn get_largest(&self) -> anyhow::Result> { let mut iterator = self.iter_rev::()?;