Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/adaptors/coalesce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ where
fn size_hint(&self) -> (usize, Option<usize>) {
let (low, hi) = size_hint::add_scalar(
self.iter.size_hint(),
matches!(self.last, Some(Some(_))) as usize,
usize::from(matches!(self.last, Some(Some(_)))),
);
((low > 0) as usize, hi)
(usize::from(low > 0), hi)
}

fn fold<Acc, FnAcc>(self, acc: Acc, mut fn_acc: FnAcc) -> Acc
Expand Down
4 changes: 2 additions & 2 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ where
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
// Not ExactSizeIterator because size may be larger than usize
size_hint::add_scalar(self.iter.size_hint(), self.top.is_some() as usize)
size_hint::add_scalar(self.iter.size_hint(), usize::from(self.top.is_some()))
}

fn count(self) -> usize {
self.iter.count() + (self.top.is_some() as usize)
self.iter.count() + usize::from(self.top.is_some())
}

fn last(self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion src/kmerge_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
while child + 1 < heap.len() {
// pick the smaller of the two children
// use arithmetic to avoid an unpredictable branch
child += less_than(&heap[child + 1], &heap[child]) as usize;
child += usize::from(less_than(&heap[child + 1], &heap[child]));

// sift down is done if we are already in order
if !less_than(&heap[child], &heap[pos]) {
Expand Down
4 changes: 2 additions & 2 deletions src/unique_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let (low, hi) = self.iter.size_hint();
((low > 0 && self.used.is_empty()) as usize, hi)
(usize::from(low > 0 && self.used.is_empty()), hi)
}

fn count(self) -> usize {
Expand Down Expand Up @@ -119,7 +119,7 @@ where
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let (low, hi) = self.iter.iter.size_hint();
((low > 0 && self.iter.used.is_empty()) as usize, hi)
(usize::from(low > 0 && self.iter.used.is_empty()), hi)
}

fn count(self) -> usize {
Expand Down
50 changes: 25 additions & 25 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ quickcheck! {

let tup1 = |(_, b)| b;
for &(ord, consume_now) in &order {
let iter = &mut [&mut chunks1, &mut chunks2][ord as usize];
let iter = &mut [&mut chunks1, &mut chunks2][usize::from(ord)];
match iter.next() {
Some((_, gr)) => if consume_now {
for og in old_chunks.drain(..) {
Expand Down Expand Up @@ -1422,9 +1422,9 @@ quickcheck! {
}

fn correct_grouping_map_by_aggregate_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = if modulo < 2 { 2 } else { modulo } as u64; // Avoid `% 0`
let modulo = u64::from(if modulo < 2 { 2 } else { modulo }); // Avoid `% 0`
let lookup = a.iter()
.map(|&b| b as u64) // Avoid overflows
.map(|&b| u64::from(b)) // Avoid overflows
.into_grouping_map_by(|i| i % modulo)
.aggregate(|acc, &key, val| {
assert!(val % modulo == key);
Expand All @@ -1436,7 +1436,7 @@ quickcheck! {
});

let group_map_lookup = a.iter()
.map(|&b| b as u64)
.map(|&b| u64::from(b))
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
Expand All @@ -1456,7 +1456,7 @@ quickcheck! {
assert_eq!(
lookup.get(&m).copied(),
a.iter()
.map(|&b| b as u64)
.map(|&b| u64::from(b))
.filter(|&val| val % modulo == m)
.fold(None, |acc, val| {
if val % (modulo - 1) == 0 {
Expand All @@ -1475,8 +1475,8 @@ quickcheck! {
acc: u64,
}

let modulo = if modulo == 0 { 1 } else { modulo } as u64; // Avoid `% 0`
let lookup = a.iter().map(|&b| b as u64) // Avoid overflows
let modulo = u64::from(if modulo == 0 { 1 } else { modulo }); // Avoid `% 0`
let lookup = a.iter().map(|&b| u64::from(b)) // Avoid overflows
.into_grouping_map_by(|i| i % modulo)
.fold_with(|_key, _val| Default::default(), |Accumulator { acc }, &key, val| {
assert!(val % modulo == key);
Expand All @@ -1485,7 +1485,7 @@ quickcheck! {
});

let group_map_lookup = a.iter()
.map(|&b| b as u64)
.map(|&b| u64::from(b))
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
Expand All @@ -1494,21 +1494,21 @@ quickcheck! {
assert_eq!(lookup, group_map_lookup);

for (&key, &Accumulator { acc: sum }) in lookup.iter() {
assert_eq!(sum, a.iter().map(|&b| b as u64).filter(|&val| val % modulo == key).sum::<u64>());
assert_eq!(sum, a.iter().map(|&b| u64::from(b)).filter(|&val| val % modulo == key).sum::<u64>());
}
}

fn correct_grouping_map_by_fold_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = if modulo == 0 { 1 } else { modulo } as u64; // Avoid `% 0`
let lookup = a.iter().map(|&b| b as u64) // Avoid overflows
let modulo = u64::from(if modulo == 0 { 1 } else { modulo }); // Avoid `% 0`
let lookup = a.iter().map(|&b| u64::from(b)) // Avoid overflows
.into_grouping_map_by(|i| i % modulo)
.fold(0u64, |acc, &key, val| {
assert!(val % modulo == key);
acc + val
});

let group_map_lookup = a.iter()
.map(|&b| b as u64)
.map(|&b| u64::from(b))
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
Expand All @@ -1517,21 +1517,21 @@ quickcheck! {
assert_eq!(lookup, group_map_lookup);

for (&key, &sum) in lookup.iter() {
assert_eq!(sum, a.iter().map(|&b| b as u64).filter(|&val| val % modulo == key).sum::<u64>());
assert_eq!(sum, a.iter().map(|&b| u64::from(b)).filter(|&val| val % modulo == key).sum::<u64>());
}
}

fn correct_grouping_map_by_reduce_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = if modulo == 0 { 1 } else { modulo } as u64; // Avoid `% 0`
let lookup = a.iter().map(|&b| b as u64) // Avoid overflows
let modulo = u64::from(if modulo == 0 { 1 } else { modulo }); // Avoid `% 0`
let lookup = a.iter().map(|&b| u64::from(b)) // Avoid overflows
.into_grouping_map_by(|i| i % modulo)
.reduce(|acc, &key, val| {
assert!(val % modulo == key);
acc + val
});

let group_map_lookup = a.iter()
.map(|&b| b as u64)
.map(|&b| u64::from(b))
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
Expand All @@ -1540,7 +1540,7 @@ quickcheck! {
assert_eq!(lookup, group_map_lookup);

for (&key, &sum) in lookup.iter() {
assert_eq!(sum, a.iter().map(|&b| b as u64).filter(|&val| val % modulo == key).sum::<u64>());
assert_eq!(sum, a.iter().map(|&b| u64::from(b)).filter(|&val| val % modulo == key).sum::<u64>());
}
}

Expand Down Expand Up @@ -1706,12 +1706,12 @@ quickcheck! {
}

fn correct_grouping_map_by_sum_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = if modulo == 0 { 1 } else { modulo } as u64; // Avoid `% 0`
let lookup = a.iter().map(|&b| b as u64) // Avoid overflows
let modulo = u64::from(if modulo == 0 { 1 } else { modulo }); // Avoid `% 0`
let lookup = a.iter().map(|&b| u64::from(b)) // Avoid overflows
.into_grouping_map_by(|i| i % modulo)
.sum();

let group_map_lookup = a.iter().map(|&b| b as u64)
let group_map_lookup = a.iter().map(|&b| u64::from(b))
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
Expand All @@ -1720,17 +1720,17 @@ quickcheck! {
assert_eq!(lookup, group_map_lookup);

for (&key, &sum) in lookup.iter() {
assert_eq!(sum, a.iter().map(|&b| b as u64).filter(|&val| val % modulo == key).sum::<u64>());
assert_eq!(sum, a.iter().map(|&b| u64::from(b)).filter(|&val| val % modulo == key).sum::<u64>());
}
}

fn correct_grouping_map_by_product_modulo_key(a: Vec<u8>, modulo: u8) -> () {
let modulo = Wrapping(if modulo == 0 { 1 } else { modulo } as u64); // Avoid `% 0`
let lookup = a.iter().map(|&b| Wrapping(b as u64)) // Avoid overflows
let modulo = Wrapping(u64::from(if modulo == 0 { 1 } else { modulo })); // Avoid `% 0`
let lookup = a.iter().map(|&b| Wrapping(u64::from(b))) // Avoid overflows
.into_grouping_map_by(|i| i % modulo)
.product();

let group_map_lookup = a.iter().map(|&b| Wrapping(b as u64))
let group_map_lookup = a.iter().map(|&b| Wrapping(u64::from(b)))
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
Expand All @@ -1742,7 +1742,7 @@ quickcheck! {
assert_eq!(
prod,
a.iter()
.map(|&b| Wrapping(b as u64))
.map(|&b| Wrapping(u64::from(b)))
.filter(|&val| val % modulo == key)
.product::<Wrapping<u64>>()
);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ qc::quickcheck! {
fn k_smallest_range(n: i64, m: u16, k: u16) -> () {
// u16 is used to constrain k and m to 0..2¹⁶,
// otherwise the test could use too much memory.
let (k, m) = (k as usize, m as u64);
let (k, m) = (k as usize, u64::from(m));

let mut v: Vec<_> = (n..n.saturating_add(m as _)).collect();
// Generate a random permutation of n..n+m
Expand Down Expand Up @@ -532,7 +532,7 @@ qc::quickcheck! {
fn k_smallest_relaxed_range(n: i64, m: u16, k: u16) -> () {
// u16 is used to constrain k and m to 0..2¹⁶,
// otherwise the test could use too much memory.
let (k, m) = (k as usize, m as u64);
let (k, m) = (k as usize, u64::from(m));

let mut v: Vec<_> = (n..n.saturating_add(m as _)).collect();
// Generate a random permutation of n..n+m
Expand Down
Loading