2024-12-02 08:51:59 +00:00
|
|
|
use std::{fmt::Debug, future::Future, sync::Arc};
|
2024-08-08 17:18:30 +00:00
|
|
|
|
|
|
|
|
use conduit::implement;
|
|
|
|
|
use futures::stream::StreamExt;
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
|
|
/// Count the total number of entries in the map.
|
|
|
|
|
#[implement(super::Map)]
|
|
|
|
|
#[inline]
|
2024-10-09 05:08:22 +00:00
|
|
|
pub fn count(&self) -> impl Future<Output = usize> + Send + '_ { self.raw_keys().count() }
|
2024-08-08 17:18:30 +00:00
|
|
|
|
|
|
|
|
/// Count the number of entries in the map starting from a lower-bound.
|
|
|
|
|
///
|
|
|
|
|
/// - From is a structured key
|
|
|
|
|
#[implement(super::Map)]
|
|
|
|
|
#[inline]
|
2024-12-02 08:51:59 +00:00
|
|
|
pub fn count_from<'a, P>(self: &'a Arc<Self>, from: &P) -> impl Future<Output = usize> + Send + 'a
|
2024-08-08 17:18:30 +00:00
|
|
|
where
|
|
|
|
|
P: Serialize + ?Sized + Debug + 'a,
|
|
|
|
|
{
|
2024-10-09 05:08:22 +00:00
|
|
|
self.keys_from_raw(from).count()
|
2024-08-08 17:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-29 03:10:18 +00:00
|
|
|
/// Count the number of entries in the map starting from a lower-bound.
|
|
|
|
|
///
|
|
|
|
|
/// - From is a raw
|
|
|
|
|
#[implement(super::Map)]
|
|
|
|
|
#[inline]
|
2024-12-02 08:51:59 +00:00
|
|
|
pub fn raw_count_from<'a, P>(self: &'a Arc<Self>, from: &'a P) -> impl Future<Output = usize> + Send + 'a
|
2024-10-29 03:10:18 +00:00
|
|
|
where
|
|
|
|
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
|
|
|
|
{
|
|
|
|
|
self.raw_keys_from(from).count()
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
/// Count the number of entries in the map matching a prefix.
|
|
|
|
|
///
|
|
|
|
|
/// - Prefix is structured key
|
|
|
|
|
#[implement(super::Map)]
|
|
|
|
|
#[inline]
|
2024-12-02 08:51:59 +00:00
|
|
|
pub fn count_prefix<'a, P>(self: &'a Arc<Self>, prefix: &P) -> impl Future<Output = usize> + Send + 'a
|
2024-08-08 17:18:30 +00:00
|
|
|
where
|
|
|
|
|
P: Serialize + ?Sized + Debug + 'a,
|
|
|
|
|
{
|
2024-10-09 05:08:22 +00:00
|
|
|
self.keys_prefix_raw(prefix).count()
|
2024-08-08 17:18:30 +00:00
|
|
|
}
|
2024-10-29 03:10:18 +00:00
|
|
|
|
|
|
|
|
/// Count the number of entries in the map matching a prefix.
|
|
|
|
|
///
|
|
|
|
|
/// - Prefix is raw
|
|
|
|
|
#[implement(super::Map)]
|
|
|
|
|
#[inline]
|
2024-12-02 08:51:59 +00:00
|
|
|
pub fn raw_count_prefix<'a, P>(self: &'a Arc<Self>, prefix: &'a P) -> impl Future<Output = usize> + Send + 'a
|
2024-10-29 03:10:18 +00:00
|
|
|
where
|
|
|
|
|
P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a,
|
|
|
|
|
{
|
|
|
|
|
self.raw_keys_prefix(prefix).count()
|
|
|
|
|
}
|