2014-12-19 23:47:50 +00:00
|
|
|
/**
|
2015-11-18 15:06:25 +00:00
|
|
|
* @file dbqueues.yap
|
|
|
|
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
|
|
|
|
* @date Tue Nov 17 15:01:49 2015
|
|
|
|
*
|
|
|
|
* @brief A library to support queues with no-backtrackable queues.
|
|
|
|
*
|
|
|
|
*
|
2014-12-19 23:47:50 +00:00
|
|
|
*/
|
2006-07-27 20:04:56 +01:00
|
|
|
|
2015-11-18 15:06:25 +00:00
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
:- module(nbqueue, [
|
2009-06-05 20:31:06 +01:00
|
|
|
nb_enqueue/2,
|
|
|
|
nb_dequeue/2,
|
|
|
|
nb_clean_queue/1,
|
|
|
|
nb_size/2
|
|
|
|
]).
|
2006-07-16 02:41:07 +01:00
|
|
|
|
2015-11-18 15:06:25 +00:00
|
|
|
/**
|
|
|
|
* @defgroup dbqueues Non-backtrackable queues in YAP.
|
|
|
|
* @ingroup library
|
|
|
|
|
|
|
|
A library to implement queues of NB Terms
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-07-16 02:41:07 +01:00
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
:- unhide('$init_nb_queue').
|
|
|
|
:- unhide('$nb_enqueue').
|
|
|
|
:- unhide('$nb_dequeue').
|
2006-07-16 02:41:07 +01:00
|
|
|
|
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
nb_enqueue(Name,El) :- var(Name),
|
|
|
|
throw(error(instantiation_error(Name),nb_enqueue(Name,El))).
|
|
|
|
nb_enqueue(Name,El) :- \+ atom(Name), !,
|
|
|
|
throw(error(type_error_atom(Name),nb_enqueue(Name,El))).
|
|
|
|
nb_enqueue(Name,El) :-
|
|
|
|
recorded('$nb_queue',[Name|Ref],_), !,
|
|
|
|
prolog:'$nb_enqueue'(Ref, El).
|
|
|
|
nb_enqueue(Name,El) :-
|
|
|
|
prolog:'$init_nb_queue'(Ref),
|
|
|
|
recorda('$nb_queue',[Name|Ref],_),
|
|
|
|
prolog:'$nb_enqueue'(Ref,El).
|
2006-07-16 02:41:07 +01:00
|
|
|
|
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
nb_dequeue(Name,El) :- var(Name),
|
|
|
|
throw(error(instantiation_error(Name),nb_dequeue(Name,El))).
|
|
|
|
nb_dequeue(Name,El) :- \+ atom(Name), !,
|
|
|
|
throw(error(type_error_atom(Name),nb_dequeue(Name,El))).
|
|
|
|
nb_dequeue(Name,El) :-
|
|
|
|
recorded('$nb_queue',[Name|Ref],R),
|
|
|
|
( prolog:'$nb_dequeue'(Ref, El) ->
|
2006-07-16 02:41:07 +01:00
|
|
|
true
|
|
|
|
;
|
|
|
|
erase(R),
|
|
|
|
fail
|
|
|
|
).
|
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
nb_clean_queue(Name) :-
|
|
|
|
recorded('$nb_queue',[Name|Ref],R), !,
|
2006-07-16 02:41:07 +01:00
|
|
|
erase(R),
|
2006-08-22 17:12:46 +01:00
|
|
|
nb_dequeue_all(Ref).
|
|
|
|
nb_clean_queue(_).
|
2006-07-16 02:41:07 +01:00
|
|
|
|
2006-08-22 17:12:46 +01:00
|
|
|
nb_dequeue_all(Ref) :-
|
|
|
|
( prolog:'$nb_dequeue'(Ref, _) -> nb_dequeue_all(Ref) ; true ).
|
|
|
|
|
|
|
|
nb_dequeue_size(Ref, Size) :-
|
|
|
|
prolog:'$nb_size'(Ref, Size).
|
2014-12-19 23:47:50 +00:00
|
|
|
|