Skip to content

Commit

Permalink
Bump some deps, fix some warnings.
Browse files Browse the repository at this point in the history
Closes #189
Closes #197
  • Loading branch information
bodil committed Apr 29, 2022
1 parent 0b3a7b2 commit 546e59b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 94 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

#189 #197

#163 #150 #154 #191 #186 #179 #173 #194 #158

### Added

- `HashSet` now implements `From<Vector<A>>` and `From<&Vector<A>> where A: Clone`.
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ debug = []
typenum = "1.12"
bitmaps = "2"
sized-chunks = "0.6.4"
rand_core = "0.5.1"
rand_xoshiro = "0.4"
quickcheck = { version = "0.9", optional = true }
proptest = { version = "0.10", optional = true }
rand_core = "0.6"
rand_xoshiro = "0.6"
quickcheck = { version = "1", optional = true }
proptest = { version = "1", optional = true }
serde = { version = "1", optional = true }
rayon = { version = "1", optional = true }
refpool = { version = "0.4", optional = true }
arbitrary = { version = "0.4", optional = true }
arbitrary = { version = "1.1", optional = true }

[dev-dependencies]
proptest = "0.10"
proptest = "1"
serde = "1"
serde_json = "1"
rayon = "1"
rand = { version = "0.7", features = ["small_rng"] }
pretty_assertions = "0.6"
rand = { version = "0.8", features = ["small_rng"] }
pretty_assertions = "1"
metrohash = "1"
proptest-derive = "0.2"
proptest-derive = "0.3"
97 changes: 18 additions & 79 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,17 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::hash::{BuildHasher, Hash};
use std::iter;

use ::arbitrary::{size_hint, Arbitrary, Result, Unstructured};

use crate::{HashMap, HashSet, OrdMap, OrdSet, Vector};

fn empty<T: 'static>() -> Box<dyn Iterator<Item = T>> {
Box::new(iter::empty())
}

fn shrink_collection<T: Clone, A: Clone + Arbitrary>(
entries: impl Iterator<Item = T>,
f: impl Fn(&T) -> Box<dyn Iterator<Item = A>>,
) -> Box<dyn Iterator<Item = Vec<A>>> {
let entries: Vec<_> = entries.collect();
if entries.is_empty() {
return empty();
}

let mut shrinkers: Vec<Vec<_>> = vec![];
let mut i = entries.len();
loop {
shrinkers.push(entries.iter().take(i).map(&f).collect());
i /= 2;
if i == 0 {
break;
}
}
Box::new(iter::once(Vec::new()).chain(iter::from_fn(move || loop {
let mut shrinker = shrinkers.pop()?;
let x: Option<Vec<A>> = shrinker.iter_mut().map(|s| s.next()).collect();
if x.is_none() {
continue;
}
shrinkers.push(shrinker);
return x;
})))
}

impl<A: Arbitrary + Clone> Arbitrary for Vector<A> {
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
impl<'a, A: Arbitrary<'a> + Clone> Arbitrary<'a> for Vector<A> {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}

fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
u.arbitrary_take_rest_iter()?.collect()
}

Expand All @@ -56,19 +22,14 @@ impl<A: Arbitrary + Clone> Arbitrary for Vector<A> {
size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
})
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let collections = shrink_collection(self.iter(), |x| x.shrink());
Box::new(collections.map(|entries| entries.into_iter().collect()))
}
}

impl<K: Arbitrary + Ord + Clone, V: Arbitrary + Clone> Arbitrary for OrdMap<K, V> {
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
impl<'a, K: Arbitrary<'a> + Ord + Clone, V: Arbitrary<'a> + Clone> Arbitrary<'a> for OrdMap<K, V> {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}

fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
u.arbitrary_take_rest_iter()?.collect()
}

Expand All @@ -77,20 +38,14 @@ impl<K: Arbitrary + Ord + Clone, V: Arbitrary + Clone> Arbitrary for OrdMap<K, V
size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
})
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let collections =
shrink_collection(self.iter(), |(k, v)| Box::new(k.shrink().zip(v.shrink())));
Box::new(collections.map(|entries| entries.into_iter().collect()))
}
}

impl<A: Arbitrary + Ord + Clone> Arbitrary for OrdSet<A> {
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
impl<'a, A: Arbitrary<'a> + Ord + Clone> Arbitrary<'a> for OrdSet<A> {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}

fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
u.arbitrary_take_rest_iter()?.collect()
}

Expand All @@ -99,24 +54,19 @@ impl<A: Arbitrary + Ord + Clone> Arbitrary for OrdSet<A> {
size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
})
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let collections = shrink_collection(self.iter(), |v| v.shrink());
Box::new(collections.map(|entries| entries.into_iter().collect()))
}
}

impl<K, V, S> Arbitrary for HashMap<K, V, S>
impl<'a, K, V, S> Arbitrary<'a> for HashMap<K, V, S>
where
K: Arbitrary + Hash + Eq + Clone,
V: Arbitrary + Clone,
K: Arbitrary<'a> + Hash + Eq + Clone,
V: Arbitrary<'a> + Clone,
S: BuildHasher + Default + 'static,
{
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}

fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
u.arbitrary_take_rest_iter()?.collect()
}

Expand All @@ -125,24 +75,18 @@ where
size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
})
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let collections =
shrink_collection(self.iter(), |(k, v)| Box::new(k.shrink().zip(v.shrink())));
Box::new(collections.map(|entries| entries.into_iter().collect()))
}
}

impl<A, S> Arbitrary for HashSet<A, S>
impl<'a, A, S> Arbitrary<'a> for HashSet<A, S>
where
A: Arbitrary + Hash + Eq + Clone,
A: Arbitrary<'a> + Hash + Eq + Clone,
S: BuildHasher + Default + 'static,
{
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}

fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
u.arbitrary_take_rest_iter()?.collect()
}

Expand All @@ -151,9 +95,4 @@ where
size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
})
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
let collections = shrink_collection(self.iter(), |v| v.shrink());
Box::new(collections.map(|entries| entries.into_iter().collect()))
}
}
10 changes: 5 additions & 5 deletions src/quickcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use std::hash::{BuildHasher, Hash};
use std::iter::FromIterator;

impl<A: Arbitrary + Sync + Clone> Arbitrary for Vector<A> {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
Vector::from_iter(Vec::<A>::arbitrary(g))
}
}

impl<K: Ord + Clone + Arbitrary + Sync, V: Clone + Arbitrary + Sync> Arbitrary for OrdMap<K, V> {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
OrdMap::from_iter(Vec::<(K, V)>::arbitrary(g))
}
}

impl<A: Ord + Clone + Arbitrary + Sync> Arbitrary for OrdSet<A> {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
OrdSet::from_iter(Vec::<A>::arbitrary(g))
}
}
Expand All @@ -26,7 +26,7 @@ where
A: Hash + Eq + Arbitrary + Sync,
S: BuildHasher + Default + Send + Sync + 'static,
{
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
HashSet::from_iter(Vec::<A>::arbitrary(g))
}
}
Expand All @@ -37,7 +37,7 @@ where
V: Arbitrary + Sync,
S: BuildHasher + Default + Send + Sync + 'static,
{
fn arbitrary<G: Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
HashMap::from(Vec::<(K, V)>::arbitrary(g))
}
}
2 changes: 1 addition & 1 deletion src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ mod test {
assert!(input.ptr_eq(&inp2));
inp2.set(len - 1, 98);
assert_ne!(inp2.get(len - 1), input.get(len - 1));
assert!(!input.ptr_eq(&inp2), "{}", len);
assert!(!input.ptr_eq(&inp2));
}
}

Expand Down

0 comments on commit 546e59b

Please sign in to comment.