diff --git a/src/arbitrary.rs b/src/arbitrary.rs index 86d2e4e..eaa1d94 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -7,7 +7,7 @@ use std::iter; use ::arbitrary::{size_hint, Arbitrary, Result, Unstructured}; -use crate::{HashMap, HashSet, OrdMap, OrdSet, Vector}; +use crate::{hashmap::HashMap, hashset::HashSet, OrdMap, OrdSet, Vector}; fn empty() -> Box> { Box::new(iter::empty()) diff --git a/src/hash/map.rs b/src/hash/map.rs index 02b84ba..6d34f96 100644 --- a/src/hash/map.rs +++ b/src/hash/map.rs @@ -57,10 +57,10 @@ use crate::util::{Pool, PoolRef, Ref}; /// ``` #[macro_export] macro_rules! hashmap { - () => { $crate::hashmap::HashMap::new() }; + () => { $crate::HashMap::new() }; ( $( $key:expr => $value:expr ),* ) => {{ - let mut map = $crate::hashmap::HashMap::new(); + let mut map = $crate::HashMap::new(); $({ map.insert($key, $value); })*; @@ -68,7 +68,7 @@ macro_rules! hashmap { }}; ( $( $key:expr => $value:expr ,)* ) => {{ - let mut map = $crate::hashmap::HashMap::new(); + let mut map = $crate::HashMap::new(); $({ map.insert($key, $value); })*; @@ -119,7 +119,10 @@ where } } -impl HashMap { +impl HashMap +where + S: BuildHasher + Default, +{ /// Construct an empty hash map. #[inline] #[must_use] @@ -141,10 +144,11 @@ impl HashMap { } } -impl HashMap +impl HashMap where K: Hash + Eq + Clone, V: Clone, + S: BuildHasher + Default, { /// Construct a hash map with a single mapping. /// @@ -152,7 +156,7 @@ where /// /// ``` /// # #[macro_use] extern crate im; - /// # use im::hashmap::HashMap; + /// # use im::HashMap; /// let map = HashMap::unit(123, "onetwothree"); /// assert_eq!( /// map.get(&123), @@ -161,8 +165,8 @@ where /// ``` #[inline] #[must_use] - pub fn unit(k: K, v: V) -> HashMap { - HashMap::new().update(k, v) + pub fn unit(k: K, v: V) -> HashMap { + HashMap::default().update(k, v) } } @@ -175,7 +179,7 @@ impl HashMap { /// /// ``` /// # #[macro_use] extern crate im; - /// # use im::hashmap::HashMap; + /// # use im::HashMap; /// assert!( /// !hashmap!{1 => 2}.is_empty() /// ); @@ -2219,7 +2223,7 @@ mod test { #[test] fn large_map() { - let mut map = HashMap::new(); + let mut map = crate::HashMap::new(); let size = 32769; for i in 0..size { map.insert(i, i); diff --git a/src/hash/set.rs b/src/hash/set.rs index 4f1dfee..8435416 100644 --- a/src/hash/set.rs +++ b/src/hash/set.rs @@ -33,8 +33,8 @@ use std::ops::{Add, Deref, Mul}; use crate::nodes::hamt::{hash_key, Drain as NodeDrain, HashValue, Iter as NodeIter, Node}; use crate::ordset::OrdSet; -use crate::Vector; use crate::util::{Pool, PoolRef, Ref}; +use crate::Vector; /// Construct a set from a sequence of values. /// @@ -52,10 +52,10 @@ use crate::util::{Pool, PoolRef, Ref}; /// ``` #[macro_export] macro_rules! hashset { - () => { $crate::hashset::HashSet::new() }; + () => { $crate::HashSet::new() }; ( $($x:expr),* ) => {{ - let mut l = $crate::hashset::HashSet::new(); + let mut l = $crate::HashSet::new(); $( l.insert($x); )* @@ -63,7 +63,7 @@ macro_rules! hashset { }}; ( $($x:expr ,)* ) => {{ - let mut l = $crate::hashset::HashSet::new(); + let mut l = $crate::HashSet::new(); $( l.insert($x); )* @@ -125,7 +125,10 @@ where } } -impl HashSet { +impl HashSet +where + S: BuildHasher + Default, +{ /// Construct an empty set. #[must_use] pub fn new() -> Self { @@ -145,9 +148,10 @@ impl HashSet { } } -impl HashSet +impl HashSet where A: Hash + Eq + Clone, + S: BuildHasher + Default, { /// Construct a set with a single value. /// @@ -155,7 +159,7 @@ where /// /// ``` /// # #[macro_use] extern crate im; - /// # use im::hashset::HashSet; + /// # use im::HashSet; /// # use std::sync::Arc; /// let set = HashSet::unit(123); /// assert!(set.contains(&123)); diff --git a/src/lib.rs b/src/lib.rs index 0444dbd..5bf9a3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -390,8 +390,10 @@ compile_error!( "The `pool` feature is not threadsafe but you've enabled it on a threadsafe version of `im`." ); -pub use crate::hashmap::HashMap; -pub use crate::hashset::HashSet; +/// HashMap with random state hasher +pub type HashMap = crate::hashmap::HashMap; +/// HashSet with random state hasher +pub type HashSet = crate::hashset::HashSet; pub use crate::ordmap::OrdMap; pub use crate::ordset::OrdSet; #[doc(inline)] diff --git a/src/quickcheck.rs b/src/quickcheck.rs index 9005815..4264f78 100644 --- a/src/quickcheck.rs +++ b/src/quickcheck.rs @@ -1,4 +1,4 @@ -use crate::{HashMap, HashSet, OrdMap, OrdSet, Vector}; +use crate::{hashmap::HashMap, hashset::HashSet, OrdMap, OrdSet, Vector}; use ::quickcheck::{Arbitrary, Gen}; use std::hash::{BuildHasher, Hash}; use std::iter::FromIterator;