itertools-0.8.0/.gitignore 0100644 0001751 0001751 00000000024 13143573266 0013764 0 ustar 00 0000000 0000000 /target/
Cargo.lock
itertools-0.8.0/.travis.yml 0100644 0001751 0001751 00000000733 13403265541 0014105 0 ustar 00 0000000 0000000 language: rust
sudo: false
matrix:
include:
- rust: 1.24.0
- rust: stable
- rust: beta
- rust: nightly
env:
- BENCH=1
branches:
only:
- master
# bors branches
- staging
- trying
script:
- |
cargo build --verbose --no-default-features &&
cargo build --verbose --features "$FEATURES" &&
cargo test --verbose --features "$FEATURES" &&
([ "$BENCH" != 1 ] || cargo bench --verbose --features "$FEATURES")
itertools-0.8.0/Cargo.toml.orig 0100644 0001751 0001751 00000001463 13403265541 0014664 0 ustar 00 0000000 0000000 [package]
name = "itertools"
version = "0.8.0"
license = "MIT/Apache-2.0"
repository = "https://github.com/bluss/rust-itertools"
documentation = "https://docs.rs/itertools/"
authors = ["bluss"]
description = "Extra iterator adaptors, iterator methods, free functions, and macros."
keywords = ["iterator", "data-structure", "zip", "product", "group-by"]
categories = ["algorithms", "rust-patterns"]
exclude = ["/bors.toml"]
[lib]
bench = false
test = false
[dependencies]
either = { version = "1.0", default-features = false }
[dev-dependencies]
rand = "0.6"
[dev-dependencies.quickcheck]
version = "0.7"
default-features = false
[dev-dependencies.permutohedron]
version = "0.2"
[features]
default = ["use_std"]
use_std = []
[profile]
bench = { debug = true }
[package.metadata.release]
no-dev-version = true
itertools-0.8.0/Cargo.toml 0000644 00000002463 00000000000 0011127 0 ustar 00 # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "itertools"
version = "0.8.0"
authors = ["bluss"]
exclude = ["/bors.toml"]
description = "Extra iterator adaptors, iterator methods, free functions, and macros."
documentation = "https://docs.rs/itertools/"
keywords = ["iterator", "data-structure", "zip", "product", "group-by"]
categories = ["algorithms", "rust-patterns"]
license = "MIT/Apache-2.0"
repository = "https://github.com/bluss/rust-itertools"
[package.metadata.release]
no-dev-version = true
[profile.bench]
debug = true
[lib]
test = false
bench = false
[dependencies.either]
version = "1.0"
default-features = false
[dev-dependencies.permutohedron]
version = "0.2"
[dev-dependencies.quickcheck]
version = "0.7"
default-features = false
[dev-dependencies.rand]
version = "0.6"
[features]
default = ["use_std"]
use_std = []
itertools-0.8.0/LICENSE-APACHE 0100644 0001751 0001751 00000025137 13143573266 0013734 0 ustar 00 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
itertools-0.8.0/LICENSE-MIT 0100644 0001751 0001751 00000002023 13143573266 0013431 0 ustar 00 0000000 0000000 Copyright (c) 2015
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
itertools-0.8.0/README.rst 0100644 0001751 0001751 00000035661 13403265541 0013473 0 ustar 00 0000000 0000000
Itertools
=========
Extra iterator adaptors, functions and macros.
Please read the `API documentation here`__
__ https://docs.rs/itertools/
|build_status|_ |crates|_
.. |build_status| image:: https://travis-ci.org/bluss/rust-itertools.svg?branch=master
.. _build_status: https://travis-ci.org/bluss/rust-itertools
.. |crates| image:: http://meritbadge.herokuapp.com/itertools
.. _crates: https://crates.io/crates/itertools
How to use with cargo:
.. code:: toml
[dependencies]
itertools = "0.8"
How to use in your crate:
.. code:: rust
#[macro_use] extern crate itertools;
use itertools::Itertools;
How to contribute
-----------------
- Fix a bug or implement a new thing
- Include tests for your new feature, preferably a quickcheck test
- Make a Pull Request
For new features, please first consider filing a PR to `rust-lang/rust `_,
adding your new feature to the `Iterator` trait of the standard library, if you believe it is reasonable.
If it isn't accepted there, proposing it for inclusion in ``itertools`` is a good idea.
The reason for doing is this is so that we avoid future breakage as with ``.flatten()``.
However, if your feature involves heap allocation, such as storing elements in a ``Vec``,
then it can't be accepted into ``libcore``, and you should propose it for ``itertools`` directly instead.
Recent Changes
--------------
- 0.8.0
- Added new adaptor ``.map_into()`` for conversions using ``Into`` by @vorner
- Improved ``Itertools`` docs by @JohnHeitmann
- The return type of ``.sorted/_by/_by_key()`` is now an iterator, not a Vec.
- The return type of the ``izip!(x, y)`` macro with exactly two arguments
is now the usual ``Iterator::zip``.
- Remove ``.flatten()`` in favour of std's ``.flatten()``
- Deprecate ``.foreach()`` in favour of std's ``.for_each()``
- Deprecate ``.step()`` in favour of std's ``.step_by()``
- Deprecate ``repeat_call`` in favour of std's ``repeat_with``
- Deprecate ``.fold_while()`` in favour of std's ``.try_fold()``
- Require Rust 1.24 as minimal version.
- 0.7.11
- Add convenience methods to ``EitherOrBoth``, making it more similar to ``Option``
and ``Either`` by @jethrogb
- 0.7.10
- No changes.
- 0.7.9
- New inclusion policy: See the readme about suggesting features for std before
accepting them in itertools.
- The ``FoldWhile`` type now implements ``Eq`` and ``PartialEq`` by @jturner314
- 0.7.8
- Add new iterator method ``.tree_fold1()`` which is like ``.fold1()``
except items are combined in a tree structure (see its docs).
By @scottmcm
- Add more ``Debug`` impls by @phimuemue: KMerge, KMergeBy, MergeJoinBy,
ConsTuples, Intersperse, ProcessResults, RcIter, Tee, TupleWindows, Tee,
ZipLongest, ZipEq, Zip.
- 0.7.7
- Add new iterator method ``.into_group_map() -> HashMap>``
which turns an iterator of ``(K, V)`` elements into such a hash table,
where values are grouped by key. By @tobz1000
- Add new free function ``flatten`` for the ``.flatten()`` adaptor.
**NOTE:** recent Rust nightlies have ``Iterator::flatten`` and thus a clash
with our flatten adaptor. One workaround is to use the itertools ``flatten``
free function.
- 0.7.6
- Add new adaptor ``.multi_cartesian_product()`` which is an n-ary product
iterator by @tobz1000
- Add new method ``.sorted_by_key()`` by @Xion
- Provide simpler and faster ``.count()`` for ``.unique()`` and ``.unique_by()``
- 0.7.5
- ``.multipeek()`` now implements ``PeekingNext``, by @nicopap.
- 0.7.4
- Add new adaptor ``.update()`` by @lucasem; this adaptor is used
to modify an element before passing it on in an iterator chain.
- 0.7.3
- Add new method ``.collect_tuple()`` by @matklad; it makes a tuple out of
the iterator's elements if the number of them matches **exactly**.
- Implement ``fold`` and ``collect`` for ``.map_results()`` which means
it reuses the code of the standard ``.map()`` for these methods.
- 0.7.2
- Add new adaptor ``.merge_join_by`` by @srijs; a heterogeneous merge join
for two ordered sequences.
- 0.7.1
- Iterator adaptors and iterators in itertools now use the same ``must_use``
reminder that the standard library adaptors do, by @matematikaedit and @bluss
*“iterator adaptors are lazy and do nothing unless consumed”*.
- 0.7.0
- Faster ``izip!()`` by @krdln
- ``izip!()`` is now a wrapper for repeated regular ``.zip()`` and
a single ``.map()``. This means it optimizes as well as the standard
library ``.zip()`` it uses.
**Note:** ``multizip`` and ``izip!()`` are now different! The former
has a named type but the latter optimizes better.
- Faster ``.unique()``
- ``no_std`` support, which is opt-in!
- Many lovable features are still there without std, like ``izip!()``
or ``.format()`` or ``.merge()``, but not those that use collections.
- Trait bounds were required up front instead of just on the type:
``group_by``'s ``PartialEq`` by @Phlosioneer and ``repeat_call``'s
``FnMut``.
- Removed deprecated constructor ``Zip::new`` — use ``izip!()`` or ``multizip()``
- 0.6.5
- Fix bug in ``.cartesian_product()``'s fold (which only was visible for
unfused iterators).
- 0.6.4
- Add specific ``fold`` implementations for ``.cartesian_product()`` and
``cons_tuples()``, which improves their performance in fold, foreach, and
iterator consumers derived from them.
- 0.6.3
- Add iterator adaptor ``.positions(predicate)`` by @tmccombs
- 0.6.2
- Add function ``process_results`` which can “lift” a function of the regular
values of an iterator so that it can process the ``Ok`` values from an
iterator of ``Results`` instead, by @shepmaster
- Add iterator method ``.concat()`` which combines all iterator elements
into a single collection using the ``Extend`` trait, by @srijs
- 0.6.1
- Better size hint testing and subsequent size hint bugfixes by @rkarp.
Fixes bugs in product, interleave_shortest size hints.
- New iterator method ``.all_equal()`` by @phimuemue
- 0.6.0
- Deprecated names were removed in favour of their replacements
- ``.flatten()`` does not implement double ended iteration anymore
- ``.fold_while()`` uses ``&mut self`` and returns ``FoldWhile``, for
composability (#168)
- ``.foreach()`` and ``.fold1()`` use ``self``, like ``.fold()`` does.
- ``.combinations(0)`` now produces a single empty vector. (#174)
- 0.5.10
- Add itertools method ``.kmerge_by()`` (and corresponding free function)
- Relaxed trait requirement of ``.kmerge()`` and ``.minmax()`` to PartialOrd.
- 0.5.9
- Add multipeek method ``.reset_peek()``
- Add categories
- 0.5.8
- Add iterator adaptor ``.peeking_take_while()`` and its trait ``PeekingNext``.
- 0.5.7
- Add iterator adaptor ``.with_position()``
- Fix multipeek's performance for long peeks by using ``VecDeque``.
- 0.5.6
- Add ``.map_results()``
- 0.5.5
- Many more adaptors now implement ``Debug``
- Add free function constructor ``repeat_n``. ``RepeatN::new`` is now
deprecated.
- 0.5.4
- Add infinite generator function ``iterate``, that takes a seed and a
closure.
- 0.5.3
- Special-cased ``.fold()`` for flatten and put back. ``.foreach()``
now uses fold on the iterator, to pick up any iterator specific loop
implementation.
- ``.combinations(n)`` asserts up front that ``n != 0``, instead of
running into an error on the second iterator element.
- 0.5.2
- Add ``.tuples::()`` that iterates by two, three or four elements at
a time (where ``T`` is a tuple type).
- Add ``.tuple_windows::()`` that iterates using a window of the
two, three or four most recent elements.
- Add ``.next_tuple::()`` method, that picks the next two, three or four
elements in one go.
- ``.interleave()`` now has an accurate size hint.
- 0.5.1
- Workaround module/function name clash that made racer crash on completing
itertools. Only internal changes needed.
- 0.5.0
- `Release announcement `_
- Renamed:
- combinations is now tuple_combinations
- combinations_n to combinations
- group_by_lazy, chunks_lazy to group_by, chunks
- Unfold::new to unfold()
- RepeatCall::new to repeat_call()
- Zip::new to multizip
- PutBack::new, PutBackN::new to put_back, put_back_n
- PutBack::with_value is now a builder setter, not a constructor
- MultiPeek::new, .multipeek() to multipeek()
- format to format_with and format_default to format
- .into_rc() to rciter
- ``Partition`` enum is now ``Either``
- Module reorganization:
- All iterator structs are under ``itertools::structs`` but also
reexported to the top level, for backwards compatibility
- All free functions are reexported at the root, ``itertools::free`` will
be removed in the next version
- Removed:
- ZipSlices, use .zip() instead
- .enumerate_from(), ZipTrusted, due to being unstable
- .mend_slices(), moved to crate odds
- Stride, StrideMut, moved to crate odds
- linspace(), moved to crate itertools-num
- .sort_by(), use .sorted_by()
- .is_empty_hint(), use .size_hint()
- .dropn(), use .dropping()
- .map_fn(), use .map()
- .slice(), use .take() / .skip()
- helper traits in misc
- ``new`` constructors on iterator structs, use Itertools trait or free
functions instead
- ``itertools::size_hint`` is now private
- Behaviour changes:
- format and format_with helpers now panic if you try to format them more
than once.
- ``repeat_call`` is not double ended anymore
- New features:
- tuple flattening iterator is constructible with ``cons_tuples``
- itertools reexports ``Either`` from the ``either`` crate. ``Either``
is an iterator when ``L, R`` are.
- ``MinMaxResult`` now implements Copy and Clone
- tuple_combinations supports 1-4 tuples of combinations (previously just 2)
- 0.4.19
- Add ``.minmax_by()``
- Add ``itertools::free::cloned``
- Add ``itertools::free::rciter``
- Improve ``.step(n)`` slightly to take advantage of specialized Fuse better.
- 0.4.18
- Only changes related to the "unstable" crate feature. This feature is more
or less deprecated.
- Use deprecated warnings when unstable is enabled. .enumerate_from() will
be removed imminently since it's using a deprecated libstd trait.
- 0.4.17
- Fix bug in .kmerge() that caused it to often produce the wrong order (#134)
- 0.4.16
- Improve precision of the interleave_shortest adaptor's size hint (it is
now computed exactly when possible).
- 0.4.15
- Fixup on top of the workaround in 0.4.14. A function in itertools::free was
removed by mistake and now it is added back again.
- 0.4.14
- Workaround an upstream regression in a rust nightly build that broke
compilation of of itertools::free::{interleave, merge}
- 0.4.13
- Add .minmax() and .minmax_by_key(), iterator methods for finding both minimum
and maximum in one scan.
- Add .format_default(), a simpler version of .format() (lazy formatting
for iterators).
- 0.4.12
- Add .zip_eq(), an adaptor like .zip() except it ensures iterators
of inequal length don't pass silently (instead it panics).
- Add .fold_while(), an iterator method that is a fold that
can short-circuit.
- Add .partition_map(), an iterator method that can separate elements
into two collections.
- 0.4.11
- Add .get() for Stride{,Mut} and .get_mut() for StrideMut
- 0.4.10
- Improve performance of .kmerge()
- 0.4.9
- Add k-ary merge adaptor .kmerge()
- Fix a bug in .islice() with ranges a..b where a > b.
- 0.4.8
- Implement Clone, Debug for Linspace
- 0.4.7
- Add function diff_with() that compares two iterators
- Add .combinations_n(), an n-ary combinations iterator
- Add methods PutBack::with_value and PutBack::into_parts.
- 0.4.6
- Add method .sorted()
- Add module ``itertools::free`` with free function variants of common
iterator adaptors and methods.
For example ``enumerate(iterable)``, ``rev(iterable)``, and so on.
- 0.4.5
- Add .flatten()
- 0.4.4
- Allow composing ZipSlices with itself
- 0.4.3
- Write iproduct!() as a single expression; this allows temporary values
in its arguments.
- 0.4.2
- Add .fold_options()
- Require Rust 1.1 or later
- 0.4.1
- Update .dropping() to take advantage of .nth()
- 0.4.0
- .merge(), .unique() and .dedup() now perform better due to not using
function pointers
- Add free functions enumerate() and rev()
- Breaking changes:
- Return types of .merge() and .merge_by() renamed and changed
- Method Merge::new removed
- .merge_by() now takes a closure that returns bool.
- Return type of .dedup() changed
- Return type of .mend_slices() changed
- Return type of .unique() changed
- Removed function times(), struct Times: use a range instead
- Removed deprecated macro icompr!()
- Removed deprecated FnMap and method .fn_map(): use .map_fn()
- .interleave_shortest() is no longer guaranteed to act like fused
- 0.3.25
- Rename .sort_by() to .sorted_by(). Old name is deprecated.
- Fix well-formedness warnings from RFC 1214, no user visible impact
- 0.3.24
- Improve performance of .merge()'s ordering function slightly
- 0.3.23
- Added .chunks(), similar to (and based on) .group_by_lazy().
- Tweak linspace to match numpy.linspace and make it double ended.
- 0.3.22
- Added ZipSlices, a fast zip for slices
- 0.3.21
- Remove `Debug` impl for `Format`, it will have different use later
- 0.3.20
- Optimize .group_by_lazy()
- 0.3.19
- Added .group_by_lazy(), a possibly nonallocating group by
- Added .format(), a nonallocating formatting helper for iterators
- Remove uses of RandomAccessIterator since it has been deprecated in rust.
- 0.3.17
- Added (adopted) Unfold from rust
- 0.3.16
- Added adaptors .unique(), .unique_by()
- 0.3.15
- Added method .sort_by()
- 0.3.14
- Added adaptor .while_some()
- 0.3.13
- Added adaptor .interleave_shortest()
- Added adaptor .pad_using()
- 0.3.11
- Added assert_equal function
- 0.3.10
- Bugfix .combinations() size_hint.
- 0.3.8
- Added source RepeatCall
- 0.3.7
- Added adaptor PutBackN
- Added adaptor .combinations()
- 0.3.6
- Added itertools::partition, partition a sequence in place based on a predicate.
- Deprecate icompr!() with no replacement.
- 0.3.5
- .map_fn() replaces deprecated .fn_map().
- 0.3.4
- .take_while_ref() *by-ref adaptor*
- .coalesce() *adaptor*
- .mend_slices() *adaptor*
- 0.3.3
- .dropping_back() *method*
- .fold1() *method*
- .is_empty_hint() *method*
License
-------
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0 or the MIT license
http://opensource.org/licenses/MIT, at your
option. This file may not be copied, modified, or distributed
except according to those terms.
itertools-0.8.0/benches/bench1.rs 0100644 0001751 0001751 00000036522 13376212402 0015113 0 ustar 00 0000000 0000000 #![feature(test)]
extern crate test;
#[macro_use] extern crate itertools;
use test::{black_box};
use itertools::Itertools;
use itertools::free::cloned;
use std::iter::repeat;
use std::cmp;
use std::ops::Add;
mod extra;
use extra::ZipSlices;
#[bench]
fn slice_iter(b: &mut test::Bencher)
{
let xs: Vec<_> = repeat(1i32).take(20).collect();
b.iter(|| for elt in xs.iter() {
test::black_box(elt);
})
}
#[bench]
fn slice_iter_rev(b: &mut test::Bencher)
{
let xs: Vec<_> = repeat(1i32).take(20).collect();
b.iter(|| for elt in xs.iter().rev() {
test::black_box(elt);
})
}
#[bench]
fn zip_default_zip(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
for (&x, &y) in xs.iter().zip(&ys) {
test::black_box(x);
test::black_box(y);
}
})
}
#[bench]
fn zipdot_i32_default_zip(b: &mut test::Bencher)
{
let xs = vec![2; 1024];
let ys = vec![2; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let mut s = 0;
for (&x, &y) in xs.iter().zip(&ys) {
s += x * y;
}
s
})
}
#[bench]
fn zipdot_f32_default_zip(b: &mut test::Bencher)
{
let xs = vec![2f32; 1024];
let ys = vec![2f32; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let mut s = 0.;
for (&x, &y) in xs.iter().zip(&ys) {
s += x * y;
}
s
})
}
#[bench]
fn zip_default_zip3(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let zs = vec![0; 766];
let xs = black_box(xs);
let ys = black_box(ys);
let zs = black_box(zs);
b.iter(|| {
for ((&x, &y), &z) in xs.iter().zip(&ys).zip(&zs) {
test::black_box(x);
test::black_box(y);
test::black_box(z);
}
})
}
#[bench]
fn zip_slices_ziptuple(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
b.iter(|| {
let xs = black_box(&xs);
let ys = black_box(&ys);
for (&x, &y) in itertools::multizip((xs, ys)) {
test::black_box(x);
test::black_box(y);
}
})
}
#[bench]
fn zipslices(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
for (&x, &y) in ZipSlices::new(&xs, &ys) {
test::black_box(x);
test::black_box(y);
}
})
}
#[bench]
fn zipslices_mut(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let xs = black_box(xs);
let mut ys = black_box(ys);
b.iter(|| {
for (&x, &mut y) in ZipSlices::from_slices(&xs[..], &mut ys[..]) {
test::black_box(x);
test::black_box(y);
}
})
}
#[bench]
fn zipdot_i32_zipslices(b: &mut test::Bencher)
{
let xs = vec![2; 1024];
let ys = vec![2; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let mut s = 0i32;
for (&x, &y) in ZipSlices::new(&xs, &ys) {
s += x * y;
}
s
})
}
#[bench]
fn zipdot_f32_zipslices(b: &mut test::Bencher)
{
let xs = vec![2f32; 1024];
let ys = vec![2f32; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let mut s = 0.;
for (&x, &y) in ZipSlices::new(&xs, &ys) {
s += x * y;
}
s
})
}
#[bench]
fn zip_checked_counted_loop(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
// Must slice to equal lengths, and then bounds checks are eliminated!
let len = cmp::min(xs.len(), ys.len());
let xs = &xs[..len];
let ys = &ys[..len];
for i in 0..len {
let x = xs[i];
let y = ys[i];
test::black_box(x);
test::black_box(y);
}
})
}
#[bench]
fn zipdot_i32_checked_counted_loop(b: &mut test::Bencher)
{
let xs = vec![2; 1024];
let ys = vec![2; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
// Must slice to equal lengths, and then bounds checks are eliminated!
let len = cmp::min(xs.len(), ys.len());
let xs = &xs[..len];
let ys = &ys[..len];
let mut s = 0i32;
for i in 0..len {
s += xs[i] * ys[i];
}
s
})
}
#[bench]
fn zipdot_f32_checked_counted_loop(b: &mut test::Bencher)
{
let xs = vec![2f32; 1024];
let ys = vec![2f32; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
// Must slice to equal lengths, and then bounds checks are eliminated!
let len = cmp::min(xs.len(), ys.len());
let xs = &xs[..len];
let ys = &ys[..len];
let mut s = 0.;
for i in 0..len {
s += xs[i] * ys[i];
}
s
})
}
#[bench]
fn zipdot_f32_checked_counted_unrolled_loop(b: &mut test::Bencher)
{
let xs = vec![2f32; 1024];
let ys = vec![2f32; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
// Must slice to equal lengths, and then bounds checks are eliminated!
let len = cmp::min(xs.len(), ys.len());
let mut xs = &xs[..len];
let mut ys = &ys[..len];
let mut s = 0.;
let (mut p0, mut p1, mut p2, mut p3, mut p4, mut p5, mut p6, mut p7) =
(0., 0., 0., 0., 0., 0., 0., 0.);
// how to unroll and have bounds checks eliminated (by cristicbz)
// split sum into eight parts to enable vectorization (by bluss)
while xs.len() >= 8 {
p0 += xs[0] * ys[0];
p1 += xs[1] * ys[1];
p2 += xs[2] * ys[2];
p3 += xs[3] * ys[3];
p4 += xs[4] * ys[4];
p5 += xs[5] * ys[5];
p6 += xs[6] * ys[6];
p7 += xs[7] * ys[7];
xs = &xs[8..];
ys = &ys[8..];
}
s += p0 + p4;
s += p1 + p5;
s += p2 + p6;
s += p3 + p7;
for i in 0..xs.len() {
s += xs[i] * ys[i];
}
s
})
}
#[bench]
fn zip_unchecked_counted_loop(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let len = cmp::min(xs.len(), ys.len());
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
test::black_box(x);
test::black_box(y);
}
}
})
}
#[bench]
fn zipdot_i32_unchecked_counted_loop(b: &mut test::Bencher)
{
let xs = vec![2; 1024];
let ys = vec![2; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let len = cmp::min(xs.len(), ys.len());
let mut s = 0i32;
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
s += x * y;
}
}
s
})
}
#[bench]
fn zipdot_f32_unchecked_counted_loop(b: &mut test::Bencher)
{
let xs = vec![2.; 1024];
let ys = vec![2.; 768];
let xs = black_box(xs);
let ys = black_box(ys);
b.iter(|| {
let len = cmp::min(xs.len(), ys.len());
let mut s = 0f32;
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
s += x * y;
}
}
s
})
}
#[bench]
fn zip_unchecked_counted_loop3(b: &mut test::Bencher)
{
let xs = vec![0; 1024];
let ys = vec![0; 768];
let zs = vec![0; 766];
let xs = black_box(xs);
let ys = black_box(ys);
let zs = black_box(zs);
b.iter(|| {
let len = cmp::min(xs.len(), cmp::min(ys.len(), zs.len()));
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
let z = *zs.get_unchecked(i);
test::black_box(x);
test::black_box(y);
test::black_box(z);
}
}
})
}
#[bench]
fn group_by_lazy_1(b: &mut test::Bencher) {
let mut data = vec![0; 1024];
for (index, elt) in data.iter_mut().enumerate() {
*elt = index / 10;
}
let data = test::black_box(data);
b.iter(|| {
for (_key, group) in &data.iter().group_by(|elt| **elt) {
for elt in group {
test::black_box(elt);
}
}
})
}
#[bench]
fn group_by_lazy_2(b: &mut test::Bencher) {
let mut data = vec![0; 1024];
for (index, elt) in data.iter_mut().enumerate() {
*elt = index / 2;
}
let data = test::black_box(data);
b.iter(|| {
for (_key, group) in &data.iter().group_by(|elt| **elt) {
for elt in group {
test::black_box(elt);
}
}
})
}
#[bench]
fn slice_chunks(b: &mut test::Bencher) {
let data = vec![0; 1024];
let data = test::black_box(data);
let sz = test::black_box(10);
b.iter(|| {
for group in data.chunks(sz) {
for elt in group {
test::black_box(elt);
}
}
})
}
#[bench]
fn chunks_lazy_1(b: &mut test::Bencher) {
let data = vec![0; 1024];
let data = test::black_box(data);
let sz = test::black_box(10);
b.iter(|| {
for group in &data.iter().chunks(sz) {
for elt in group {
test::black_box(elt);
}
}
})
}
#[bench]
fn equal(b: &mut test::Bencher) {
let data = vec![7; 1024];
let l = data.len();
let alpha = test::black_box(&data[1..]);
let beta = test::black_box(&data[..l - 1]);
b.iter(|| {
itertools::equal(alpha, beta)
})
}
#[bench]
fn merge_default(b: &mut test::Bencher) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}
let mut y = 0;
for (i, elt) in data2.iter_mut().enumerate() {
*elt += y;
if i % 3 == 0 {
y += 3;
} else {
y += 0;
}
}
let data1 = test::black_box(data1);
let data2 = test::black_box(data2);
b.iter(|| {
data1.iter().merge(&data2).count()
})
}
#[bench]
fn merge_by_cmp(b: &mut test::Bencher) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}
let mut y = 0;
for (i, elt) in data2.iter_mut().enumerate() {
*elt += y;
if i % 3 == 0 {
y += 3;
} else {
y += 0;
}
}
let data1 = test::black_box(data1);
let data2 = test::black_box(data2);
b.iter(|| {
data1.iter().merge_by(&data2, PartialOrd::le).count()
})
}
#[bench]
fn merge_by_lt(b: &mut test::Bencher) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}
let mut y = 0;
for (i, elt) in data2.iter_mut().enumerate() {
*elt += y;
if i % 3 == 0 {
y += 3;
} else {
y += 0;
}
}
let data1 = test::black_box(data1);
let data2 = test::black_box(data2);
b.iter(|| {
data1.iter().merge_by(&data2, |a, b| a <= b).count()
})
}
#[bench]
fn kmerge_default(b: &mut test::Bencher) {
let mut data1 = vec![0; 1024];
let mut data2 = vec![0; 800];
let mut x = 0;
for (_, elt) in data1.iter_mut().enumerate() {
*elt = x;
x += 1;
}
let mut y = 0;
for (i, elt) in data2.iter_mut().enumerate() {
*elt += y;
if i % 3 == 0 {
y += 3;
} else {
y += 0;
}
}
let data1 = test::black_box(data1);
let data2 = test::black_box(data2);
let its = &[data1.iter(), data2.iter()];
b.iter(|| {
its.iter().cloned().kmerge().count()
})
}
#[bench]
fn kmerge_tenway(b: &mut test::Bencher) {
let mut data = vec![0; 10240];
let mut state = 1729u16;
fn rng(state: &mut u16) -> u16 {
let new = state.wrapping_mul(31421) + 6927;
*state = new;
new
}
for elt in &mut data {
*elt = rng(&mut state);
}
let mut chunks = Vec::new();
let mut rest = &mut data[..];
while rest.len() > 0 {
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);
fst.sort();
chunks.push(fst.iter().cloned());
rest = tail;
}
// println!("Chunk lengths: {}", chunks.iter().format_with(", ", |elt, f| f(&elt.len())));
b.iter(|| {
chunks.iter().cloned().kmerge().count()
})
}
fn fast_integer_sum(iter: I) -> I::Item
where I: IntoIterator,
I::Item: Default + Add