It depends on Alexandria, and outside SBCL additionally on Bordeaux-Threads.
Pileup is maintained in Git:
git clone git://github.com/nikodemus/pileup.git
will get you a local copy.
http://github.com/nikodemus/pileup
is the GitHub project page.
Class precedence list:
heap, structure-object, t
A thread-safe binary heap.
Heap operations which need the heap to remain consistent heap lock it. Users can also group multiple heap operations into atomic units using
with-locked-heap
.Thread-safety is implemented using a single lock per heap. While Pileup heaps are fine for threaded use, a more specialized solution is recommended when the heap is highly contested between multiple threads.
Important: Pileup heaps are not asynch-unwind safe: asynchronous interrupts causing non-local exits may leave the heap in an inconsistent state or lose data. Do not use
interrupt-thread
or asychronous timeouts with Pileup.All slot names in
heap
are internal to thepileup
package, so it is safe to subclass using eg.defstruct
:include
, as long as only the exported operations are used to accessor or modify heap state.
The
predicate
determines the ordering of the heap. It must be a function of two arguments, returning true if the first argument should be closer to top of the heap than the second. If a predicate signals an error and causes a non-local exit from a heap operation, it may leave the heap in an inconsistent state and cause a subsequent heap operation to signal an error.If
key
is notnil
, it must be a function of one argument, and is used to extract values for use bypredicate
for comparison.The
name
can be used to optionally specify a name for the heap: it affects only printing of the heap.The
size
is the size of the storage initially reserved for the heap. Specifying size is not necessary: the heap will grow as necessary, but a reasonable estimate can improve performance by eliminating unnecessary copying by allocating sufficient storage immediately.
Executes
body
withheap
locked. Heap operations which implicitly lock the heap are:heap-insert
,heap-pop
,heap-delete
, andmap-heap
. Allows grouping multiple heap operations into atomic units.
Insert
elt
toheap
. Returnselt
.Locks the heap during its operation unless the current thread is already holding the heap lock via
with-locked-heap
.
Removes and returns the element at the top of the
heap
and a secondary value oft
. Should the heap be empty, both the primary and the secondary values arenil
.Locks the heap during its operation unless the current thread is already holding the heap lock via
with-locked-heap
.
Returns the element at the top of the
heap
without removing it, and a secondary value oft
. Should the heap be empty, both the primary and the secondary values arenil
.
Removes elements of the
heap
eql
toelt
. Returnst
if one or more elements were found and removed,nil
otherwise.If
count
isnil
(the default), removes all elementseql
toelt
, otherwise at most the indicated number.Locks the heap during its operation unless the current thread is already holding the heap lock via
with-locked-heap
.
Calls
function
for each element in heap. Returns the heap.If
ordered
is true (the default), processes the elements in heap order from top down.If
ordered
is false, uses unordered traversal. Unordered traversal is faster and also works on heaps that have been corrupted by eg. the heap predicate performing a non-local exit from a heap operation.Attempts to insert or delete elements to the heap from
function
will cause an error to be signalled.Locks the heap during its operation unless the current thread is already holding the heap lock via
with-locked-heap
.
Returns the name of the heap. Heap name affects only printed representation of the heap. Can be changed using
setf
unlike other heap properties.
Returns the heap key, a function one argument used to extract values for use by the heap predicate. Heap key may also be
nil
, meaning heap elements are used directly by the heap predicate.
Returns the heap predicate, a function of two arguments, returning true if the first argument should be closer to te top of the heap than the second.