From 24b78dbf8bd2a6644e50e88c010eb650e7784d94 Mon Sep 17 00:00:00 2001 From: vsc Date: Sun, 16 Jul 2006 01:41:07 +0000 Subject: [PATCH] an implementation of queues in the DB. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1674 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- library/dbqueues.yap | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 library/dbqueues.yap diff --git a/library/dbqueues.yap b/library/dbqueues.yap new file mode 100644 index 000000000..2cbf74eb1 --- /dev/null +++ b/library/dbqueues.yap @@ -0,0 +1,46 @@ +:- module(dbqueue, [ + db_enqueue/2, + db_dequeue/2, + db_clean_queue/1 + ]). + + +:- unhide('$init_db_queue'). +:- unhide('$db_enqueue'). +:- unhide('$db_dequeue'). + + +db_enqueue(Name,El) :- var(Name), + throw(error(instantiation_error(Name),db_enqueue(Name,El))). +db_enqueue(Name,El) :- \+ atom(Name), !, + throw(error(type_error_atom(Name),db_enqueue(Name,El))). +db_enqueue(Name,El) :- + recorded('$db_queue',[Name|Ref],_), !, + prolog:'$db_enqueue'(Ref, El). +db_enqueue(Name,El) :- + prolog:'$init_db_queue'(Ref), + recorda('$db_queue',[Name|Ref],_), + prolog:'$db_enqueue'(Ref,El). + + +db_dequeue(Name,El) :- var(Name), + throw(error(instantiation_error(Name),db_dequeue(Name,El))). +db_dequeue(Name,El) :- \+ atom(Name), !, + throw(error(type_error_atom(Name),db_dequeue(Name,El))). +db_dequeue(Name,El) :- + recorded('$db_queue',[Name|Ref],R), + ( prolog:'$db_dequeue'(Ref, El) -> + true + ; + erase(R), + fail + ). + +db_clean_queue(Name) :- + recorded('$db_queue',[Name|Ref],R), !, + erase(R), + db_dequeue_all(Ref). +db_clean_queue(_). + +db_dequeue_all(Ref) :- + ( prolog:'$db_dequeue'(Ref, _) -> db_dequeue_all(Ref) ; true ).