use alloc::collections::{BTreeMap, BTreeSet, btree_map};
use super::{Collection, CollectionBase, CollectionEntry, CollectionMap, CollectionSet, MapEntry};
impl<T: Ord> CollectionBase for BTreeSet<T> {
type Item = T;
fn item_count(&self) -> usize {
BTreeSet::len(self)
}
fn push(&mut self, elem: Self::Item) {
BTreeSet::insert(self, elem);
}
fn clear(&mut self) {
BTreeSet::clear(self)
}
}
impl<T: Ord> Collection for BTreeSet<T> {
fn with_capacity(_capacity: usize) -> Self {
BTreeSet::new()
}
}
impl<T: Ord> CollectionSet for BTreeSet<T> {
fn contains(&self, item: &Self::Item) -> bool {
BTreeSet::contains(self, item)
}
fn get(&self, item: &Self::Item) -> Option<&Self::Item> {
BTreeSet::get(self, item)
}
fn iter(&self) -> impl Iterator<Item = &Self::Item> {
BTreeSet::iter(self)
}
fn insert(&mut self, item: Self::Item) -> bool {
BTreeSet::insert(self, item)
}
fn replace(&mut self, item: Self::Item) -> Option<Self::Item> {
BTreeSet::replace(self, item)
}
fn remove(&mut self, item: &Self::Item) -> bool {
BTreeSet::remove(self, item)
}
fn take(&mut self, item: &Self::Item) -> Option<Self::Item> {
BTreeSet::take(self, item)
}
fn retain(&mut self, f: impl FnMut(&Self::Item) -> bool) {
BTreeSet::retain(self, f)
}
}
impl<K: Ord, V> CollectionBase for BTreeMap<K, V> {
type Item = (K, V);
fn item_count(&self) -> usize {
BTreeMap::len(self)
}
fn push(&mut self, elem: Self::Item) {
BTreeMap::insert(self, elem.0, elem.1);
}
fn clear(&mut self) {
BTreeMap::clear(self)
}
}
impl<K: Ord, V> Collection for BTreeMap<K, V> {
fn with_capacity(_capacity: usize) -> Self {
BTreeMap::new()
}
}
impl<K: Ord, V> CollectionMap for BTreeMap<K, V> {
type Key = K;
type Value = V;
fn contains_key(&self, key: &Self::Key) -> bool {
BTreeMap::contains_key(self, key)
}
fn get(&self, key: &Self::Key) -> Option<&Self::Value> {
BTreeMap::get(self, key)
}
fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value> {
BTreeMap::get_mut(self, key)
}
fn iter(&self) -> impl Iterator<Item = (&Self::Key, &Self::Value)> {
BTreeMap::iter(self)
}
fn keys(&self) -> impl Iterator<Item = &Self::Key> {
BTreeMap::keys(self)
}
fn values(&self) -> impl Iterator<Item = &Self::Value> {
BTreeMap::values(self)
}
fn iter_mut(&mut self) -> impl Iterator<Item = (&Self::Key, &mut Self::Value)> {
BTreeMap::iter_mut(self)
}
fn values_mut(&mut self) -> impl Iterator<Item = &mut Self::Value> {
BTreeMap::values_mut(self)
}
fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value> {
BTreeMap::insert(self, key, value)
}
fn remove(&mut self, key: &Self::Key) -> Option<Self::Value> {
BTreeMap::remove(self, key)
}
fn retain(&mut self, f: impl FnMut(&K, &mut V) -> bool) {
BTreeMap::retain(self, f)
}
}
impl<K: Ord, V> CollectionEntry for BTreeMap<K, V> {
type Entry<'a>
= btree_map::Entry<'a, K, V>
where
K: 'a,
V: 'a;
fn entry(&mut self, key: Self::Key) -> Self::Entry<'_> {
BTreeMap::entry(self, key)
}
}
impl<'a, K: Ord + 'a, V: 'a> MapEntry<'a> for btree_map::Entry<'a, K, V> {
type Key = K;
type Value = V;
fn key(&self) -> &Self::Key {
btree_map::Entry::key(self)
}
fn or_insert(self, default: Self::Value) -> &'a mut Self::Value {
btree_map::Entry::or_insert(self, default)
}
fn or_insert_with<F: FnOnce() -> Self::Value>(self, default: F) -> &'a mut Self::Value {
btree_map::Entry::or_insert_with(self, default)
}
fn or_default(self) -> &'a mut Self::Value
where
Self::Value: Default,
{
btree_map::Entry::or_default(self)
}
fn and_modify<F: FnOnce(&mut Self::Value)>(self, f: F) -> Self {
btree_map::Entry::and_modify(self, f)
}
}