Name: myset_init/0
Name: myset_reset/0
Name: myset_add_node/1
Name: myset_delete_node/1
Name: myset_size/1
Name: myset_empty/1
Name: myset_isempty/0
Name: test/0
Name: bench/0
add(X) :- X>0,!, myset_add_node(X), X1 is X-1, add(X1). add(_).
Calls:
Name: RECURSIVE_CALL/1
Name: is/2
Name: !
Name: >/2
Called:
Name: bench/1
ass(X) :- X>0,!, assertz(factset(X)), X1 is X-1, ass(X1). ass(_).
Name: assertz/1
assert_dir :- (user:library_directory('.') -> true ; assertz(user:library_directory('.'))).
Name: true
Name: library_directory/1
Name: ->/3
bench :- bench(1000000).
bench(X) :- assertz(user:library_directory('.')), myset_init, statistics(runtime,_), add(X), print_time(myset_add), ass(X), print_time(assert), del(X), print_time(myset_del), ret(X), print_time(retract).
Name: print_time/1
Name: ret/1
Name: del/1
Name: ass/1
Name: add/1
Name: statistics/2
del(X) :- X>0,!, myset_delete_node(X), X1 is X-1, del(X1). del(_).
foreign(myset_initialize,myset_initialize). % initializes the data structure foreign(myset_reset,myset_reset). % resets the heap to the empty heap; frees memory foreign(myset_add_node,myset_add_node(+integer)). % ID foreign(myset_delete_node,myset_delete_node(+integer)). % ID foreign(myset_node_exists,myset_node_exists(+integer,[-integer])). foreign(myset_size,myset_size([-integer])). foreign(myset_empty,myset_empty([-integer])). %return 1 if empty, 0 if non-empty
foreign_resource(myset, [ myset_reset ,myset_initialize ,myset_add_node ,myset_delete_node ,myset_node_exists ,myset_size ,myset_empty ]).
loadfr :- (loaded -> true ; (assertz(loaded), %assert_dir, %assertz(user:library_directory(prob_home('.'))), %print(loading_foreign_resource(myset)),nl, load_foreign_resource(library(myset))) ).
Name: load_foreign_resource/1
Name: loaded
myset_init :- loadfr, %print(initializing_myset),nl, myset_initialize.
Name: myset_initialize
Name: loadfr/0
myset_isempty :- myset_empty(X),X=1.
Name: =/2
print_time(T) :- statistics(runtime,[_,T2]), print(T), print(' : '), print(T2), print(' ms'),nl.
Name: nl
Name: print/1
ret(X) :- X>0,!, (retract(factset(X)) -> true ; print(fail(X)),nl), X1 is X-1, ret(X1). ret(_).
Name: factset/1
Name: retract/1
test :- assertz(user:library_directory('.')), myset_init, myset_add_node(22), myset_add_node(33), myset_add_node(221), myset_size(Sz), print(size(Sz)),nl, flush_output(user), myset_delete_node(33), myset_delete_node(33), myset_size(Sz2), print(size(Sz2)),nl, flush_output(user), myset_node_exists(22,X22), myset_node_exists(33,X33), format('Exists 22:~w, 33:~w~n',[X22,X33]).
Name: format/2
Name: myset_node_exists/2
Name: flush_output/1