mirror of
https://github.com/servo/servo.git
synced 2025-07-17 20:33:40 +01:00
Format hashglobe #21373
This commit is contained in:
parent
2c9e32a09e
commit
951bda3600
7 changed files with 552 additions and 434 deletions
|
@ -122,8 +122,9 @@ pub struct HashSet<T, S = RandomState> {
|
|||
}
|
||||
|
||||
impl<T, S> HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
/// Creates a new empty hash set which will use the given hasher to hash
|
||||
/// keys.
|
||||
|
@ -147,7 +148,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn with_hasher(hasher: S) -> HashSet<T, S> {
|
||||
HashSet { map: HashMap::with_hasher(hasher) }
|
||||
HashSet {
|
||||
map: HashMap::with_hasher(hasher),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates an empty `HashSet` with with the specified capacity, using
|
||||
|
@ -173,7 +176,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashSet<T, S> {
|
||||
HashSet { map: HashMap::with_capacity_and_hasher(capacity, hasher) }
|
||||
HashSet {
|
||||
map: HashMap::with_capacity_and_hasher(capacity, hasher),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a reference to the set's [`BuildHasher`].
|
||||
|
@ -265,7 +270,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// }
|
||||
/// ```
|
||||
pub fn iter(&self) -> Iter<T> {
|
||||
Iter { iter: self.map.keys() }
|
||||
Iter {
|
||||
iter: self.map.keys(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Visits the values representing the difference,
|
||||
|
@ -319,10 +326,13 @@ impl<T, S> HashSet<T, S>
|
|||
/// assert_eq!(diff1, diff2);
|
||||
/// assert_eq!(diff1, [1, 4].iter().collect());
|
||||
/// ```
|
||||
pub fn symmetric_difference<'a>(&'a self,
|
||||
other: &'a HashSet<T, S>)
|
||||
-> SymmetricDifference<'a, T, S> {
|
||||
SymmetricDifference { iter: self.difference(other).chain(other.difference(self)) }
|
||||
pub fn symmetric_difference<'a>(
|
||||
&'a self,
|
||||
other: &'a HashSet<T, S>,
|
||||
) -> SymmetricDifference<'a, T, S> {
|
||||
SymmetricDifference {
|
||||
iter: self.difference(other).chain(other.difference(self)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Visits the values representing the intersection,
|
||||
|
@ -369,7 +379,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// assert_eq!(union, [1, 2, 3, 4].iter().collect());
|
||||
/// ```
|
||||
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
|
||||
Union { iter: self.iter().chain(other.difference(self)) }
|
||||
Union {
|
||||
iter: self.iter().chain(other.difference(self)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of elements in the set.
|
||||
|
@ -423,7 +435,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn drain(&mut self) -> Drain<T> {
|
||||
Drain { iter: self.map.drain() }
|
||||
Drain {
|
||||
iter: self.map.drain(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the set, removing all values.
|
||||
|
@ -438,7 +452,10 @@ impl<T, S> HashSet<T, S>
|
|||
/// v.clear();
|
||||
/// assert!(v.is_empty());
|
||||
/// ```
|
||||
pub fn clear(&mut self) where T: 'static {
|
||||
pub fn clear(&mut self)
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
self.map.clear()
|
||||
}
|
||||
|
||||
|
@ -461,8 +478,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// [`Eq`]: ../../std/cmp/trait.Eq.html
|
||||
/// [`Hash`]: ../../std/hash/trait.Hash.html
|
||||
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
|
||||
where T: Borrow<Q>,
|
||||
Q: Hash + Eq
|
||||
where
|
||||
T: Borrow<Q>,
|
||||
Q: Hash + Eq,
|
||||
{
|
||||
self.map.contains_key(value)
|
||||
}
|
||||
|
@ -476,8 +494,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// [`Eq`]: ../../std/cmp/trait.Eq.html
|
||||
/// [`Hash`]: ../../std/hash/trait.Hash.html
|
||||
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
|
||||
where T: Borrow<Q>,
|
||||
Q: Hash + Eq
|
||||
where
|
||||
T: Borrow<Q>,
|
||||
Q: Hash + Eq,
|
||||
{
|
||||
Recover::get(&self.map, value)
|
||||
}
|
||||
|
@ -598,8 +617,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// [`Eq`]: ../../std/cmp/trait.Eq.html
|
||||
/// [`Hash`]: ../../std/hash/trait.Hash.html
|
||||
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
|
||||
where T: Borrow<Q>,
|
||||
Q: Hash + Eq
|
||||
where
|
||||
T: Borrow<Q>,
|
||||
Q: Hash + Eq,
|
||||
{
|
||||
self.map.remove(value).is_some()
|
||||
}
|
||||
|
@ -613,8 +633,9 @@ impl<T, S> HashSet<T, S>
|
|||
/// [`Eq`]: ../../std/cmp/trait.Eq.html
|
||||
/// [`Hash`]: ../../std/hash/trait.Hash.html
|
||||
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
|
||||
where T: Borrow<Q>,
|
||||
Q: Hash + Eq
|
||||
where
|
||||
T: Borrow<Q>,
|
||||
Q: Hash + Eq,
|
||||
{
|
||||
Recover::take(&mut self.map, value)
|
||||
}
|
||||
|
@ -634,15 +655,17 @@ impl<T, S> HashSet<T, S>
|
|||
/// assert_eq!(set.len(), 3);
|
||||
/// ```
|
||||
pub fn retain<F>(&mut self, mut f: F)
|
||||
where F: FnMut(&T) -> bool
|
||||
where
|
||||
F: FnMut(&T) -> bool,
|
||||
{
|
||||
self.map.retain(|k, _| f(k));
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> PartialEq for HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn eq(&self, other: &HashSet<T, S>) -> bool {
|
||||
if self.len() != other.len() {
|
||||
|
@ -654,14 +677,16 @@ impl<T, S> PartialEq for HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<T, S> Eq for HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
}
|
||||
|
||||
impl<T, S> fmt::Debug for HashSet<T, S>
|
||||
where T: Eq + Hash + fmt::Debug,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash + fmt::Debug,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_set().entries(self.iter()).finish()
|
||||
|
@ -669,8 +694,9 @@ impl<T, S> fmt::Debug for HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<T, S> FromIterator<T> for HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher + Default
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> HashSet<T, S> {
|
||||
let mut set = HashSet::with_hasher(Default::default());
|
||||
|
@ -680,8 +706,9 @@ impl<T, S> FromIterator<T> for HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<T, S> Extend<T> for HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
|
||||
self.map.extend(iter.into_iter().map(|k| (k, ())));
|
||||
|
@ -689,8 +716,9 @@ impl<T, S> Extend<T> for HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<'a, T, S> Extend<&'a T> for HashSet<T, S>
|
||||
where T: 'a + Eq + Hash + Copy,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: 'a + Eq + Hash + Copy,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
|
||||
self.extend(iter.into_iter().cloned());
|
||||
|
@ -698,18 +726,22 @@ impl<'a, T, S> Extend<&'a T> for HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<T, S> Default for HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher + Default
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
/// Creates an empty `HashSet<T, S>` with the `Default` value for the hasher.
|
||||
fn default() -> HashSet<T, S> {
|
||||
HashSet { map: HashMap::default() }
|
||||
HashSet {
|
||||
map: HashMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, T, S> BitOr<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
||||
where T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default
|
||||
where
|
||||
T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
type Output = HashSet<T, S>;
|
||||
|
||||
|
@ -739,8 +771,9 @@ impl<'a, 'b, T, S> BitOr<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<'a, 'b, T, S> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
||||
where T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default
|
||||
where
|
||||
T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
type Output = HashSet<T, S>;
|
||||
|
||||
|
@ -770,8 +803,9 @@ impl<'a, 'b, T, S> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<'a, 'b, T, S> BitXor<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
||||
where T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default
|
||||
where
|
||||
T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
type Output = HashSet<T, S>;
|
||||
|
||||
|
@ -801,8 +835,9 @@ impl<'a, 'b, T, S> BitXor<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<'a, 'b, T, S> Sub<&'b HashSet<T, S>> for &'a HashSet<T, S>
|
||||
where T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default
|
||||
where
|
||||
T: Eq + Hash + Clone,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
type Output = HashSet<T, S>;
|
||||
|
||||
|
@ -915,8 +950,9 @@ pub struct Union<'a, T: 'a, S: 'a> {
|
|||
}
|
||||
|
||||
impl<'a, T, S> IntoIterator for &'a HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
type Item = &'a T;
|
||||
type IntoIter = Iter<'a, T>;
|
||||
|
@ -927,8 +963,9 @@ impl<'a, T, S> IntoIterator for &'a HashSet<T, S>
|
|||
}
|
||||
|
||||
impl<T, S> IntoIterator for HashSet<T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
type Item = T;
|
||||
type IntoIter = IntoIter<T>;
|
||||
|
@ -954,13 +991,17 @@ impl<T, S> IntoIterator for HashSet<T, S>
|
|||
/// }
|
||||
/// ```
|
||||
fn into_iter(self) -> IntoIter<T> {
|
||||
IntoIter { iter: self.map.into_iter() }
|
||||
IntoIter {
|
||||
iter: self.map.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K> Clone for Iter<'a, K> {
|
||||
fn clone(&self) -> Iter<'a, K> {
|
||||
Iter { iter: self.iter.clone() }
|
||||
Iter {
|
||||
iter: self.iter.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a, K> Iterator for Iter<'a, K> {
|
||||
|
@ -1003,10 +1044,7 @@ impl<K> ExactSizeIterator for IntoIter<K> {
|
|||
|
||||
impl<K: fmt::Debug> fmt::Debug for IntoIter<K> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let entries_iter = self.iter
|
||||
.inner
|
||||
.iter()
|
||||
.map(|(k, _)| k);
|
||||
let entries_iter = self.iter.inner.iter().map(|(k, _)| k);
|
||||
f.debug_list().entries(entries_iter).finish()
|
||||
}
|
||||
}
|
||||
|
@ -1029,23 +1067,24 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> {
|
|||
|
||||
impl<'a, K: fmt::Debug> fmt::Debug for Drain<'a, K> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let entries_iter = self.iter
|
||||
.inner
|
||||
.iter()
|
||||
.map(|(k, _)| k);
|
||||
let entries_iter = self.iter.inner.iter().map(|(k, _)| k);
|
||||
f.debug_list().entries(entries_iter).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, S> Clone for Intersection<'a, T, S> {
|
||||
fn clone(&self) -> Intersection<'a, T, S> {
|
||||
Intersection { iter: self.iter.clone(), ..*self }
|
||||
Intersection {
|
||||
iter: self.iter.clone(),
|
||||
..*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, S> Iterator for Intersection<'a, T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
type Item = &'a T;
|
||||
|
||||
|
@ -1065,8 +1104,9 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S>
|
|||
}
|
||||
|
||||
impl<'a, T, S> fmt::Debug for Intersection<'a, T, S>
|
||||
where T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
|
@ -1075,13 +1115,17 @@ impl<'a, T, S> fmt::Debug for Intersection<'a, T, S>
|
|||
|
||||
impl<'a, T, S> Clone for Difference<'a, T, S> {
|
||||
fn clone(&self) -> Difference<'a, T, S> {
|
||||
Difference { iter: self.iter.clone(), ..*self }
|
||||
Difference {
|
||||
iter: self.iter.clone(),
|
||||
..*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, S> Iterator for Difference<'a, T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
type Item = &'a T;
|
||||
|
||||
|
@ -1101,8 +1145,9 @@ impl<'a, T, S> Iterator for Difference<'a, T, S>
|
|||
}
|
||||
|
||||
impl<'a, T, S> fmt::Debug for Difference<'a, T, S>
|
||||
where T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
|
@ -1111,13 +1156,16 @@ impl<'a, T, S> fmt::Debug for Difference<'a, T, S>
|
|||
|
||||
impl<'a, T, S> Clone for SymmetricDifference<'a, T, S> {
|
||||
fn clone(&self) -> SymmetricDifference<'a, T, S> {
|
||||
SymmetricDifference { iter: self.iter.clone() }
|
||||
SymmetricDifference {
|
||||
iter: self.iter.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
type Item = &'a T;
|
||||
|
||||
|
@ -1130,8 +1178,9 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S>
|
|||
}
|
||||
|
||||
impl<'a, T, S> fmt::Debug for SymmetricDifference<'a, T, S>
|
||||
where T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
|
@ -1140,13 +1189,16 @@ impl<'a, T, S> fmt::Debug for SymmetricDifference<'a, T, S>
|
|||
|
||||
impl<'a, T, S> Clone for Union<'a, T, S> {
|
||||
fn clone(&self) -> Union<'a, T, S> {
|
||||
Union { iter: self.iter.clone() }
|
||||
Union {
|
||||
iter: self.iter.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, S> fmt::Debug for Union<'a, T, S>
|
||||
where T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: fmt::Debug + Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
|
@ -1154,8 +1206,9 @@ impl<'a, T, S> fmt::Debug for Union<'a, T, S>
|
|||
}
|
||||
|
||||
impl<'a, T, S> Iterator for Union<'a, T, S>
|
||||
where T: Eq + Hash,
|
||||
S: BuildHasher
|
||||
where
|
||||
T: Eq + Hash,
|
||||
S: BuildHasher,
|
||||
{
|
||||
type Item = &'a T;
|
||||
|
||||
|
@ -1178,20 +1231,24 @@ fn assert_covariance() {
|
|||
fn into_iter<'new>(v: IntoIter<&'static str>) -> IntoIter<&'new str> {
|
||||
v
|
||||
}
|
||||
fn difference<'a, 'new>(v: Difference<'a, &'static str, RandomState>)
|
||||
-> Difference<'a, &'new str, RandomState> {
|
||||
fn difference<'a, 'new>(
|
||||
v: Difference<'a, &'static str, RandomState>,
|
||||
) -> Difference<'a, &'new str, RandomState> {
|
||||
v
|
||||
}
|
||||
fn symmetric_difference<'a, 'new>(v: SymmetricDifference<'a, &'static str, RandomState>)
|
||||
-> SymmetricDifference<'a, &'new str, RandomState> {
|
||||
fn symmetric_difference<'a, 'new>(
|
||||
v: SymmetricDifference<'a, &'static str, RandomState>,
|
||||
) -> SymmetricDifference<'a, &'new str, RandomState> {
|
||||
v
|
||||
}
|
||||
fn intersection<'a, 'new>(v: Intersection<'a, &'static str, RandomState>)
|
||||
-> Intersection<'a, &'new str, RandomState> {
|
||||
fn intersection<'a, 'new>(
|
||||
v: Intersection<'a, &'static str, RandomState>,
|
||||
) -> Intersection<'a, &'new str, RandomState> {
|
||||
v
|
||||
}
|
||||
fn union<'a, 'new>(v: Union<'a, &'static str, RandomState>)
|
||||
-> Union<'a, &'new str, RandomState> {
|
||||
fn union<'a, 'new>(
|
||||
v: Union<'a, &'static str, RandomState>,
|
||||
) -> Union<'a, &'new str, RandomState> {
|
||||
v
|
||||
}
|
||||
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue