The XSB documentation has a paragraph about a heap data structure library, in the manual volume 2 Section 1.16.5. But I can't find any sign of the library, either in the source, or the version history, or via Google. Any ideas if this library actually exists still?
The only lead I have is a library in logtalk which is apparently sourced from the same original. But I'm working with Prolog, so would have to port the logtalk back to Prolog.
You can use Logtalk in XSB (or any other supported Prolog compiler) as just another library and call its resources from plain Prolog or from Prolog modules. Regarding Logtalk's heaps library support, it's indeed based (as stated in its documentation) on original Richard O'Keefe code but enhanced to provide both minimum heaps and maximum heaps. The heaps interface can be browsed e.g. here:
http://logtalk.org/library/heapp_0.html
http://logtalk.org/library/heap_1.html
A simple usage example:
?- heap(<)::(new(Heap), insert_all([1-a,4-d,2-b,5-e,6-f,3-c,7-g], Heap, UpdatedHeap), top(UpdatedHeap, Key, Value)).
Heap = t(0, [], t),
UpdatedHeap = t(7, [], t(1, a, t(3, c, t(5, e, t, t), t(4, d, t, t)), t(2, b, t(6, f, t, t), t(7, g, t, t)))),
Key = 1,
Value = a.
?- heap(>)::(new(Heap), insert_all([1-a,4-d,2-b,5-e,6-f,3-c,7-g], Heap, UpdatedHeap), top(UpdatedHeap, Key, Value)).
Heap = t(0, [], t),
UpdatedHeap = t(7, [], t(7, g, t(4, d, t(1, a, t, t), t(3, c, t, t)), t(6, f, t(2, b, t, t), t(5, e, t, t)))),
Key = 7,
Value = g.
One caveat, however. The ::/2 calls offer performance compared with plain Prolog only when made from within Logtalk objects (or Logtalk categories). Queries at the top-level interpreter or from within a Prolog module are interpreted (meaning that the message is resolved at runtime) instead of compiled (where the message would be resolved at compile time). Whether the performance hit is meaningful for your application only you can tell (in Prolog compilers supporting term-expansion, is easy to reduce the performance hit for ::/2 calls from within modules).