Priority queues are data structures that maintain a dynamic collection of elements and allow inserting new elements and removing the smallest element. The most widely known and used priority queue is likely the implicit binary heap, even though it is has frequent cache misses and is hard to optimize using e.g. SIMD instructions. We introduce the SimdQuickHeap, a variant of the QuickHeap that was introduced by Navarro and Paredes in 2010. As suggested by the name, the data structure bears some similarity to QuickSort. We modify the data layout of the original QuickHeap to have all \emph{pivots} adjacent in memory, with elements between consecutive pivots stored in dedicated \emph{buckets}. This allows efficient SIMD implementations for both partitioning of buckets and scanning the list of pivots to find the bucket to append newly inserted elements to. The SimdQuickHeap has amortized expected complexity $O(\log n)$ per operation, which improves to $O(\frac 1W\log n)$ in non-degenerate cases, where $W$ is the number of words in a SIMD register. In this case, the I/O-complexity is amortized $O(\frac 1B)$ per push and $O(\frac 1B \log_2 \frac nM)$ per pop. In synthetic benchmarks, the SimdQuickHeap is up to twice as fast as the next-best competitor, including the non-comparison radix heap, and needs around $1.5\log_2 n$ comparisons and $\log_2 n$ nanoseconds per pair of push and pop operations. On graph benchmarks with Dijkstra's shortest path algorithm and Jarnik-Prim's minimum spanning tree algorithm, the SimdQuickHeap is consistently the fastest.
翻译:优先队列是一种维护动态元素集合的数据结构,支持插入新元素和移除最小元素。最广为人知和使用的优先队列可能是隐式二叉堆,尽管它存在频繁的缓存未命中问题,且难以通过SIMD指令等方法优化。我们提出了SimdQuickHeap,这是纳瓦罗(Navarro)和帕雷德斯(Paredes)于2010年提出的QuickHeap的一种变体。顾名思义,该数据结构与QuickSort具有一定的相似性。我们对原始QuickHeap的数据布局进行了修改,使所有*枢轴*在内存中相邻排列,而相邻枢轴之间的元素则存储在专用的*桶*中。这使得我们可以为桶的分区以及扫描枢轴列表以找到插入新元素的目标桶,实现高效的SIMD实现。SimdQuickHeap的每操作平摊期望复杂度为$O(\log n)$,在非退化情况下可改进至$O(\frac 1W\log n)$,其中$W$是SIMD寄存器中的字长。在此情况下,其I/O复杂度为每次push操作平摊$O(\frac 1B)$,每次pop操作平摊$O(\frac 1B \log_2 \frac nM)$。在合成基准测试中,SimdQuickHeap的速度是次优竞争算法(包括非比较型基数堆)的两倍,且每对push和pop操作平均需要约$1.5\log_2 n$次比较和$\log_2 n$纳秒。在使用Dijkstra最短路径算法和Jarnik-Prim最小生成树算法的图基准测试中,SimdQuickHeap始终是最快的。