Optionally return position in canFindIndex
This commit is contained in:
parent
c4a7f9cb04
commit
dca63110f7
|
@ -1849,9 +1849,28 @@ const pure @safe @nogc:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canFindIndex(const size_t[] items, size_t index) pure @safe @nogc
|
bool canFindIndex(const size_t[] items, size_t index, size_t* pos = null) pure @safe @nogc
|
||||||
{
|
{
|
||||||
import std.range : assumeSorted;
|
import std.range : assumeSorted;
|
||||||
|
if (!pos)
|
||||||
return !assumeSorted(items).equalRange(index).empty;
|
{
|
||||||
|
return !assumeSorted(items).equalRange(index).empty;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto trisection_result = assumeSorted(items).trisect(index);
|
||||||
|
if (trisection_result[1].length == 1)
|
||||||
|
{
|
||||||
|
*pos = trisection_result[0].length;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (trisection_result[1].length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(0, "the constraint of having unique locations has been violated");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue