基于比较的搜索的数组布局
Array Layouts for Comparison-Based Searching
摘要:
我们尝试确定最佳顺序和搜索算法,以将$n$可比较的数据项存储在长度为$n$的数组$A$中,以便对于任何查询值$x$,我们都可以快速找到$A$中大于或等于$x$的最小值。特别是,我们认为有许多这样的查询相同的数组,$A$,它完全驻留在RAM中的重要情况。除了明显的排序顺序/二进制搜索组合,我们考虑通常用于堆的Eytzinger(BFS)布局,一个隐含的B树布局,概括了Eytzinger布局,和van Emde Boas布局中常用的高速缓存遗忘算法文献。在对各种现代硬件进行广泛的测试和调优之后,我们得出结论,对于$n$的小值,排序顺序与二进制搜索的良好实现相结合是最好的。对于较大的$n$值,我们得出了令人惊讶的结论,即Eytzinger布局通常是最快的。后一个结论是出乎意料的,并且与Brodal,Fagerberg和Jacob(SODA~2003)的早期实验工作相反,他们得出结论,对于$n$的大值,B树和van Emde Boas布局都比Eytzinger布局快。我们最快的C++实现在编译时使用条件移动来避免分支预测错误和预取来减少缓存延迟。
英文摘要:
We attempt to determine the best order and search algorithm to store $n$ comparable data items in an array, $A$, of length $n$ so that we can, for any query value, $x$, quickly find the smallest value in $A$ that is greater than or equal to $x$. In particular, we consider the important case where there are many such queries to the same array, $A$, which resides entirely in RAM. In addition to the obvious sorted order/binary search combination we consider the Eytzinger (BFS) layout normally used for heaps, an implicit B-tree layout that generalizes the Eytzinger layout, and the van Emde Boas layout commonly used in the cache-oblivious algorithms literature. After extensive testing and tuning on a wide variety of modern hardware, we arrive at the conclusion that, for small values of $n$, sorted order, combined with a good implementation of binary search is best. For larger values of $n$, we arrive at the surprising conclusion that the Eytzinger layout is usually the fastest. The latter conclusion is unexpected and goes counter to earlier experimental work by Brodal, Fagerberg, and Jacob (SODA~2003), who concluded that both the B-tree and van Emde Boas layouts were faster than the Eytzinger layout for large values of $n$. Our fastest C++ implementations, when compiled, use conditional moves to avoid branch mispredictions and prefetching to reduce cache latency.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。