- Description
- Heap (a.k.a. priority queue) data structure
- Latest
- heap-0.5.el, 2017-Aug-18, 12.0 KiB
- Home page
- http://www.dr-qubit.org/emacs.php
- Browse ELPA's repository
- CGit or Gitweb
- Badge

To install this package, run in Emacs:

M-x package-install RET heap RET

A heap is a form of efficient self-sorting tree. In particular, the root node is guaranteed to be the highest-ranked entry in the tree. (The comparison function used for ranking the data can, of course, be freely defined). Therefore repeatedly removing the root node will return the data in order of increasing rank. They are often used as priority queues, for scheduling tasks in order of importance. This package implements ternary heaps, since they are about 12% more efficient than binary heaps for heaps containing more than about 10 elements, and for very small heaps the difference is negligible. The asymptotic complexity of ternary heap operations is the same as for a binary heap: 'add', 'delete-root' and 'modify' operations are all O(log n) on a heap containing n elements. Note that this package implements a heap as an implicit data structure on a vector. Therefore, the maximum size of the heap has to be specified in advance. Although the heap will grow dynamically if it becomes full, this requires copying the entire heap, so insertion has worst-case complexity O(n) instead of O(log n), though the amortized complexity is still O(log n). (For applications where the maximum size of the heap is not known in advance, an implementation based on binary trees might be more suitable, but is not currently implemented in this package.) You create a heap using `make-heap', add elements to it using `heap-add', delete and return the root of the heap using `heap-delete-root', and modify an element of the heap using `heap-modify'. A number of other heap convenience functions are also provided, all with the prefix `heap-'. Functions with prefix `heap--' are for internal use only, and should never be used outside this package.

heap-0.3.el | 2012-Nov-29 | 11.7 KiB |