Skip to content
Open
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
16 changes: 8 additions & 8 deletions benches/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,29 +355,29 @@ bench_specializations! {
}
v.iter().copied().update(|x| *x *= 7)
}
tuple_combinations1 {
array_combinations1 {
{
let v = black_box(vec![0; 1024]);
}
v.iter().tuple_combinations::<(_,)>()
v.iter().array_combinations::<1>()
}
tuple_combinations2 {
array_combinations2 {
{
let v = black_box(vec![0; 64]);
}
v.iter().tuple_combinations::<(_, _)>()
v.iter().array_combinations::<2>()
}
tuple_combinations3 {
array_combinations3 {
{
let v = black_box(vec![0; 64]);
}
v.iter().tuple_combinations::<(_, _, _)>()
v.iter().array_combinations::<3>()
}
tuple_combinations4 {
array_combinations4 {
{
let v = black_box(vec![0; 64]);
}
v.iter().tuple_combinations::<(_, _, _, _)>()
v.iter().array_combinations::<4>()
}
intersperse {
{
Expand Down
56 changes: 28 additions & 28 deletions benches/tuple_combinations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const N2: usize = 448;
const N3: usize = 86;
const N4: usize = 41;

fn tuple_comb_for1(c: &mut Criterion) {
c.bench_function("tuple comb for1", move |b| {
fn array_comb_for1(c: &mut Criterion) {
c.bench_function("array comb for1", move |b| {
b.iter(|| {
for i in 0..N1 {
black_box(i);
Expand All @@ -17,8 +17,8 @@ fn tuple_comb_for1(c: &mut Criterion) {
});
}

fn tuple_comb_for2(c: &mut Criterion) {
c.bench_function("tuple comb for2", move |b| {
fn array_comb_for2(c: &mut Criterion) {
c.bench_function("array comb for2", move |b| {
b.iter(|| {
for i in 0..N2 {
for j in (i + 1)..N2 {
Expand All @@ -29,8 +29,8 @@ fn tuple_comb_for2(c: &mut Criterion) {
});
}

fn tuple_comb_for3(c: &mut Criterion) {
c.bench_function("tuple comb for3", move |b| {
fn array_comb_for3(c: &mut Criterion) {
c.bench_function("array comb for3", move |b| {
b.iter(|| {
for i in 0..N3 {
for j in (i + 1)..N3 {
Expand All @@ -43,8 +43,8 @@ fn tuple_comb_for3(c: &mut Criterion) {
});
}

fn tuple_comb_for4(c: &mut Criterion) {
c.bench_function("tuple comb for4", move |b| {
fn array_comb_for4(c: &mut Criterion) {
c.bench_function("array comb for4", move |b| {
b.iter(|| {
for i in 0..N4 {
for j in (i + 1)..N4 {
Expand All @@ -59,40 +59,40 @@ fn tuple_comb_for4(c: &mut Criterion) {
});
}

fn tuple_comb_c1(c: &mut Criterion) {
c.bench_function("tuple comb c1", move |b| {
fn array_comb_c1(c: &mut Criterion) {
c.bench_function("array comb c1", move |b| {
b.iter(|| {
for (i,) in (0..N1).tuple_combinations() {
for [i] in (0..N1).array_combinations() {
black_box(i);
}
})
});
}

fn tuple_comb_c2(c: &mut Criterion) {
c.bench_function("tuple comb c2", move |b| {
fn array_comb_c2(c: &mut Criterion) {
c.bench_function("array comb c2", move |b| {
b.iter(|| {
for (i, j) in (0..N2).tuple_combinations() {
for [i, j] in (0..N2).array_combinations() {
black_box(i + j);
}
})
});
}

fn tuple_comb_c3(c: &mut Criterion) {
c.bench_function("tuple comb c3", move |b| {
fn array_comb_c3(c: &mut Criterion) {
c.bench_function("array comb c3", move |b| {
b.iter(|| {
for (i, j, k) in (0..N3).tuple_combinations() {
for [i, j, k] in (0..N3).array_combinations() {
black_box(i + j + k);
}
})
});
}

fn tuple_comb_c4(c: &mut Criterion) {
c.bench_function("tuple comb c4", move |b| {
fn array_comb_c4(c: &mut Criterion) {
c.bench_function("array comb c4", move |b| {
b.iter(|| {
for (i, j, k, l) in (0..N4).tuple_combinations() {
for [i, j, k, l] in (0..N4).array_combinations() {
black_box(i + j + k + l);
}
})
Expand All @@ -101,13 +101,13 @@ fn tuple_comb_c4(c: &mut Criterion) {

criterion_group!(
benches,
tuple_comb_for1,
tuple_comb_for2,
tuple_comb_for3,
tuple_comb_for4,
tuple_comb_c1,
tuple_comb_c2,
tuple_comb_c3,
tuple_comb_c4,
array_comb_for1,
array_comb_for2,
array_comb_for3,
array_comb_for4,
array_comb_c1,
array_comb_c2,
array_comb_c3,
array_comb_c4,
);
criterion_main!(benches);
4 changes: 2 additions & 2 deletions examples/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ fn main() {
let n = 30; // plot size
let mut plot = vec![' '; n * n];

// using Itertools::tuple_combinations
for (a, b) in (0..4).tuple_combinations() {
// using Itertools::array_combinations
for [a, b] in (0..4).array_combinations() {
println!("Column {a} vs {b}:");

// Clear plot
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,7 @@ pub trait Itertools: Iterator {
/// let it: TupleCombinations<Range<u32>, (u32, u32, u32)> = (1..5).tuple_combinations();
/// itertools::assert_equal(it, vec![(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]);
/// ```
#[deprecated(note = "Use .array_combinations() instead", since = "0.15.0")]
fn tuple_combinations<T>(self) -> TupleCombinations<Self, T>
where
Self: Sized,
Expand Down
12 changes: 12 additions & 0 deletions tests/laziness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,29 @@ must_use_tests! {
while_some {
let _ = Panicking.map(Some).while_some();
}
#[allow(deprecated)]
tuple_combinations1 {
let _ = Panicking.tuple_combinations::<(_,)>();
}
#[allow(deprecated)]
#[should_panic]
tuple_combinations2 {
let _ = Panicking.tuple_combinations::<(_, _)>();
}
#[allow(deprecated)]
#[should_panic]
tuple_combinations3 {
let _ = Panicking.tuple_combinations::<(_, _, _)>();
}
array_combinations1 {
let _ = Panicking.array_combinations::<1>();
}
array_combinations2 {
let _ = Panicking.array_combinations::<2>();
}
array_combinations3 {
let _ = Panicking.array_combinations::<3>();
}
combinations {
let _ = Panicking.combinations(0);
let _ = Panicking.combinations(1);
Expand Down
1 change: 1 addition & 0 deletions tests/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ quickcheck! {
test_double_ended_specializations(&it);
}

#[allow(deprecated)]
fn tuple_combinations(v: Vec<u8>) -> TestResult {
if v.len() > 10 {
return TestResult::discard();
Expand Down
12 changes: 9 additions & 3 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,9 +1066,15 @@ fn combinations() {
],
);

it::assert_equal((0..0).tuple_combinations::<(_, _)>(), <Vec<_>>::new());
it::assert_equal((0..1).tuple_combinations::<(_, _)>(), <Vec<_>>::new());
it::assert_equal((0..2).tuple_combinations::<(_, _)>(), vec![(0, 1)]);
#[allow(deprecated)]
{
it::assert_equal((0..0).tuple_combinations::<(_, _)>(), <Vec<_>>::new());
it::assert_equal((0..1).tuple_combinations::<(_, _)>(), <Vec<_>>::new());
it::assert_equal((0..2).tuple_combinations::<(_, _)>(), vec![(0, 1)]);
}
it::assert_equal((0..0).array_combinations::<2>(), <Vec<[isize; 2]>>::new());
it::assert_equal((0..1).array_combinations::<2>(), <Vec<[isize; 2]>>::new());
it::assert_equal((0..2).array_combinations::<2>(), vec![[0, 1]]);

it::assert_equal((0..0).combinations(2), <Vec<Vec<_>>>::new());
it::assert_equal((0..1).combinations(1), vec![vec![0]]);
Expand Down
Loading