Skip to content

Commit 2d051ae

Browse files
committed
Replace 'iterable' with either 'range', 'container' or 'collection'
1 parent 4ddc6d1 commit 2d051ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+909
-909
lines changed

benchmarks/benchmarking-tools/statistics.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* Copyright (c) 2020 Morwenn
2+
* Copyright (c) 2020-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#include <cmath>
66

77
// Simple statistics functions
88

9-
template<typename Iterable>
10-
auto average(const Iterable& values)
9+
template<typename Range>
10+
auto average(const Range& values)
1111
-> double
1212
{
1313
double avg = 0.0;
@@ -17,8 +17,8 @@ auto average(const Iterable& values)
1717
return avg;
1818
}
1919

20-
template<typename Iterable>
21-
auto standard_deviation(const Iterable& values, double avg)
20+
template<typename Range>
21+
auto standard_deviation(const Range& values, double avg)
2222
-> double
2323
{
2424
double stddev = 0.0;

docs/Benchmarks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ All of the graphs on this page have been generated with slightly modified versio
1515

1616
*The latest benchmarks were run on Windows 10 with 64-bit MinGW-w64 g++12.0, with the flags -O3 -march=native -std=c++20.*
1717

18-
# Random-access iterables
18+
# Random-access collections
1919

2020
Most sorting algorithms are designed to work with random-access iterators, so this section is deemed to be bigger than the other ones. Note that many of the algorithms work better with contiguous iterators; the results for `std::vector` and `std::deque` are probably different.
2121

@@ -76,7 +76,7 @@ The analysis is pretty simple here:
7676
* As a result `smooth_sort` and `poplar_sort` beat each other depending on the type of the collection to sort.
7777
* Slabsort has an unusual graph: even for shuffled data it might end up beating `heap_sort` when the collection becomes big enough.
7878

79-
# Bidirectional iterables
79+
# Bidirectional collections
8080

8181
Sorting algorithms that handle non-random-access iterators are often second class citizens, but **cpp-sort** still provides a few ones. The most interesting part is that we can see how generic sorting algorithms perform compared to algorithms such as [`std::list::sort`][std-list-sort] which are aware of the data structure they are sorting.
8282

@@ -92,14 +92,14 @@ For elements as small as `double`, there are two clear winners here: `drop_merge
9292
* `quick_sort` and `quick_merge_sort` are good enough contenders when trying to avoid heap memory allocations.
9393
* `mel_sort` is bad.
9494

95-
# Forward iterables
95+
# Forward collections
9696

9797
Even fewer sorters can handle forward iterators. `out_of_place_adapter(pdq_sort)` was not included in the patterns benchmark, because it adapts to patterns the same way `pdq_sort` does.
9898

9999
![Benchmark speed of sorts with increasing size for std::forward_list<double>](https://i.imgur.com/if15kX1.png)
100100
![Benchmark sorts over different patterns for std::forward_list<double>](https://i.imgur.com/uF0UzLm.png)
101101

102-
The results are roughly the same than with bidirectional iterables:
102+
The results are roughly the same than with bidirectional collections:
103103
* Sorting out-of-place is faster than anything else.
104104
* [`std::forward_list::sort`][std-forward-list-sort] doesn't scale well when moves are inexpensive.
105105
* `quick_sort` and `quick_merge_sort` are good enough contenders when trying to avoid heap memory allocations.

docs/Comparators.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ Partial order comparators are considered as [generating branchless code][branchl
6464
#include <cpp-sort/comparators/natural_less.h>
6565
```
6666

67-
The comparator `natural_less` is a [customization point][custom-point] that can be used to perform a [natural sort][natural-sort]. The function handles any two forward iterable sequences of `char` out of the box using [`std::isdigit`][std-is-digit] to identify digits (which includes `std::string`, `std::vector<char>` and `char[]`). Other character types and locales are currently not handled and it is unlikely that the library will evolve more than switching to `<locale>`'s `std::isdigit` instead of `<cctype>`'s one.
67+
The comparator `natural_less` is a [customization point][custom-point] that can be used to perform a [natural sort][natural-sort]. The function handles any two forward ranges of `char` out of the box using [`std::isdigit`][std-is-digit] to identify digits (which includes `std::string`, `std::vector<char>` and `char[]`). Other character types and locales are currently not handled and it is unlikely that the library will evolve more than switching to `<locale>`'s `std::isdigit` instead of `<cctype>`'s one.
6868

6969
### Case-insensitive comparator
7070

7171
```cpp
7272
#include <cpp-sort/comparators/case_insensitive_less.h>
7373
```
7474

75-
The comparator `case_insensitive_less` is a [customization point][custom-point] that be used to perform a [case-insensitive][case-sensitivity] sort on collections. The function handles any forward iterable sequence of `char` or `wchar_t` out of the box using [`std::ctype::tolower`][to-lower] prior to character comparison. The customization point has two distinct signatures:
75+
The comparator `case_insensitive_less` is a [customization point][custom-point] that be used to perform a [case-insensitive][case-sensitivity] sort on collections. The function handles any forward range of `char` or `wchar_t` out of the box using [`std::ctype::tolower`][to-lower] prior to character comparison. The customization point has two distinct signatures:
7676

7777
```cpp
7878
template<typename T>

docs/Fixed-size-sorters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Fixed-size sorters, sometimes called *fixed sorters* for simplicity are a special kind of sorters designed to sort a fixed number of values. Their `operator()` also takes either an iterable or a pair of iterators as well as an optional comparison and projection functions. Most of the time the end iterator is unused, but future versions of the library may start to use it to optionally perform bound-checking.
1+
Fixed-size sorters, sometimes called *fixed sorters* for simplicity are a special kind of sorters designed to sort a fixed number of values. Their `operator()` also takes either a range or a pair of iterators as well as an optional comparison and projection functions. Most of the time the end iterator is unused, but future versions of the library may start to use it to optionally perform bound-checking.
22

33
Fixed-size sorters are not actual sorters *per se* but class templates that take an `std::size_t` template parameter. Every valid specialization of a fixed-size sorter for a given size yields a "valid" sorter. Several fixed-size sorters have specializations for some sizes only and will trigger a compile-time error when one tries to instantiate a specialization which is not part of the fixed-size sorter's domain (the domain corresponds to the set of valid specializations). Information about fixed-size sorters can be obtained via [`fixed_sorter_traits`][fixed-sorter-traits]. One can also make sure that a given fixed-size sorter is automatically used to sort small fixed-size arrays thanks to [`small_array_adapter`][small-array-adapter].
44

docs/Library-nomenclature.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
* *Proxy iterator*: sometimes `std::move` and `std::swap` are not enough to correctly move values around, and we need to know more about the iterators in order to perform the appropriate operation. It's typically the case with proxy iterators: iterators whose `reference` type is not actually a reference type (*e.g.* `std::vector<bool>::reference`). Traditional algorithms don't play well with these types, however there are [standard proposals][p0022] to solve the problem by introducing a function named `iter_move` and making it as well as `iter_swap` customization points. No proposal has been accepted yet, so standard libraries don't handle proxy iterators; however every sorter in **cpp-sort** can actually handle such iterators (except `std_sorter` and `std_stable_sorter`). The library exposes the functions [`utility::iter_move` and `utility::iter_swap`][utility-iter-move] in case you also need to make your own algorithms handle proxy iterators.
4242

43-
* *Sorter*: [sorters][sorters] are the protagonists in this library. They are function objects implementing specific sorting algorithms. Their `operator()` is overloaded so that it can handle iterables or pairs of iterators, and conditionally overloaded so that it can handle user-provided comparison and/or projection functions (see *unified sorting interface*).
43+
* *Sorter*: [sorters][sorters] are the protagonists in this library. They are function objects implementing specific sorting algorithms. Their `operator()` is overloaded so that it can handle ranges or pairs of iterators, and conditionally overloaded so that it can handle user-provided comparison and/or projection functions (see *unified sorting interface*).
4444

4545
cppsort::pdq_sorter{}(std::begin(collection), std::end(collection),
4646
std::greater{}, &wrapper::value);
@@ -65,7 +65,7 @@
6565

6666
* *Type-specific sorter*: some non-comparison sorters such as the [`spread_sorter`][spread-sorter] implement specific sorting algorithms which only work with some specific types (for example integers or strings).
6767

68-
* *Unified sorting interface*: *sorters*, *sorter adapters*, *measures of presortedness* and a few other components of the library accept an iterable or a pair of iterators, and optionally a comparison function and/or a comparison function. Those components typically rely on the library's [`sorter_facade`][sorter-facade] which handles the dispatching to the component's implementation and to handle a number of special cases. For simplicity, what is accepted by the `operator()` of such components is referred to as the *unified sorting interface* in the rest of the library.
68+
* *Unified sorting interface*: *sorters*, *sorter adapters*, *measures of presortedness* and a few other components of the library accept a range or a pair of iterators, and optionally a comparison function and/or a comparison function. Those components typically rely on the library's [`sorter_facade`][sorter-facade] which handles the dispatching to the component's implementation and to handle a number of special cases. For simplicity, what is accepted by the `operator()` of such components is referred to as the *unified sorting interface* in the rest of the library.
6969

7070

7171
[comparators]: Comparators.md

docs/Measures-of-presortedness.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The measures of presortedness in bold in the graph are available in **cpp-sort**
3737

3838
## Measures of presortedness in cpp-sort
3939

40-
In **cpp-sort**, measures of presortedness are implemented as instances of some specific function objects. They take an iterable or a pair of iterators and return how much disorder there is in the sequence according to the measure. Measures of presortedness follow the *unified sorting interface*, allowing a certain degree a freedom in the parameters they accept:
40+
In **cpp-sort**, measures of presortedness are implemented as instances of some specific function objects. They take a range or a pair of iterators and return how much disorder there is in the sequence according to the measure. Measures of presortedness follow the *unified sorting interface*, allowing a certain degree a freedom in the parameters they accept:
4141

4242
```cpp
4343
using namespace cppsort;
@@ -146,7 +146,7 @@ Computes the minimum number of exchanges required to sort *X*, which corresponds
146146

147147
`max_for_size`: |*X*| - 1 when every element in *X* is one element away from its sorted position.
148148

149-
*Warning: this algorithm might be noticeably slower when the passed iterable is not random-access.*
149+
*Warning: this algorithm might be noticeably slower when the passed range is not random-access.*
150150

151151
### *Ham*
152152

docs/Miscellaneous-utilities.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ The algorithm requires both the elements range and the indices range to be mutab
3131
```cpp
3232
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
3333
auto apply_permutation(RandomAccessIterator1 first, RandomAccessIterator1 last,
34-
RandomAccessIterator2 indices_first, RandomAccessIterator2 indices_last)
34+
RandomAccessIterator2 indices_first, RandomAccessIterator2 indices_last)
3535
-> void;
3636

37-
template<typename RandomAccessIterable1, typename RandomAccessIterable2>
38-
auto apply_permutation(RandomAccessIterable1&& iterable, RandomAccessIterable2&& indices)
37+
template<typename RandomAccessRange1, typename RandomAccessRange2>
38+
auto apply_permutation(RandomAccessRange1&& range, RandomAccessRange2&& indices)
3939
-> void;
4040
```
4141
@@ -375,7 +375,7 @@ auto m = get<foo_tag>(mm);
375375

376376
***WARNING:** this header is removed in version 3.0.0, use `mstd::distance` instead.*
377377

378-
`size` is a function that can be used to get the size of an iterable. It is equivalent to the C++17 function [`std::size`][std-size] but has an additional tweak so that, if the iterable is not a fixed-size C array and doesn't have a `size` method, it calls `std::distance(std::begin(iter), std::end(iter))` on the iterable. Therefore, this function can also be used for `std::forward_list` as well as some implementations of ranges.
378+
`size` is a function that can be used to get the size of a container. It is equivalent to the C++17 function [`std::size`][std-size] but has an additional tweak so that, if the container is not a fixed-size C array and doesn't have a `size` method, it calls `std::distance(std::begin(cont), std::end(cont))` on the container. Therefore, this function can also be used for `std::forward_list` as well as some views.
379379

380380
### `sorted_indices`
381381

docs/Sorter-adapters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ template<typename Sorter>
172172
struct self_sort_adapter;
173173
```
174174

175-
Since it is impossible to guarantee the stability of the `sort` method of a given iterable, the *resulting sorter*'s `is_always_stable` is `std::false_type`. However, [`is_stable`][is-stable] will be `std::true_type` if a container's `stable_sort` is called or if a call to the *adapted sorter* is stable. A special case considers valid calls to `std::list::sort` and `std::forward_list::sort` to be stable.
175+
Since it is impossible to guarantee the stability of the `sort` method of a given container, the *resulting sorter*'s `is_always_stable` is `std::false_type`. However, [`is_stable`][is-stable] is `std::true_type` when a container's `stable_sort` is called or if a call to the *adapted sorter* is stable. It is special-cased to consider calls to `std::list::sort` and `std::forward_list::sort` to be stable.
176176

177177
### `small_array_adapter`
178178

0 commit comments

Comments
 (0)