Skip to content

Commit

Permalink
Forward additional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Aug 23, 2023
1 parent af90158 commit f635768
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 41 deletions.
127 changes: 101 additions & 26 deletions src/btreemap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use derive_more::Debug;
use std::borrow::Borrow;
use std::collections::btree_map::*;
use std::ops::RangeBounds;
use std::collections::BTreeMap;
use std::iter::{FromIterator, IntoIterator};
use std::ops::{Index, IndexMut};
Expand Down Expand Up @@ -183,44 +184,50 @@ impl<K: Eq + Ord, V> IndexMut<K> for DefaultBTreeMap<K, V> {
/// the usage of these methods.
impl<K: Eq + Ord, V> DefaultBTreeMap<K, V> {
#[inline]
pub fn keys(&self) -> Keys<K, V> {
self.map.keys()
}
#[inline]
pub fn values(&self) -> Values<K, V> {
self.map.values()
}
#[inline]
pub fn values_mut(&mut self) -> ValuesMut<K, V> {
self.map.values_mut()
}
#[inline]
pub fn iter(&self) -> Iter<K, V> {
self.map.iter()
pub fn clear(&mut self) {
self.map.clear()
}
#[inline]
pub fn iter_mut(&mut self) -> IterMut<K, V> {
self.map.iter_mut()
pub fn first_key_value(&self) -> Option<(&K, &V)>
where
K: Ord,
{
self.map.first_key_value()
}
#[inline]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
self.map.entry(key)
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
where
K: Ord,
{
self.map.first_entry()
}
#[inline]
pub fn len(&self) -> usize {
self.map.len()
pub fn pop_first(&mut self) -> Option<(K, V)>
where
K: Ord,
{
self.map.pop_first()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.map.is_empty()
pub fn last_key_value(&self) -> Option<(&K, &V)>
where
K: Ord,
{
self.map.last_key_value()
}
#[inline]
pub fn clear(&mut self) {
self.map.clear()
pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
where
K: Ord,
{
self.map.last_entry()
}
#[inline]
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
self.map.insert(k, v)
pub fn pop_last(&mut self) -> Option<(K, V)>
where
K: Ord,
{
self.map.pop_last()
}
#[inline]
pub fn contains_key<Q>(&self, k: &Q) -> bool
Expand All @@ -231,6 +238,10 @@ impl<K: Eq + Ord, V> DefaultBTreeMap<K, V> {
self.map.contains_key(k)
}
#[inline]
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
self.map.insert(k, v)
}
#[inline]
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where
K: Borrow<Q>,
Expand All @@ -245,6 +256,70 @@ impl<K: Eq + Ord, V> DefaultBTreeMap<K, V> {
{
self.map.retain(f)
}
#[inline]
pub fn append(&mut self, other: &mut Self)
{
self.map.append(&mut other.map)
}
#[inline]
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>
where
T: Ord,
K: Borrow<T> + Ord,
R: RangeBounds<T>,
{
self.map.range(range)
}
#[inline]
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>
where
T: Ord,
K: Borrow<T> + Ord,
R: RangeBounds<T>,
{
self.map.range_mut(range)
}
#[inline]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
self.map.entry(key)
}
#[inline]
pub fn into_keys(self) -> IntoKeys<K, V> {
self.map.into_keys()
}
#[inline]
pub fn into_values(self) -> IntoValues<K, V> {
self.map.into_values()
}

#[inline]
pub fn iter(&self) -> Iter<K, V> {
self.map.iter()
}
#[inline]
pub fn iter_mut(&mut self) -> IterMut<K, V> {
self.map.iter_mut()
}
#[inline]
pub fn keys(&self) -> Keys<K, V> {
self.map.keys()
}
#[inline]
pub fn values(&self) -> Values<K, V> {
self.map.values()
}
#[inline]
pub fn values_mut(&mut self) -> ValuesMut<K, V> {
self.map.values_mut()
}
#[inline]
pub fn len(&self) -> usize {
self.map.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.map.is_empty()
}
}

impl<K: Eq + Ord, V: Default> FromIterator<(K, V)> for DefaultBTreeMap<K, V> {
Expand Down
57 changes: 42 additions & 15 deletions src/hashmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use derive_more::Debug;
use std::borrow::Borrow;
use std::collections::hash_map::*;
use std::collections::TryReserveError;
use std::collections::HashMap;
use std::hash::Hash;
use std::iter::{FromIterator, IntoIterator};
Expand Down Expand Up @@ -187,18 +188,14 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
self.map.capacity()
}
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.map.reserve(additional)
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.map.shrink_to_fit()
}
#[inline]
pub fn keys(&self) -> Keys<K, V> {
self.map.keys()
}
#[inline]
pub fn into_keys(self) -> IntoKeys<K, V> {
self.map.into_keys()
}
#[inline]
pub fn values(&self) -> Values<K, V> {
self.map.values()
}
Expand All @@ -207,6 +204,10 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
self.map.values_mut()
}
#[inline]
pub fn into_values(self) -> IntoValues<K, V> {
self.map.into_values()
}
#[inline]
pub fn iter(&self) -> Iter<K, V> {
self.map.iter()
}
Expand All @@ -215,10 +216,6 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
self.map.iter_mut()
}
#[inline]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
self.map.entry(key)
}
#[inline]
pub fn len(&self) -> usize {
self.map.len()
}
Expand All @@ -231,9 +228,37 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
self.map.drain()
}
#[inline]
pub fn retain<RF>(&mut self, f: RF)
where
RF: FnMut(&K, &mut V) -> bool,
{
self.map.retain(f)
}
#[inline]
pub fn clear(&mut self) {
self.map.clear()
}
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.map.reserve(additional)
}
#[inline]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
self.map.try_reserve(additional)
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.map.shrink_to_fit()
}
#[inline]
pub fn shrink_to(&mut self, min_capacity: usize) {
self.map.shrink_to(min_capacity);
}
#[inline]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
self.map.entry(key)
}

#[inline]
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
self.map.insert(k, v)
Expand All @@ -255,12 +280,14 @@ impl<K: Eq + Hash, V> DefaultHashMap<K, V> {
self.map.remove(k)
}
#[inline]
pub fn retain<RF>(&mut self, f: RF)
pub fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
where
RF: FnMut(&K, &mut V) -> bool,
K: Borrow<Q>,
Q: Hash + Eq,
{
self.map.retain(f)
self.map.remove_entry(k)
}

}

impl<K: Eq + Hash, V: Default> FromIterator<(K, V)> for DefaultHashMap<K, V> {
Expand Down

0 comments on commit f635768

Please sign in to comment.