Skip to content

Commit

Permalink
Fix clippy::multiple_bound_locations
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Mar 22, 2024
1 parent 0060546 commit b76ff73
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 73 deletions.
60 changes: 30 additions & 30 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ where
/// Return `true` if an equivalent to `key` exists in the map.
///
/// Computes in **O(1)** time (average).
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
self.get_index_of(key).is_some()
}
Expand All @@ -545,9 +545,9 @@ where
/// else `None`.
///
/// Computes in **O(1)** time (average).
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &self.as_entries()[i];
Expand All @@ -561,9 +561,9 @@ where
/// if it is present, else `None`.
///
/// Computes in **O(1)** time (average).
pub fn get_key_value<Q: ?Sized>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &self.as_entries()[i];
Expand All @@ -574,9 +574,9 @@ where
}

/// Return item index, key and value
pub fn get_full<Q: ?Sized>(&self, key: &Q) -> Option<(usize, &K, &V)>
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &self.as_entries()[i];
Expand All @@ -589,9 +589,9 @@ where
/// Return item index, if it exists in the map
///
/// Computes in **O(1)** time (average).
pub fn get_index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize>
pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
match self.as_entries() {
[] => None,
Expand All @@ -603,9 +603,9 @@ where
}
}

pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &mut self.as_entries_mut()[i];
Expand All @@ -615,9 +615,9 @@ where
}
}

pub fn get_full_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<(usize, &K, &mut V)>
pub fn get_full_mut<Q>(&mut self, key: &Q) -> Option<(usize, &K, &mut V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &mut self.as_entries_mut()[i];
Expand All @@ -636,9 +636,9 @@ where
/// [`.shift_remove(key)`][Self::shift_remove] instead.
#[deprecated(note = "`remove` disrupts the map order -- \
use `swap_remove` or `shift_remove` for explicit behavior.")]
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
self.swap_remove(key)
}
Expand All @@ -651,9 +651,9 @@ where
/// use [`.shift_remove_entry(key)`][Self::shift_remove_entry] instead.
#[deprecated(note = "`remove_entry` disrupts the map order -- \
use `swap_remove_entry` or `shift_remove_entry` for explicit behavior.")]
pub fn remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
self.swap_remove_entry(key)
}
Expand All @@ -668,9 +668,9 @@ where
/// Return `None` if `key` is not in map.
///
/// Computes in **O(1)** time (average).
pub fn swap_remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<V>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
self.swap_remove_full(key).map(third)
}
Expand All @@ -684,9 +684,9 @@ where
/// Return `None` if `key` is not in map.
///
/// Computes in **O(1)** time (average).
pub fn swap_remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>
pub fn swap_remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
match self.swap_remove_full(key) {
Some((_, key, value)) => Some((key, value)),
Expand All @@ -704,9 +704,9 @@ where
/// Return `None` if `key` is not in map.
///
/// Computes in **O(1)** time (average).
pub fn swap_remove_full<Q: ?Sized>(&mut self, key: &Q) -> Option<(usize, K, V)>
pub fn swap_remove_full<Q>(&mut self, key: &Q) -> Option<(usize, K, V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
match self.as_entries() {
[x] if key.equivalent(&x.key) => {
Expand All @@ -731,9 +731,9 @@ where
/// Return `None` if `key` is not in map.
///
/// Computes in **O(n)** time (average).
pub fn shift_remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
pub fn shift_remove<Q>(&mut self, key: &Q) -> Option<V>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
self.shift_remove_full(key).map(third)
}
Expand All @@ -747,9 +747,9 @@ where
/// Return `None` if `key` is not in map.
///
/// Computes in **O(n)** time (average).
pub fn shift_remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>
pub fn shift_remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
match self.shift_remove_full(key) {
Some((_, key, value)) => Some((key, value)),
Expand All @@ -767,9 +767,9 @@ where
/// Return `None` if `key` is not in map.
///
/// Computes in **O(n)** time (average).
pub fn shift_remove_full<Q: ?Sized>(&mut self, key: &Q) -> Option<(usize, K, V)>
pub fn shift_remove_full<Q>(&mut self, key: &Q) -> Option<(usize, K, V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
match self.as_entries() {
[x] if key.equivalent(&x.key) => {
Expand Down
16 changes: 8 additions & 8 deletions src/map/core/raw_entry_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ impl<K, V, S> fmt::Debug for RawEntryBuilder<'_, K, V, S> {

impl<'a, K, V, S> RawEntryBuilder<'a, K, V, S> {
/// Access an entry by key.
pub fn from_key<Q: ?Sized>(self, key: &Q) -> Option<(&'a K, &'a V)>
pub fn from_key<Q>(self, key: &Q) -> Option<(&'a K, &'a V)>
where
S: BuildHasher,
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
self.map.get_key_value(key)
}

/// Access an entry by a key and its hash.
pub fn from_key_hashed_nocheck<Q: ?Sized>(self, hash: u64, key: &Q) -> Option<(&'a K, &'a V)>
pub fn from_key_hashed_nocheck<Q>(self, hash: u64, key: &Q) -> Option<(&'a K, &'a V)>
where
Q: Equivalent<K>,
Q: ?Sized + Equivalent<K>,
{
let hash = HashValue(hash as usize);
let i = self.map.core.get_index_of(hash, key)?;
Expand Down Expand Up @@ -265,19 +265,19 @@ impl<K, V, S> fmt::Debug for RawEntryBuilderMut<'_, K, V, S> {

impl<'a, K, V, S> RawEntryBuilderMut<'a, K, V, S> {
/// Access an entry by key.
pub fn from_key<Q: ?Sized>(self, key: &Q) -> RawEntryMut<'a, K, V, S>
pub fn from_key<Q>(self, key: &Q) -> RawEntryMut<'a, K, V, S>
where
S: BuildHasher,
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
let hash = self.map.hash(key);
self.from_key_hashed_nocheck(hash.get(), key)
}

/// Access an entry by a key and its hash.
pub fn from_key_hashed_nocheck<Q: ?Sized>(self, hash: u64, key: &Q) -> RawEntryMut<'a, K, V, S>
pub fn from_key_hashed_nocheck<Q>(self, hash: u64, key: &Q) -> RawEntryMut<'a, K, V, S>
where
Q: Equivalent<K>,
Q: ?Sized + Equivalent<K>,
{
self.from_hash(hash, |k| Q::equivalent(key, k))
}
Expand Down
11 changes: 4 additions & 7 deletions src/map/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ pub trait MutableKeys: private::Sealed {
/// Return item index, mutable reference to key and value
///
/// Computes in **O(1)** time (average).
fn get_full_mut2<Q: ?Sized>(
&mut self,
key: &Q,
) -> Option<(usize, &mut Self::Key, &mut Self::Value)>
fn get_full_mut2<Q>(&mut self, key: &Q) -> Option<(usize, &mut Self::Key, &mut Self::Value)>
where
Q: Hash + Equivalent<Self::Key>;
Q: ?Sized + Hash + Equivalent<Self::Key>;

/// Return mutable reference to key and value at an index.
///
Expand Down Expand Up @@ -59,9 +56,9 @@ where
type Key = K;
type Value = V;

fn get_full_mut2<Q: ?Sized>(&mut self, key: &Q) -> Option<(usize, &mut K, &mut V)>
fn get_full_mut2<Q>(&mut self, key: &Q) -> Option<(usize, &mut K, &mut V)>
where
Q: Hash + Equivalent<K>,
Q: ?Sized + Hash + Equivalent<K>,
{
if let Some(i) = self.get_index_of(key) {
let entry = &mut self.as_entries_mut()[i];
Expand Down
48 changes: 24 additions & 24 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ where
/// Return `true` if an equivalent to `value` exists in the set.
///
/// Computes in **O(1)** time (average).
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
pub fn contains<Q>(&self, value: &Q) -> bool
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.contains_key(value)
}
Expand All @@ -521,27 +521,27 @@ where
/// else `None`.
///
/// Computes in **O(1)** time (average).
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
pub fn get<Q>(&self, value: &Q) -> Option<&T>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.get_key_value(value).map(|(x, &())| x)
}

/// Return item index and value
pub fn get_full<Q: ?Sized>(&self, value: &Q) -> Option<(usize, &T)>
pub fn get_full<Q>(&self, value: &Q) -> Option<(usize, &T)>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.get_full(value).map(|(i, x, &())| (i, x))
}

/// Return item index, if it exists in the set
///
/// Computes in **O(1)** time (average).
pub fn get_index_of<Q: ?Sized>(&self, value: &Q) -> Option<usize>
pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.get_index_of(value)
}
Expand All @@ -554,9 +554,9 @@ where
/// [`.shift_remove(value)`][Self::shift_remove] instead.
#[deprecated(note = "`remove` disrupts the set order -- \
use `swap_remove` or `shift_remove` for explicit behavior.")]
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
pub fn remove<Q>(&mut self, value: &Q) -> bool
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.swap_remove(value)
}
Expand All @@ -570,9 +570,9 @@ where
/// Return `false` if `value` was not in the set.
///
/// Computes in **O(1)** time (average).
pub fn swap_remove<Q: ?Sized>(&mut self, value: &Q) -> bool
pub fn swap_remove<Q>(&mut self, value: &Q) -> bool
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.swap_remove(value).is_some()
}
Expand All @@ -586,9 +586,9 @@ where
/// Return `false` if `value` was not in the set.
///
/// Computes in **O(n)** time (average).
pub fn shift_remove<Q: ?Sized>(&mut self, value: &Q) -> bool
pub fn shift_remove<Q>(&mut self, value: &Q) -> bool
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.shift_remove(value).is_some()
}
Expand All @@ -602,9 +602,9 @@ where
/// [`.shift_take(value)`][Self::shift_take] instead.
#[deprecated(note = "`take` disrupts the set order -- \
use `swap_take` or `shift_take` for explicit behavior.")]
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
pub fn take<Q>(&mut self, value: &Q) -> Option<T>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.swap_take(value)
}
Expand All @@ -619,9 +619,9 @@ where
/// Return `None` if `value` was not in the set.
///
/// Computes in **O(1)** time (average).
pub fn swap_take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
pub fn swap_take<Q>(&mut self, value: &Q) -> Option<T>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.swap_remove_entry(value).map(|(x, ())| x)
}
Expand All @@ -636,9 +636,9 @@ where
/// Return `None` if `value` was not in the set.
///
/// Computes in **O(n)** time (average).
pub fn shift_take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
pub fn shift_take<Q>(&mut self, value: &Q) -> Option<T>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.shift_remove_entry(value).map(|(x, ())| x)
}
Expand All @@ -650,9 +650,9 @@ where
/// the position of what used to be the last element!**
///
/// Return `None` if `value` was not in the set.
pub fn swap_remove_full<Q: ?Sized>(&mut self, value: &Q) -> Option<(usize, T)>
pub fn swap_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.swap_remove_full(value).map(|(i, x, ())| (i, x))
}
Expand All @@ -664,9 +664,9 @@ where
/// **This perturbs the index of all of those elements!**
///
/// Return `None` if `value` was not in the set.
pub fn shift_remove_full<Q: ?Sized>(&mut self, value: &Q) -> Option<(usize, T)>
pub fn shift_remove_full<Q>(&mut self, value: &Q) -> Option<(usize, T)>
where
Q: Hash + Equivalent<T>,
Q: ?Sized + Hash + Equivalent<T>,
{
self.map.shift_remove_full(value).map(|(i, x, ())| (i, x))
}
Expand Down
Loading

0 comments on commit b76ff73

Please sign in to comment.