.. index:: heapp
.. _heapp/0:

**protocol**

``heapp``
=========

Heap protocol.

| **Author:** Richard O'Keefe; adapted to Logtalk by Paulo Moura and Victor Lagerkvist.
| **Version:** 1.01
| **Date:** 2010/11/13

| **Compilation flags:**
|    ``static``


(no dependencies on other entities)


Public interface
----------------

.. raw:: html

   <div id="insert/4"> </div>

.. index:: insert/4
.. _heapp/0::insert/4:

``insert/4``
^^^^^^^^^^^^

Inserts the new Key-Value pair into a heap, returning the updated heap.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``insert(Key,Value,Heap,NewHeap)``
| **Mode and number of proofs:**
|    ``insert(+key,+value,+heap,-heap)`` - ``one``


.. raw:: html

   <div id="insert_all/3"> </div>

.. index:: insert_all/3
.. _heapp/0::insert_all/3:

``insert_all/3``
^^^^^^^^^^^^^^^^

Inserts a list of Key-Value pairs into a heap, returning the updated heap.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``insert_all(List,Heap,NewHeap)``
| **Mode and number of proofs:**
|    ``insert_all(@list(pairs),+heap,-heap)`` - ``one``


.. raw:: html

   <div id="delete/4"> </div>

.. index:: delete/4
.. _heapp/0::delete/4:

``delete/4``
^^^^^^^^^^^^

Deletes and returns the top Key-Value pair in OldHeap and the resulting NewHeap.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``delete(Heap,Key,Value,NewHeap)``
| **Mode and number of proofs:**
|    ``delete(+heap,?key,?value,-heap)`` - ``zero_or_one``


.. raw:: html

   <div id="merge/3"> </div>

.. index:: merge/3
.. _heapp/0::merge/3:

``merge/3``
^^^^^^^^^^^

Merges two heaps.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``merge(Heap1,Heap2,NewHeap)``
| **Mode and number of proofs:**
|    ``merge(+heap,+heap,-heap)`` - ``one``


.. raw:: html

   <div id="empty/1"> </div>

.. index:: empty/1
.. _heapp/0::empty/1:

``empty/1``
^^^^^^^^^^^

True if the heap is empty.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``empty(Heap)``
| **Mode and number of proofs:**
|    ``empty(@heap)`` - ``zero_or_one``


.. raw:: html

   <div id="size/2"> </div>

.. index:: size/2
.. _heapp/0::size/2:

``size/2``
^^^^^^^^^^

Returns the number of heap elements.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``size(Heap,Size)``
| **Mode and number of proofs:**
|    ``size(+heap,?integer)`` - ``zero_or_one``


.. raw:: html

   <div id="as_list/2"> </div>

.. index:: as_list/2
.. _heapp/0::as_list/2:

``as_list/2``
^^^^^^^^^^^^^

Returns the current set of Key-Value pairs in the Heap as a List, sorted into ascending order of Keys.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``as_list(Heap,List)``
| **Mode and number of proofs:**
|    ``as_list(+heap,-list)`` - ``one``


.. raw:: html

   <div id="as_heap/2"> </div>

.. index:: as_heap/2
.. _heapp/0::as_heap/2:

``as_heap/2``
^^^^^^^^^^^^^

Constructs a Heap from a list of Key-Value pairs.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``as_heap(List,Heap)``
| **Mode and number of proofs:**
|    ``as_heap(+list,-heap)`` - ``one``


.. raw:: html

   <div id="top/3"> </div>

.. index:: top/3
.. _heapp/0::top/3:

``top/3``
^^^^^^^^^

Returns the top Key-Value pair in Heap. Fails if the heap is empty.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``top(Heap,Key,Value)``
| **Mode and number of proofs:**
|    ``top(+heap,?key,?value)`` - ``zero_or_one``


.. raw:: html

   <div id="top_next/5"> </div>

.. index:: top_next/5
.. _heapp/0::top_next/5:

``top_next/5``
^^^^^^^^^^^^^^

Returns the top pair, Key1-Value1, and the next pair, Key2-Value2, in Heap. Fails if the heap does not have at least two elements.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``top_next(Heap,Key1,Value1,Key2,Value2)``
| **Mode and number of proofs:**
|    ``top_next(+heap,?key,?value,?key,?value)`` - ``zero_or_one``


Protected interface
-------------------

(none)

Private predicates
------------------

(none)

Operators
---------

(none)

Remarks
-------

(none)

.. seealso::

   :ref:`heap(Order) <heap/1>`

