Skip to content

Commit e3e86a2

Browse files
authored
Merge pull request #141 from cuviper/relax
Relax some bounds to match std
2 parents 4f10104 + f4cacc1 commit e3e86a2

File tree

4 files changed

+123
-155
lines changed

4 files changed

+123
-155
lines changed

src/map.rs

+65-87
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ impl<K, V, S> Entries for IndexMap<K, V, S> {
125125

126126
impl<K, V, S> fmt::Debug for IndexMap<K, V, S>
127127
where
128-
K: fmt::Debug + Hash + Eq,
128+
K: fmt::Debug,
129129
V: fmt::Debug,
130-
S: BuildHasher,
131130
{
132131
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133132
if cfg!(not(feature = "test_debug")) {
@@ -165,10 +164,7 @@ impl<K, V, S> IndexMap<K, V, S> {
165164
///
166165
/// Computes in **O(n)** time.
167166
#[inline]
168-
pub fn with_capacity_and_hasher(n: usize, hash_builder: S) -> Self
169-
where
170-
S: BuildHasher,
171-
{
167+
pub fn with_capacity_and_hasher(n: usize, hash_builder: S) -> Self {
172168
if n == 0 {
173169
IndexMap {
174170
core: IndexMapCore::new(),
@@ -182,6 +178,21 @@ impl<K, V, S> IndexMap<K, V, S> {
182178
}
183179
}
184180

181+
/// Create a new map with `hash_builder`
182+
pub fn with_hasher(hash_builder: S) -> Self {
183+
Self::with_capacity_and_hasher(0, hash_builder)
184+
}
185+
186+
/// Computes in **O(1)** time.
187+
pub fn capacity(&self) -> usize {
188+
self.core.capacity()
189+
}
190+
191+
/// Return a reference to the map's `BuildHasher`.
192+
pub fn hasher(&self) -> &S {
193+
&self.hash_builder
194+
}
195+
185196
/// Return the number of key-value pairs in the map.
186197
///
187198
/// Computes in **O(1)** time.
@@ -198,40 +209,63 @@ impl<K, V, S> IndexMap<K, V, S> {
198209
self.len() == 0
199210
}
200211

201-
/// Create a new map with `hash_builder`
202-
pub fn with_hasher(hash_builder: S) -> Self
203-
where
204-
S: BuildHasher,
205-
{
206-
Self::with_capacity_and_hasher(0, hash_builder)
212+
/// Return an iterator over the key-value pairs of the map, in their order
213+
pub fn iter(&self) -> Iter<'_, K, V> {
214+
Iter {
215+
iter: self.as_entries().iter(),
216+
}
207217
}
208218

209-
/// Return a reference to the map's `BuildHasher`.
210-
pub fn hasher(&self) -> &S
211-
where
212-
S: BuildHasher,
213-
{
214-
&self.hash_builder
219+
/// Return an iterator over the key-value pairs of the map, in their order
220+
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
221+
IterMut {
222+
iter: self.as_entries_mut().iter_mut(),
223+
}
215224
}
216225

217-
/// Computes in **O(1)** time.
218-
pub fn capacity(&self) -> usize {
219-
self.core.capacity()
226+
/// Return an iterator over the keys of the map, in their order
227+
pub fn keys(&self) -> Keys<'_, K, V> {
228+
Keys {
229+
iter: self.as_entries().iter(),
230+
}
231+
}
232+
233+
/// Return an iterator over the values of the map, in their order
234+
pub fn values(&self) -> Values<'_, K, V> {
235+
Values {
236+
iter: self.as_entries().iter(),
237+
}
238+
}
239+
240+
/// Return an iterator over mutable references to the the values of the map,
241+
/// in their order
242+
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
243+
ValuesMut {
244+
iter: self.as_entries_mut().iter_mut(),
245+
}
220246
}
221-
}
222247

223-
impl<K, V, S> IndexMap<K, V, S>
224-
where
225-
K: Hash + Eq,
226-
S: BuildHasher,
227-
{
228248
/// Remove all key-value pairs in the map, while preserving its capacity.
229249
///
230250
/// Computes in **O(n)** time.
231251
pub fn clear(&mut self) {
232252
self.core.clear();
233253
}
234254

255+
/// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
256+
/// Keeps the allocated memory for reuse.
257+
pub fn drain(&mut self, range: RangeFull) -> Drain<'_, K, V> {
258+
Drain {
259+
iter: self.core.drain(range),
260+
}
261+
}
262+
}
263+
264+
impl<K, V, S> IndexMap<K, V, S>
265+
where
266+
K: Hash + Eq,
267+
S: BuildHasher,
268+
{
235269
/// Reserve capacity for `additional` more key-value pairs.
236270
///
237271
/// Computes in **O(n)** time.
@@ -296,42 +330,6 @@ where
296330
self.core.entry(hash, key)
297331
}
298332

299-
/// Return an iterator over the key-value pairs of the map, in their order
300-
pub fn iter(&self) -> Iter<'_, K, V> {
301-
Iter {
302-
iter: self.as_entries().iter(),
303-
}
304-
}
305-
306-
/// Return an iterator over the key-value pairs of the map, in their order
307-
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
308-
IterMut {
309-
iter: self.as_entries_mut().iter_mut(),
310-
}
311-
}
312-
313-
/// Return an iterator over the keys of the map, in their order
314-
pub fn keys(&self) -> Keys<'_, K, V> {
315-
Keys {
316-
iter: self.as_entries().iter(),
317-
}
318-
}
319-
320-
/// Return an iterator over the values of the map, in their order
321-
pub fn values(&self) -> Values<'_, K, V> {
322-
Values {
323-
iter: self.as_entries().iter(),
324-
}
325-
}
326-
327-
/// Return an iterator over mutable references to the the values of the map,
328-
/// in their order
329-
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
330-
ValuesMut {
331-
iter: self.as_entries_mut().iter_mut(),
332-
}
333-
}
334-
335333
/// Return `true` if an equivalent to `key` exists in the map.
336334
///
337335
/// Computes in **O(1)** time (average).
@@ -660,14 +658,6 @@ where
660658
pub fn reverse(&mut self) {
661659
self.core.reverse()
662660
}
663-
664-
/// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
665-
/// Keeps the allocated memory for reuse.
666-
pub fn drain(&mut self, range: RangeFull) -> Drain<'_, K, V> {
667-
Drain {
668-
iter: self.core.drain(range),
669-
}
670-
}
671661
}
672662

673663
impl<K, V, S> IndexMap<K, V, S> {
@@ -963,35 +953,23 @@ impl<K, V> DoubleEndedIterator for Drain<'_, K, V> {
963953
double_ended_iterator_methods!(Bucket::key_value);
964954
}
965955

966-
impl<'a, K, V, S> IntoIterator for &'a IndexMap<K, V, S>
967-
where
968-
K: Hash + Eq,
969-
S: BuildHasher,
970-
{
956+
impl<'a, K, V, S> IntoIterator for &'a IndexMap<K, V, S> {
971957
type Item = (&'a K, &'a V);
972958
type IntoIter = Iter<'a, K, V>;
973959
fn into_iter(self) -> Self::IntoIter {
974960
self.iter()
975961
}
976962
}
977963

978-
impl<'a, K, V, S> IntoIterator for &'a mut IndexMap<K, V, S>
979-
where
980-
K: Hash + Eq,
981-
S: BuildHasher,
982-
{
964+
impl<'a, K, V, S> IntoIterator for &'a mut IndexMap<K, V, S> {
983965
type Item = (&'a K, &'a mut V);
984966
type IntoIter = IterMut<'a, K, V>;
985967
fn into_iter(self) -> Self::IntoIter {
986968
self.iter_mut()
987969
}
988970
}
989971

990-
impl<K, V, S> IntoIterator for IndexMap<K, V, S>
991-
where
992-
K: Hash + Eq,
993-
S: BuildHasher,
994-
{
972+
impl<K, V, S> IntoIterator for IndexMap<K, V, S> {
995973
type Item = (K, V);
996974
type IntoIter = IntoIter<K, V>;
997975
fn into_iter(self) -> Self::IntoIter {
@@ -1099,7 +1077,7 @@ where
10991077

11001078
impl<K, V, S> Default for IndexMap<K, V, S>
11011079
where
1102-
S: BuildHasher + Default,
1080+
S: Default,
11031081
{
11041082
/// Return an empty `IndexMap`
11051083
fn default() -> Self {

src/rayon/map.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use crate::IndexMap;
2121
/// Requires crate feature `"rayon"`.
2222
impl<K, V, S> IntoParallelIterator for IndexMap<K, V, S>
2323
where
24-
K: Hash + Eq + Send,
24+
K: Send,
2525
V: Send,
26-
S: BuildHasher,
2726
{
2827
type Item = (K, V);
2928
type Iter = IntoParIter<K, V>;
@@ -66,9 +65,8 @@ impl<K: Send, V: Send> IndexedParallelIterator for IntoParIter<K, V> {
6665
/// Requires crate feature `"rayon"`.
6766
impl<'a, K, V, S> IntoParallelIterator for &'a IndexMap<K, V, S>
6867
where
69-
K: Hash + Eq + Sync,
68+
K: Sync,
7069
V: Sync,
71-
S: BuildHasher,
7270
{
7371
type Item = (&'a K, &'a V);
7472
type Iter = ParIter<'a, K, V>;
@@ -117,7 +115,7 @@ impl<K: Sync, V: Sync> IndexedParallelIterator for ParIter<'_, K, V> {
117115
/// Requires crate feature `"rayon"`.
118116
impl<'a, K, V, S> IntoParallelIterator for &'a mut IndexMap<K, V, S>
119117
where
120-
K: Hash + Eq + Sync + Send,
118+
K: Sync + Send,
121119
V: Send,
122120
S: BuildHasher,
123121
{
@@ -159,9 +157,8 @@ impl<K: Sync + Send, V: Send> IndexedParallelIterator for ParIterMut<'_, K, V> {
159157
/// See also the `IntoParallelIterator` implementations.
160158
impl<K, V, S> IndexMap<K, V, S>
161159
where
162-
K: Hash + Eq + Sync,
160+
K: Sync,
163161
V: Sync,
164-
S: BuildHasher,
165162
{
166163
/// Return a parallel iterator over the keys of the map.
167164
///
@@ -182,7 +179,14 @@ where
182179
entries: self.as_entries(),
183180
}
184181
}
182+
}
185183

184+
impl<K, V, S> IndexMap<K, V, S>
185+
where
186+
K: Hash + Eq + Sync,
187+
V: Sync,
188+
S: BuildHasher,
189+
{
186190
/// Returns `true` if `self` contains all of the same key-value pairs as `other`,
187191
/// regardless of each map's indexed order, determined in parallel.
188192
pub fn par_eq<V2, S2>(&self, other: &IndexMap<K, V2, S2>) -> bool
@@ -269,9 +273,8 @@ impl<K: Sync, V: Sync> IndexedParallelIterator for ParValues<'_, K, V> {
269273
/// Requires crate feature `"rayon"`.
270274
impl<K, V, S> IndexMap<K, V, S>
271275
where
272-
K: Hash + Eq + Send,
276+
K: Send,
273277
V: Send,
274-
S: BuildHasher,
275278
{
276279
/// Return a parallel iterator over mutable references to the the values of the map
277280
///
@@ -282,7 +285,14 @@ where
282285
entries: self.as_entries_mut(),
283286
}
284287
}
288+
}
285289

290+
impl<K, V, S> IndexMap<K, V, S>
291+
where
292+
K: Hash + Eq + Send,
293+
V: Send,
294+
S: BuildHasher,
295+
{
286296
/// Sort the map’s key-value pairs in parallel, by the default ordering of the keys.
287297
pub fn par_sort_keys(&mut self)
288298
where

src/rayon/set.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ type Bucket<T> = crate::Bucket<T, ()>;
2222
/// Requires crate feature `"rayon"`.
2323
impl<T, S> IntoParallelIterator for IndexSet<T, S>
2424
where
25-
T: Hash + Eq + Send,
26-
S: BuildHasher,
25+
T: Send,
2726
{
2827
type Item = T;
2928
type Iter = IntoParIter<T>;
@@ -66,8 +65,7 @@ impl<T: Send> IndexedParallelIterator for IntoParIter<T> {
6665
/// Requires crate feature `"rayon"`.
6766
impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S>
6867
where
69-
T: Hash + Eq + Sync,
70-
S: BuildHasher,
68+
T: Sync,
7169
{
7270
type Item = &'a T;
7371
type Iter = ParIter<'a, T>;

0 commit comments

Comments
 (0)