binary-search - D 2.0 (Phobos) 中的二分搜索?

标签 binary-search d phobos

是我一个人,还是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));

关于binary-search - D 2.0 (Phobos) 中的二分搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4622377/

相关文章:

d - 开始使用 vibe.d

pointers - 声明 const 指针为 int 吗?

regex - std.regex.regex 的返回值?

d - 检查字符串是否以 D/phobos 中的子字符串开头?

d - std.algorithm.joiner(string[],string) - 为什么结果元素是 dchar 而不是 char?

java - Java中的字符串二分查找

algorithm - 如何在一个谎言模型中进行二分查找?

java - 如果我必须对大量数据进行二分查找,我应该使用哪种数据类型?

concurrency - D 编程语言中的 Erlang 风格并发

javascript - 二进制搜索代码