use std::collections::btree_map::{self, BTreeMap};
use std::collections::hash_map::{self, HashMap};
use std::hash::BuildHasher;
use std::ops::RangeBounds;
use crate::store::item::{Key, Value};
use crate::store::{
StoreIterable, StoreIterableMut, StoreKeys, StoreRange, StoreValues,
};
impl<K, V, S> StoreIterable<K, V> for HashMap<K, V, S>
where
K: Key,
V: Value,
S: BuildHasher,
{
type Iter<'a> = hash_map::Iter<'a, K, V>
where
Self: 'a;
#[inline]
fn iter(&self) -> Self::Iter<'_> {
HashMap::iter(self)
}
}
impl<K, V, S> StoreIterableMut<K, V> for HashMap<K, V, S>
where
K: Key,
V: Value,
S: BuildHasher,
{
type IterMut<'a> = hash_map::IterMut<'a, K, V>
where
Self: 'a;
#[inline]
fn iter_mut(&mut self) -> Self::IterMut<'_> {
HashMap::iter_mut(self)
}
}
impl<K, V, S> StoreKeys<K, V> for HashMap<K, V, S>
where
K: Key,
S: BuildHasher,
{
type Keys<'a> = hash_map::Keys<'a, K, V>
where
Self: 'a;
#[inline]
fn keys(&self) -> Self::Keys<'_> {
HashMap::keys(self)
}
}
impl<K, V, S> StoreValues<K, V> for HashMap<K, V, S>
where
K: Key,
V: Value,
S: BuildHasher,
{
type Values<'a> = hash_map::Values<'a, K, V>
where
Self: 'a;
#[inline]
fn values(&self) -> Self::Values<'_> {
HashMap::values(self)
}
}
impl<K, V> StoreIterable<K, V> for BTreeMap<K, V>
where
K: Key,
V: Value,
{
type Iter<'a> = btree_map::Iter<'a, K, V>
where
Self: 'a;
#[inline]
fn iter(&self) -> Self::Iter<'_> {
BTreeMap::iter(self)
}
}
impl<K, V> StoreIterableMut<K, V> for BTreeMap<K, V>
where
K: Key,
V: Value,
{
type IterMut<'a> = btree_map::IterMut<'a, K, V>
where
Self: 'a;
#[inline]
fn iter_mut(&mut self) -> Self::IterMut<'_> {
BTreeMap::iter_mut(self)
}
}
impl<K, V> StoreKeys<K, V> for BTreeMap<K, V>
where
K: Key,
{
type Keys<'a> = btree_map::Keys<'a, K, V>
where
Self: 'a;
#[inline]
fn keys(&self) -> Self::Keys<'_> {
BTreeMap::keys(self)
}
}
impl<K, V> StoreValues<K, V> for BTreeMap<K, V>
where
K: Key,
V: Value,
{
type Values<'a> = btree_map::Values<'a, K, V>
where
Self: 'a;
#[inline]
fn values(&self) -> Self::Values<'_> {
BTreeMap::values(self)
}
}
impl<K, V> StoreRange<K, V> for BTreeMap<K, V>
where
K: Key,
V: Value,
{
type Range<'a> = btree_map::Range<'a, K, V>
where
Self: 'a;
#[inline]
fn range<R>(&self, range: R) -> Self::Range<'_>
where
R: RangeBounds<K>,
{
BTreeMap::range(self, range)
}
}