diff options
author | David LeGare <legare@google.com> | 2022-03-10 16:15:25 +0000 |
---|---|---|
committer | David LeGare <legare@google.com> | 2022-03-10 16:15:25 +0000 |
commit | 9f6431dee3524903dae80ca9ae4577301236d400 (patch) | |
tree | 9eb9b985863843fbf9332a33951797aca28db187 /src/set.rs | |
parent | c77953dabfec89f29d3916be3f2d9c2f3066f1bb (diff) | |
download | hashbrown-9f6431dee3524903dae80ca9ae4577301236d400.tar.gz |
Revert "Update hashbrown to 0.12.0"
This reverts commit c77953dabfec89f29d3916be3f2d9c2f3066f1bb.
Reason for revert: Performance regression.
Bug: 223002010
Change-Id: I139eac2ddc94c81938ed40d96465dc8f7e4a88f1
Diffstat (limited to 'src/set.rs')
-rw-r--r-- | src/set.rs | 78 |
1 files changed, 14 insertions, 64 deletions
@@ -378,7 +378,7 @@ impl<T, S, A: Allocator + Clone> HashSet<T, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn clear(&mut self) { - self.map.clear(); + self.map.clear() } } @@ -454,12 +454,6 @@ impl<T, S, A> HashSet<T, S, A> where A: Allocator + Clone, { - /// Returns a reference to the underlying allocator. - #[inline] - pub fn allocator(&self) -> &A { - self.map.allocator() - } - /// Creates a new empty hash set which will use the given hasher to hash /// keys. /// @@ -559,7 +553,7 @@ where /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn reserve(&mut self, additional: usize) { - self.map.reserve(additional); + self.map.reserve(additional) } /// Tries to reserve capacity for at least `additional` more elements to be inserted @@ -601,7 +595,7 @@ where /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn shrink_to_fit(&mut self) { - self.map.shrink_to_fit(); + self.map.shrink_to_fit() } /// Shrinks the capacity of the set with a lower limit. It will drop @@ -627,7 +621,7 @@ where /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn shrink_to(&mut self, min_capacity: usize) { - self.map.shrink_to(min_capacity); + self.map.shrink_to(min_capacity) } /// Visits the values representing the difference, @@ -991,30 +985,6 @@ where self.map.insert(value, ()).is_none() } - /// Insert a value the set without checking if the value already exists in the set. - /// - /// Returns a reference to the value just inserted. - /// - /// This operation is safe if a value does not exist in the set. - /// - /// However, if a value exists in the set already, the behavior is unspecified: - /// this operation may panic, loop forever, or any following operation with the set - /// may panic, loop forever or return arbitrary result. - /// - /// That said, this operation (and following operations) are guaranteed to - /// not violate memory safety. - /// - /// This operation is faster than regular insert, because it does not perform - /// lookup before insertion. - /// - /// This operation is useful during initial population of the set. - /// For example, when constructing a set from another set, we know - /// that values are unique. - #[cfg_attr(feature = "inline-more", inline)] - pub fn insert_unique_unchecked(&mut self, value: T) -> &T { - self.map.insert_unique_unchecked(value, ()).0 - } - /// Adds a value to the set, replacing the existing value, if any, that is equal to the given /// one. Returns the replaced value. /// @@ -1128,7 +1098,8 @@ where impl<T, S, A> fmt::Debug for HashSet<T, S, A> where - T: fmt::Debug, + T: Eq + Hash + fmt::Debug, + S: BuildHasher, A: Allocator + Clone, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -1159,27 +1130,6 @@ where } } -// The default hasher is used to match the std implementation signature -#[cfg(feature = "ahash")] -impl<T, A, const N: usize> From<[T; N]> for HashSet<T, DefaultHashBuilder, A> -where - T: Eq + Hash, - A: Default + Allocator + Clone, -{ - /// # Examples - /// - /// ``` - /// use hashbrown::HashSet; - /// - /// let set1 = HashSet::from([1, 2, 3, 4]); - /// let set2: HashSet<_> = [1, 2, 3, 4].into(); - /// assert_eq!(set1, set2); - /// ``` - fn from(arr: [T; N]) -> Self { - arr.into_iter().collect() - } -} - impl<T, S, A> Extend<T> for HashSet<T, S, A> where T: Eq + Hash, @@ -1212,7 +1162,7 @@ where { #[cfg_attr(feature = "inline-more", inline)] fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) { - self.extend(iter.into_iter().copied()); + self.extend(iter.into_iter().cloned()); } #[inline] @@ -2013,7 +1963,7 @@ mod test_set { let expected = [3, 5, 11, 77]; for x in a.intersection(&b) { assert!(expected.contains(x)); - i += 1; + i += 1 } assert_eq!(i, expected.len()); } @@ -2036,7 +1986,7 @@ mod test_set { let expected = [1, 5, 11]; for x in a.difference(&b) { assert!(expected.contains(x)); - i += 1; + i += 1 } assert_eq!(i, expected.len()); } @@ -2062,7 +2012,7 @@ mod test_set { let expected = [-2, 1, 5, 11, 14, 22]; for x in a.symmetric_difference(&b) { assert!(expected.contains(x)); - i += 1; + i += 1 } assert_eq!(i, expected.len()); } @@ -2092,7 +2042,7 @@ mod test_set { let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24]; for x in a.union(&b) { assert!(expected.contains(x)); - i += 1; + i += 1 } assert_eq!(i, expected.len()); } @@ -2118,7 +2068,7 @@ mod test_set { fn test_from_iter() { let xs = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9]; - let set: HashSet<_> = xs.iter().copied().collect(); + let set: HashSet<_> = xs.iter().cloned().collect(); for x in &xs { assert!(set.contains(x)); @@ -2280,7 +2230,7 @@ mod test_set { #[test] fn test_retain() { let xs = [1, 2, 3, 4, 5, 6]; - let mut set: HashSet<i32> = xs.iter().copied().collect(); + let mut set: HashSet<i32> = xs.iter().cloned().collect(); set.retain(|&k| k % 2 == 0); assert_eq!(set.len(), 3); assert!(set.contains(&2)); @@ -2322,7 +2272,7 @@ mod test_set { const EMPTY_SET: HashSet<u32, MyHasher> = HashSet::with_hasher(MyHasher); - let mut set = EMPTY_SET; + let mut set = EMPTY_SET.clone(); set.insert(19); assert!(set.contains(&19)); } |