fix library heap

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@280 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-01-08 03:47:18 +00:00
parent 2fd3f33819
commit fcbf07a251
2 changed files with 11 additions and 1 deletions

View File

@ -6586,6 +6586,12 @@ stable, that is, if you insert several pairs with the same @var{Key} it
is not defined which of them will come out first, and it is possible for
any of them to come out first depending on the history of the heap.
@item empty_heap(?@var{Heap})
@findex empty_heap/1
@syindex empty_heap/1
@cnindex empty_heap/1
Succeeds if @var{Heap} is an empty heap.
@item get_from_heap(+@var{Heap},-@var{key},-@var{Datum},-@var{Heap})
@findex get_from_heap/4
@syindex get_from_heap/4

View File

@ -43,6 +43,7 @@
:- module(heaps,[
add_to_heap/4, % Heap x Key x Datum -> Heap
get_from_heap/4, % Heap -> Key x Datum x Heap
empty_heap/1, % Heap
heap_size/2, % Heap -> Size
heap_to_list/2, % Heap -> List
list_to_heap/2, % List -> Heap
@ -95,7 +96,7 @@ add_to_heap(t(M,[H|T],OldTree), Key, Datum, t(N,T,NewTree)) :-
add_to_heap(1, Key, Datum, _, t(Key,Datum,t,t)) :- !.
add_to_heap(N, Key, Datum, t(K1,D1,L1,R1), t(K2,D2,L2,R2)) :-
E is N mod 2,
M is N/2,
M is N//2,
% M > 0, % only called from list_to_heap/4,add_to_heap/4
sort2(Key, Datum, K1, D1, K2, D2, K3, D3),
add_to_heap(E, M, K3, D3, L1, R1, L2, R2).
@ -227,3 +228,6 @@ min_of_heap(t(Ka,Da,_,_), t(Kb,Db,_,_), Kb, Db) :-
min_of_heap(t(Ka,Da,_,_), _, Ka, Da).
min_of_heap(t, t(Kb,Db,_,_), Kb, Db).
empty_heap(t(0,[],t)).