From ed76797b55c8f32e11fcb0a3b8d0d29a4b93b6b8 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 29 Oct 2024 03:10:18 +0000 Subject: [PATCH] add raw_ overloads for prefix/from counting Signed-off-by: Jason Volk --- src/database/database.rs | 3 +++ src/database/map/count.rs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/database/database.rs b/src/database/database.rs index 099df87d..bf8c8855 100644 --- a/src/database/database.rs +++ b/src/database/database.rs @@ -33,6 +33,9 @@ impl Database { #[inline] pub fn iter(&self) -> impl Iterator + Send + '_ { self.maps.iter() } + #[inline] + pub fn keys(&self) -> impl Iterator + Send + '_ { self.maps.keys() } + #[inline] #[must_use] pub fn is_read_only(&self) -> bool { self.db.secondary || self.db.read_only } diff --git a/src/database/map/count.rs b/src/database/map/count.rs index dab45b7a..3e92279c 100644 --- a/src/database/map/count.rs +++ b/src/database/map/count.rs @@ -21,6 +21,18 @@ where self.keys_from_raw(from).count() } +/// Count the number of entries in the map starting from a lower-bound. +/// +/// - From is a raw +#[implement(super::Map)] +#[inline] +pub fn raw_count_from<'a, P>(&'a self, from: &'a P) -> impl Future + Send + 'a +where + P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, +{ + self.raw_keys_from(from).count() +} + /// Count the number of entries in the map matching a prefix. /// /// - Prefix is structured key @@ -32,3 +44,15 @@ where { self.keys_prefix_raw(prefix).count() } + +/// Count the number of entries in the map matching a prefix. +/// +/// - Prefix is raw +#[implement(super::Map)] +#[inline] +pub fn raw_count_prefix<'a, P>(&'a self, prefix: &'a P) -> impl Future + Send + 'a +where + P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, +{ + self.raw_keys_prefix(prefix).count() +}