它只是我,还是在Phobos中没有二进制搜索功能?我有一个预先排序的数组,我想用我自己的比较器函数进行搜索,但我在std.algorithms或std.containers中找不到任何东西。
谢谢!
它只是我,还是在Phobos中没有二进制搜索功能?我有一个预先排序的数组,我想用我自己的比较器函数进行搜索,但我在std.algorithms或std.containers中找不到任何东西。
谢谢!
使用 SortedRange
从 std.range
:
从中受贿 http://www.digitalmars.com/d/2.0/phobos/std_range.html#SortedRange:
auto a = [ 1, 2, 3, 42, 52, 64 ];
auto r = assumeSorted(a);
assert(r.canFind(3));
assert(!r.canFind(32));
使用 SortedRange
从 std.range
:
从中受贿 http://www.digitalmars.com/d/2.0/phobos/std_range.html#SortedRange:
auto a = [ 1, 2, 3, 42, 52, 64 ];
auto r = assumeSorted(a);
assert(r.canFind(3));
assert(!r.canFind(32));