Skip to content

Commit

Permalink
Upgrade to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Mar 8, 2019
1 parent c87740d commit 37deedd
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 255 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false

matrix:
include:
- rust: 1.29.0
- rust: 1.31.0
- rust: stable
- rust: beta
- rust: nightly
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/Amanieu/hashbrown"
readme = "README.md"
keywords = ["hash", "no_std", "hashmap", "swisstable"]
categories = ["data-structures", "no-std"]
edition = "2018"

[dependencies]
# For external trait impls
Expand Down
2 changes: 0 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(test)]

extern crate hashbrown;
extern crate rustc_hash;
extern crate test;

use std::hash::Hash;
Expand Down
84 changes: 40 additions & 44 deletions src/external_trait_impls/rayon/map.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Rayon extensions for `HashMap`.

use crate::hash_map::HashMap;
use core::fmt;
use core::hash::{BuildHasher, Hash};
use hash_map::HashMap;
use rayon::iter::plumbing::UnindexedConsumer;
use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator};

Expand All @@ -15,7 +15,7 @@ use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, Pa
/// [`par_iter`]: /hashbrown/struct.HashMap.html#method.par_iter
/// [`HashMap`]: /hashbrown/struct.HashMap.html
/// [`IntoParallelRefIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelRefIterator.html
pub struct ParIter<'a, K: 'a, V: 'a, S: 'a> {
pub struct ParIter<'a, K, V, S> {
map: &'a HashMap<K, V, S>,
}

Expand All @@ -38,17 +38,15 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParIter<'a, K, V, S> {
}
}

impl<'a, K, V, S> Clone for ParIter<'a, K, V, S> {
impl<K, V, S> Clone for ParIter<'_, K, V, S> {
#[inline]
fn clone(&self) -> Self {
ParIter { map: self.map }
}
}

impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
for ParIter<'a, K, V, S>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParIter<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.iter().fmt(f)
}
}
Expand All @@ -60,7 +58,7 @@ impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
///
/// [`par_keys`]: /hashbrown/struct.HashMap.html#method.par_keys
/// [`HashMap`]: /hashbrown/struct.HashMap.html
pub struct ParKeys<'a, K: 'a, V: 'a, S: 'a> {
pub struct ParKeys<'a, K, V, S> {
map: &'a HashMap<K, V, S>,
}

Expand All @@ -80,15 +78,15 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParKeys<'a, K, V, S> {
}
}

impl<'a, K, V, S> Clone for ParKeys<'a, K, V, S> {
impl<K, V, S> Clone for ParKeys<'_, K, V, S> {
#[inline]
fn clone(&self) -> Self {
ParKeys { map: self.map }
}
}

impl<'a, K: fmt::Debug + Eq + Hash, V, S: BuildHasher> fmt::Debug for ParKeys<'a, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<K: fmt::Debug + Eq + Hash, V, S: BuildHasher> fmt::Debug for ParKeys<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.keys().fmt(f)
}
}
Expand All @@ -100,7 +98,7 @@ impl<'a, K: fmt::Debug + Eq + Hash, V, S: BuildHasher> fmt::Debug for ParKeys<'a
///
/// [`par_values`]: /hashbrown/struct.HashMap.html#method.par_values
/// [`HashMap`]: /hashbrown/struct.HashMap.html
pub struct ParValues<'a, K: 'a, V: 'a, S: 'a> {
pub struct ParValues<'a, K, V, S> {
map: &'a HashMap<K, V, S>,
}

Expand All @@ -120,15 +118,15 @@ impl<'a, K: Sync, V: Sync, S: Sync> ParallelIterator for ParValues<'a, K, V, S>
}
}

impl<'a, K, V, S> Clone for ParValues<'a, K, V, S> {
impl<K, V, S> Clone for ParValues<'_, K, V, S> {
#[inline]
fn clone(&self) -> Self {
ParValues { map: self.map }
}
}

impl<'a, K: Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParValues<'a, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<K: Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParValues<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.values().fmt(f)
}
}
Expand All @@ -142,7 +140,7 @@ impl<'a, K: Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParValues<'
/// [`par_iter_mut`]: /hashbrown/struct.HashMap.html#method.par_iter_mut
/// [`HashMap`]: /hashbrown/struct.HashMap.html
/// [`IntoParallelRefMutIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelRefMutIterator.html
pub struct ParIterMut<'a, K: 'a, V: 'a, S: 'a> {
pub struct ParIterMut<'a, K, V, S> {
map: &'a mut HashMap<K, V, S>,
}

Expand All @@ -165,10 +163,10 @@ impl<'a, K: Send + Sync, V: Send, S: Send> ParallelIterator for ParIterMut<'a, K
}
}

impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
for ParIterMut<'a, K, V, S>
impl<K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
for ParIterMut<'_, K, V, S>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.iter().fmt(f)
}
}
Expand All @@ -180,7 +178,7 @@ impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
///
/// [`par_values_mut`]: /hashbrown/struct.HashMap.html#method.par_values_mut
/// [`HashMap`]: /hashbrown/struct.HashMap.html
pub struct ParValuesMut<'a, K: 'a, V: 'a, S: 'a> {
pub struct ParValuesMut<'a, K, V, S> {
map: &'a mut HashMap<K, V, S>,
}

Expand All @@ -200,8 +198,8 @@ impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParValuesMut<'a, K, V,
}
}

impl<'a, K: Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParValuesMut<'a, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<K: Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for ParValuesMut<'_, K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.values().fmt(f)
}
}
Expand Down Expand Up @@ -231,10 +229,8 @@ impl<K: Send, V: Send, S: Send> ParallelIterator for IntoParIter<K, V, S> {
}
}

impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
for IntoParIter<K, V, S>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl<K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug for IntoParIter<K, V, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.iter().fmt(f)
}
}
Expand All @@ -246,11 +242,11 @@ impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
///
/// [`par_drain`]: /hashbrown/struct.HashMap.html#method.par_drain
/// [`HashMap`]: /hashbrown/struct.HashMap.html
pub struct ParDrain<'a, K: 'a, V: 'a, S: 'a> {
pub struct ParDrain<'a, K, V, S> {
map: &'a mut HashMap<K, V, S>,
}

impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParDrain<'a, K, V, S> {
impl<K: Send, V: Send, S: Send> ParallelIterator for ParDrain<'_, K, V, S> {
type Item = (K, V);

#[inline]
Expand All @@ -262,39 +258,39 @@ impl<'a, K: Send, V: Send, S: Send> ParallelIterator for ParDrain<'a, K, V, S> {
}
}

impl<'a, K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
for ParDrain<'a, K, V, S>
impl<K: fmt::Debug + Eq + Hash, V: fmt::Debug, S: BuildHasher> fmt::Debug
for ParDrain<'_, K, V, S>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.map.iter().fmt(f)
}
}

impl<K: Sync, V: Sync, S: Sync> HashMap<K, V, S> {
/// Visits (potentially in parallel) immutably borrowed keys in an arbitrary order.
#[inline]
pub fn par_keys(&self) -> ParKeys<K, V, S> {
pub fn par_keys(&self) -> ParKeys<'_, K, V, S> {
ParKeys { map: self }
}

/// Visits (potentially in parallel) immutably borrowed values in an arbitrary order.
#[inline]
pub fn par_values(&self) -> ParValues<K, V, S> {
pub fn par_values(&self) -> ParValues<'_, K, V, S> {
ParValues { map: self }
}
}

impl<K: Send, V: Send, S: Send> HashMap<K, V, S> {
/// Visits (potentially in parallel) mutably borrowed values in an arbitrary order.
#[inline]
pub fn par_values_mut(&mut self) -> ParValuesMut<K, V, S> {
pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V, S> {
ParValuesMut { map: self }
}

/// Consumes (potentially in parallel) all values in an arbitrary order,
/// while preserving the map's allocated memory for reuse.
#[inline]
pub fn par_drain(&mut self) -> ParDrain<K, V, S> {
pub fn par_drain(&mut self) -> ParDrain<'_, K, V, S> {
ParDrain { map: self }
}
}
Expand Down Expand Up @@ -426,34 +422,34 @@ mod test_par_map {

use rayon::prelude::*;

use hash_map::HashMap;
use crate::hash_map::HashMap;

struct Dropable<'a> {
k: usize,
counter: &'a AtomicUsize,
}

impl<'a> Dropable<'a> {
fn new(k: usize, counter: &AtomicUsize) -> Dropable {
impl Dropable<'_> {
fn new(k: usize, counter: &AtomicUsize) -> Dropable<'_> {
counter.fetch_add(1, Ordering::Relaxed);

Dropable { k, counter }
}
}

impl<'a> Drop for Dropable<'a> {
impl Drop for Dropable<'_> {
fn drop(&mut self) {
self.counter.fetch_sub(1, Ordering::Relaxed);
}
}

impl<'a> Clone for Dropable<'a> {
fn clone(&self) -> Dropable<'a> {
impl Clone for Dropable<'_> {
fn clone(&self) -> Self {
Dropable::new(self.k, self.counter)
}
}

impl<'a> Hash for Dropable<'a> {
impl Hash for Dropable<'_> {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
Expand All @@ -462,13 +458,13 @@ mod test_par_map {
}
}

impl<'a> PartialEq for Dropable<'a> {
impl PartialEq for Dropable<'_> {
fn eq(&self, other: &Self) -> bool {
self.k == other.k
}
}

impl<'a> Eq for Dropable<'a> {}
impl Eq for Dropable<'_> {}

#[test]
fn test_into_iter_drops() {
Expand Down
14 changes: 7 additions & 7 deletions src/external_trait_impls/rayon/raw.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::raw::Bucket;
use crate::raw::{RawIterRange, RawTable};
use crate::scopeguard::guard;
use alloc::alloc::dealloc;
use core::marker::PhantomData;
use core::mem;
use core::ptr::NonNull;
use raw::Bucket;
use raw::{RawIterRange, RawTable};
use rayon::iter::{
plumbing::{self, Folder, UnindexedConsumer, UnindexedProducer},
ParallelIterator,
};
use scopeguard::guard;

/// Parallel iterator which returns a raw pointer to every full bucket in the table.
pub struct RawParIter<T> {
Expand Down Expand Up @@ -87,9 +87,9 @@ pub struct RawParDrain<'a, T> {
_marker: PhantomData<&'a RawTable<T>>,
}

unsafe impl<'a, T> Send for RawParDrain<'a, T> {}
unsafe impl<T> Send for RawParDrain<'_, T> {}

impl<'a, T: Send> ParallelIterator for RawParDrain<'a, T> {
impl<T: Send> ParallelIterator for RawParDrain<'_, T> {
type Item = T;

#[inline]
Expand All @@ -107,7 +107,7 @@ impl<'a, T: Send> ParallelIterator for RawParDrain<'a, T> {
}
}

impl<'a, T> Drop for RawParDrain<'a, T> {
impl<T> Drop for RawParDrain<'_, T> {
fn drop(&mut self) {
// If drive_unindexed is not called then simply clear the table.
unsafe { self.table.as_mut().clear() }
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<T> RawTable<T> {
/// Returns a parallel iterator which consumes all elements of a `RawTable`
/// without freeing its memory allocation.
#[inline]
pub fn par_drain(&mut self) -> RawParDrain<T> {
pub fn par_drain(&mut self) -> RawParDrain<'_, T> {
RawParDrain {
table: NonNull::from(self),
_marker: PhantomData,
Expand Down
Loading

0 comments on commit 37deedd

Please sign in to comment.