Skip to content

Faster iterator for arbitrary order #469

Open
@jturner314

Description

@jturner314

.iter() provides an iterator over all the elements, but it always iterates in logical order, which may be slow depending on the memory layout of the array. In some cases, however, the order of iteration doesn't matter. Recent issues regarding these types of cases include #466 and #468. Examples of methods where order doesn't matter include the most common uses of these from the Iterator trait

  • .fold()
  • .for_each()
  • .all() and .any()
  • .find()
  • .min(), .max(), .min_by(), .max_by(), .min_by_key(), .max_by_key()
  • .sum(), .product()

and these from Itertools

  • .cartesian_product()
  • .unique(), .unique_by()
  • .combinations()
  • .all_equal()
  • .foreach()
  • .fold_results(), .fold_options(), .fold1(), .tree_fold(), .fold_while()
  • .sorted(), .sorted_by(), .sorted_by_key()
  • .partition_map()
  • .into_group_map()
  • .minmax(), .minmax_by_key(), minmax_by()

We have already implemented some of these "arbitrary order" adapters as individual methods on ArrayBase, including .fold(), .scalar_sum(), and .visit(). However, it doesn't make sense to create separate methods for all of the possible iterator adapters.

As a result, I'd like to add "arbitrary order" .iter(), .iter_mut(), .indexed_iter(), and .indexed_iter_mut() methods designed to iterate in the fastest possible order so that we can hopefully get good performance with iterator adapters.

What does everyone think these "arbitrary order" iterators should be named?

I've thought of .iter_arbitrary() and .iter_unordered(), but those names seem somewhat unclear and unnecessarily verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions