Commit 0f82d0ba authored by Jeremy Roman's avatar Jeremy Roman Committed by Chromium LUCI CQ

Simplify base::internal::is_sorted_and_unique.

The first part currently checks:
  a[0] <= a[1] <= ... <= a[n-1]

And the second checks:
 a[0] < a[1] < ... < a[n-1]

But the second implies the first, so the first can be removed.

Change-Id: Icfa9b65e1dddb4c9d7b0f0541af6e4a35d220ae4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606126
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839851}
parent e2e3775b
......@@ -33,10 +33,10 @@ namespace internal {
// sorted_unique are indeed sorted and unique.
template <typename Range, typename Comp>
constexpr bool is_sorted_and_unique(const Range& range, Comp comp) {
return ranges::is_sorted(range, comp) &&
// Being unique implies that there are no adjacent elements that
// compare equal.
ranges::adjacent_find(range, base::not_fn(comp)) == ranges::end(range);
// Being unique implies that there are no adjacent elements that
// compare equal. So this checks that each element is strictly less
// than the element after it.
return ranges::adjacent_find(range, base::not_fn(comp)) == ranges::end(range);
}
// This is a convenience method returning true if Iterator is at least a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment