Skip to content

Commit

Permalink
Merge branch 'master' into add-cargo-semver-check-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet authored Jan 18, 2024
2 parents 87ffed5 + 6c588cd commit 3f4462a
Show file tree
Hide file tree
Showing 44 changed files with 1,908 additions and 623 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: CI

on:
pull_request:
paths-ignore:
- "**.md"
merge_group:
paths-ignore:
- "**.md"

jobs:
check:
Expand All @@ -19,7 +23,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: RUSTFLAGS="--deny warnings" cargo check ${{ matrix.features }}
with:
components: clippy
- run: RUSTFLAGS="--deny warnings" cargo clippy ${{ matrix.features }}

doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: RUSTDOCFLAGS="-Dwarnings" cargo doc --all-features

msrv:
runs-on: ubuntu-latest
Expand All @@ -28,7 +41,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@cargo-no-dev-deps
- uses: dtolnay/[email protected]
- uses: dtolnay/rust-toolchain@master
with:
# Here, it does not trigger a PR from dependabot.
toolchain: 1.43.1
- run: cargo no-dev-deps check

test:
Expand Down Expand Up @@ -63,7 +79,7 @@ jobs:
name: All checks succeeded
if: success()
runs-on: ubuntu-latest
needs: [check, msrv, test, check-format, semver-checks]
needs: [check, msrv, test, check-format, doc, semver-checks]
steps:
- name: Mark the job as successful
run: exit 0
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# Changelog

## 0.12.0

### Breaking
- Made `take_while_inclusive` consume iterator by value (#709)
- Added `Clone` bound to `Unique` (#777)

### Added
- Added `Itertools::try_len` (#723)
- Added free function `sort_unstable` (#796)
- Added `GroupMap::fold_with` (#778, #785)
- Added `PeekNth::{peek_mut, peek_nth_mut}` (#716)
- Added `PeekNth::{next_if, next_if_eq}` (#734)
- Added conversion into `(Option<A>,Option<B>)` to `EitherOrBoth` (#713)
- Added conversion from `Either<A, B>` to `EitherOrBoth<A, B>` (#715)
- Implemented `ExactSizeIterator` for `Tuples` (#761)
- Implemented `ExactSizeIterator` for `(Circular)TupleWindows` (#752)
- Made `EitherOrBoth<T>` a shorthand for `EitherOrBoth<T, T>` (#719)

### Changed
- Added missing `#[must_use]` annotations on iterator adaptors (#794)
- Made `Combinations` lazy (#795)
- Made `Intersperse(With)` lazy (#797)
- Made `Permutations` lazy (#793)
- Made `Product` lazy (#800)
- Made `TupleWindows` lazy (#602)
- Specialized `Combinations::{count, size_hint}` (#729)
- Specialized `CombinationsWithReplacement::{count, size_hint}` (#737)
- Specialized `Powerset::fold` (#765)
- Specialized `Powerset::count` (#735)
- Specialized `TupleCombinations::{count, size_hint}` (#763)
- Specialized `TupleCombinations::fold` (#775)
- Specialized `WhileSome::fold` (#780)
- Specialized `WithPosition::fold` (#772)
- Specialized `ZipLongest::fold` (#774)
- Changed `{min, max}_set*` operations require `alloc` feature, instead of `std` (#760)
- Improved documentation of `tree_fold1` (#787)
- Improved documentation of `permutations` (#724)
- Fixed typo in documentation of `multiunzip` (#770)

### Notable Internal Changes
- Improved specialization tests (#799, #786, #782)
- Simplified implementation of `Permutations` (#739, #748, #790)
- Combined `Merge`/`MergeBy`/`MergeJoinBy` implementations (#736)
- Simplified `Permutations::size_hint` (#739)
- Fix wrapping arithmetic in benchmarks (#770)
- Enforced `rustfmt` in CI (#751)
- Disallowed compile warnings in CI (#720)
- Used `cargo hack` to check MSRV (#754)

## 0.11.0

### Breaking
Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "itertools"
version = "0.11.0"
version = "0.12.0"

license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-itertools/itertools"
Expand All @@ -12,10 +12,10 @@ description = "Extra iterator adaptors, iterator methods, free functions, and ma

keywords = ["iterator", "data-structure", "zip", "product", "group-by"]
categories = ["algorithms", "rust-patterns"]
exclude = ["/bors.toml"]

edition = "2018"

# When bumping, please resolve all `#[allow(clippy::*)]` that are newly resolvable.
rust-version = "1.43.1"

[lib]
Expand Down Expand Up @@ -71,3 +71,7 @@ harness = false
[[bench]]
name = "powerset"
harness = false

[[bench]]
name = "specializations"
harness = false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ How to use with Cargo:

```toml
[dependencies]
itertools = "0.11.0"
itertools = "0.12.0"
```

How to use in your crate:
Expand Down
135 changes: 28 additions & 107 deletions benches/bench1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use itertools::free::cloned;
use itertools::iproduct;
use itertools::Itertools;
use itertools::Position;
use itertools::{iproduct, EitherOrBoth};

use std::cmp;
use std::iter::repeat;
Expand Down Expand Up @@ -391,25 +390,6 @@ fn zip_unchecked_counted_loop3(c: &mut Criterion) {
});
}

fn ziplongest(c: &mut Criterion) {
let v1 = black_box((0..768).collect_vec());
let v2 = black_box((0..1024).collect_vec());
c.bench_function("ziplongest", move |b| {
b.iter(|| {
let zip = v1.iter().zip_longest(v2.iter());
let sum = zip.fold(0u32, |mut acc, val| {
match val {
EitherOrBoth::Both(x, y) => acc += x * y,
EitherOrBoth::Left(x) => acc += x,
EitherOrBoth::Right(y) => acc += y,
}
acc
});
sum
})
});
}

fn group_by_lazy_1(c: &mut Criterion) {
let mut data = vec![0; 1024];
for (index, elt) in data.iter_mut().enumerate() {
Expand Down Expand Up @@ -448,25 +428,6 @@ fn group_by_lazy_2(c: &mut Criterion) {
});
}

fn while_some(c: &mut Criterion) {
c.bench_function("while_some", |b| {
b.iter(|| {
let data = black_box(
(0..)
.fuse()
.map(|i| std::char::from_digit(i, 16))
.while_some(),
);
// let result: String = data.fold(String::new(), |acc, ch| acc + &ch.to_string());
let result = data.fold(String::new(), |mut acc, ch| {
acc.push(ch);
acc
});
assert_eq!(result.as_str(), "0123456789abcdef");
});
});
}

fn slice_chunks(c: &mut Criterion) {
let data = vec![0; 1024];

Expand Down Expand Up @@ -514,6 +475,8 @@ fn merge_default(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;

#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
Expand All @@ -540,6 +503,8 @@ fn merge_by_cmp(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;

#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
Expand All @@ -566,6 +531,8 @@ fn merge_by_lt(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;

#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
Expand All @@ -592,6 +559,8 @@ fn kmerge_default(c: &mut Criterion) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;

#[allow(clippy::explicit_counter_loop, clippy::unused_enumerate_index)]
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
Expand Down Expand Up @@ -631,7 +600,7 @@ fn kmerge_tenway(c: &mut Criterion) {

let mut chunks = Vec::new();
let mut rest = &mut data[..];
while rest.len() > 0 {
while !rest.is_empty() {
let chunk_len = 1 + rng(&mut state) % 512;
let chunk_len = cmp::min(rest.len(), chunk_len as usize);
let (fst, tail) = { rest }.split_at_mut(chunk_len);
Expand Down Expand Up @@ -687,6 +656,22 @@ fn step_range_10(c: &mut Criterion) {
});
}

fn vec_iter_mut_partition(c: &mut Criterion) {
let data = std::iter::repeat(-1024i32..1024)
.take(256)
.flatten()
.collect_vec();
c.bench_function("vec iter mut partition", move |b| {
b.iter_batched(
|| data.clone(),
|mut data| {
black_box(itertools::partition(black_box(&mut data), |n| *n >= 0));
},
BatchSize::LargeInput,
)
});
}

fn cartesian_product_iterator(c: &mut Criterion) {
let xs = vec![0; 16];

Expand All @@ -703,22 +688,6 @@ fn cartesian_product_iterator(c: &mut Criterion) {
});
}

fn cartesian_product_fold(c: &mut Criterion) {
let xs = vec![0; 16];

c.bench_function("cartesian product fold", move |b| {
b.iter(|| {
let mut sum = 0;
iproduct!(&xs, &xs, &xs).fold((), |(), (&x, &y, &z)| {
sum += x;
sum += y;
sum += z;
});
sum
})
});
}

fn multi_cartesian_product_iterator(c: &mut Criterion) {
let xs = [vec![0; 16], vec![0; 16], vec![0; 16]];

Expand All @@ -735,22 +704,6 @@ fn multi_cartesian_product_iterator(c: &mut Criterion) {
});
}

fn multi_cartesian_product_fold(c: &mut Criterion) {
let xs = [vec![0; 16], vec![0; 16], vec![0; 16]];

c.bench_function("multi cartesian product fold", move |b| {
b.iter(|| {
let mut sum = 0;
xs.iter().multi_cartesian_product().fold((), |(), x| {
sum += x[0];
sum += x[1];
sum += x[2];
});
sum
})
});
}

fn cartesian_product_nested_for(c: &mut Criterion) {
let xs = vec![0; 16];

Expand Down Expand Up @@ -839,33 +792,6 @@ fn permutations_slice(c: &mut Criterion) {
});
}

fn with_position_fold(c: &mut Criterion) {
let v = black_box((0..10240).collect_vec());
c.bench_function("with_position fold", move |b| {
b.iter(|| {
v.iter()
.with_position()
.fold(0, |acc, (pos, &item)| match pos {
Position::Middle => acc + item,
Position::First => acc - 2 * item,
Position::Last => acc + 2 * item,
Position::Only => acc + 5 * item,
})
})
});
}

fn tuple_combinations_fold(c: &mut Criterion) {
let v = black_box((0..64).collect_vec());
c.bench_function("tuple_combinations fold", move |b| {
b.iter(|| {
v.iter()
.tuple_combinations()
.fold(0, |acc, (a, b, c, d)| acc + *a * *c - *b * *d)
})
});
}

criterion_group!(
benches,
slice_iter,
Expand All @@ -887,7 +813,6 @@ criterion_group!(
zipdot_i32_unchecked_counted_loop,
zipdot_f32_unchecked_counted_loop,
zip_unchecked_counted_loop3,
ziplongest,
group_by_lazy_1,
group_by_lazy_2,
slice_chunks,
Expand All @@ -902,19 +827,15 @@ criterion_group!(
step_vec_10,
step_range_2,
step_range_10,
vec_iter_mut_partition,
cartesian_product_iterator,
cartesian_product_fold,
multi_cartesian_product_iterator,
multi_cartesian_product_fold,
cartesian_product_nested_for,
all_equal,
all_equal_for,
all_equal_default,
permutations_iter,
permutations_range,
permutations_slice,
with_position_fold,
tuple_combinations_fold,
while_some,
);
criterion_main!(benches);
Loading

0 comments on commit 3f4462a

Please sign in to comment.