Skip to content

Commit

Permalink
New method DeltaReader::get_smallest[_async] (#17)
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Costa <[email protected]>
  • Loading branch information
neysofu authored Aug 14, 2024
1 parent d640252 commit 207287a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/cache/delta_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Schema>(&self) -> anyhow::Result<Option<(S::Key, S::Value)>> {
let mut iterator = self.iter::<S>()?;
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<S: Schema>(
&self,
) -> anyhow::Result<Option<(S::Key, S::Value)>> {
tokio::task::block_in_place(|| self.get_smallest::<S>())
}

/// Get a value of the largest key written value for given [`Schema`].
pub fn get_largest<S: Schema>(&self) -> anyhow::Result<Option<(S::Key, S::Value)>> {
let mut iterator = self.iter_rev::<S>()?;
Expand Down

0 comments on commit 207287a

Please sign in to comment.