use crate::generic_containers::*;
use core::borrow::Borrow;
use core::ops::{Index, IndexMut};
pub trait CopyMap<K, V>: Container
where
K: Copy + Eq,
{
fn get(&self, key: K) -> Option<&V>;
fn get_mut(&mut self, key: K) -> Option<&mut V>;
fn insert(&mut self, k: K, v: V) -> Option<V>;
}
pub trait Map<K, V>: Container
where
K: Eq,
{
fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Eq;
fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Eq;
fn insert(&mut self, k: K, v: V) -> Option<V>;
}
pub trait CopyDictionary<K, V>: CopyMap<K, V> + DynamicContainer
where
K: Copy + Eq,
{
fn contains(&self, key: K) -> bool {
match self.get(key) {
Some(_) => true,
None => false,
}
}
fn remove(&mut self, k: K) -> Option<V>;
}
pub trait Dictionary<K, V>: Map<K, V> + DynamicContainer
where
K: Eq,
{
fn contains<Q: ?Sized>(&self, key: &Q) -> bool
where
K: Borrow<Q>,
Q: Eq,
{
match self.get(key) {
Some(_) => true,
None => false,
}
}
fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
where
K: Borrow<Q>,
Q: Eq;
}
pub trait Array<V>:
CopyMap<usize, V> + Index<usize, Output = V> + IndexMut<usize, Output = V>
{
}
pub trait DynamicArray<V>:
CopyMap<usize, V> + DynamicContainer + Index<usize, Output = V> + IndexMut<usize, Output = V>
{
}