Skip to content

Commit 1caa776

Browse files
committed
fix assumeSortedEqualIndex
1 parent 3145024 commit 1caa776

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

source/mir/ndslice/sorting.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ template assumeSortedContains(alias test = "a < b")
507507
/++
508508
Returns: the smallest index of a sorted array such
509509
that the index corresponds to the arrays element at the index according to the predicate
510-
and array length if the array doesn't contain corresponding element.
510+
and `-1` if the array doesn't contain corresponding element.
511511
512512
Params:
513513
test = strict ordering symmetric predicate.
@@ -528,15 +528,15 @@ template assumeSortedEqualIndex(alias test = "a < b")
528528
slice = sorted one-dimensional slice or array.
529529
v = value to test with. It is passed to second argument.
530530
+/
531-
size_t assumeSortedEqualIndex(Iterator, SliceKind kind, V)
531+
sizediff_t assumeSortedEqualIndex(Iterator, SliceKind kind, V)
532532
(auto ref Slice!(Iterator, 1, kind) slice, auto ref scope const V v)
533533
{
534534
auto ti = transitionIndex!test(slice, v);
535-
return ti < slice.length && !test(v, slice[ti]) ? ti : slice.length;
535+
return ti < slice.length && !test(v, slice[ti]) ? ti : -1;
536536
}
537537

538538
/// ditto
539-
size_t assumeSortedEqualIndex(T, V)(scope T[] ar, auto ref scope const V v)
539+
sizediff_t assumeSortedEqualIndex(T, V)(scope T[] ar, auto ref scope const V v)
540540
{
541541
return .assumeSortedEqualIndex!test(ar.sliced, v);
542542
}
@@ -553,10 +553,10 @@ version(mir_test)
553553
auto a = [0, 1, 2, 3, 4, 6];
554554

555555
assert(a.assumeSortedEqualIndex(2) == 2);
556-
assert(a.assumeSortedEqualIndex(5) == a.length);
556+
assert(a.assumeSortedEqualIndex(5) == -1);
557557

558558
// <= non strict predicates doesn't work
559-
assert(a.assumeSortedEqualIndex!"a <= b"(2) == a.length);
559+
assert(a.assumeSortedEqualIndex!"a <= b"(2) == -1);
560560
}
561561

562562
/++

0 commit comments

Comments
 (0)