YAP 7.1.0
nb.yap
Go to the documentation of this file.
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: nb.yap *
12* Last rev: 5/12/99 *
13* mods: *
14* comments: non-backtrackable data-structures *
15* *
16*************************************************************************/
17
18/**
19 * @file nb.yap
20 * @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
21 * @date Tue Nov 17 23:18:13 2015
22 *
23 * @brief stub for global (non-backtrackable) variables.
24 *
25 *
26*/
27
28
29:- module(nb, [
30 nb_create_accumulator/2,
31 nb_add_to_accumulator/2,
32 nb_accumulator_value/2,
34 nb_queue/2,
41 nb_queue_replace/3,
48 nb_heap_clear/1,
56% nb_beam_check/1,
58
59/** @defgroup nonback Non-Backtrackable Data Structures
60@ingroup YAPLibrary
61@{
62
63The following routines implement well-known data-structures using global
64non-backtrackable variables (implemented on the Prolog stack). The
65data-structures currently supported are Queues, Heaps, and Beam for Beam
66search. They are allowed through `library(nb)`.
67
68
69*/
70
71/** @pred nb_beam(+ _DefaultSize_,- _Beam_)
72
73
74Create a _Beam_ with default size _DefaultSize_. Note that size
75is fixed throughout.
76
77
78*/
79/** @pred nb_beam_add(+ _Beam_, + _Key_, + _Value_)
80
81
82Add _Key_- _Value_ to the beam _Beam_. The key is sorted on
83 _Key_ only.
84
85
86*/
87/** @pred nb_beam_close(+ _Beam_)
88
89
90Close the beam _Beam_: no further elements can be added.
91
92
93*/
94/** @pred nb_beam_del(+ _Beam_, - _Key_, - _Value_)
95
96
97Remove element _Key_- _Value_ with smallest _Value_ in beam
98 _Beam_. Fail if the beam is empty.
99
100
101*/
102/** @pred nb_beam_empty(+ _Beam_)
103
104
105Succeeds if _Beam_ is empty.
106
107
108
109
110 */
111/** @pred nb_beam_peek(+ _Beam_, - _Key_, - _Value_))
112
113
114 _Key_- _Value_ is the element with smallest _Key_ in the beam
115 _Beam_. Fail if the beam is empty.
116
117
118*/
119/** @pred nb_beam_size(+ _Beam_, - _Size_)
120
121
122Unify _Size_ with the number of elements in the beam _Beam_.
123
124
125*/
126/** @pred nb_heap(+ _DefaultSize_,- _Heap_)
127
128
129Create a _Heap_ with default size _DefaultSize_. Note that size
130will expand as needed.
131
132
133*/
134/** @pred nb_heap_add(+ _Heap_, + _Key_, + _Value_)
135
136
137Add _Key_- _Value_ to the heap _Heap_. The key is sorted on
138 _Key_ only.
139
140
141*/
142/** @pred nb_heap_close(+ _Heap_)
143
144
145Close the heap _Heap_: no further elements can be added.
146
147
148*/
149/** @pred nb_heap_del(+ _Heap_, - _Key_, - _Value_)
150
151
152Remove element _Key_- _Value_ with smallest _Value_ in heap
153 _Heap_. Fail if the heap is empty.
154
155
156*/
157/** @pred nb_heap_empty(+ _Heap_)
158
159
160Succeeds if _Heap_ is empty.
161
162
163*/
164/** @pred nb_heap_peek(+ _Heap_, - _Key_, - _Value_))
165
166
167 _Key_- _Value_ is the element with smallest _Key_ in the heap
168 _Heap_. Fail if the heap is empty.
169
170
171*/
172/** @pred nb_heap_size(+ _Heap_, - _Size_)
173
174
175Unify _Size_ with the number of elements in the heap _Heap_.
176
177
178*/
179/** @pred nb_queue(- _Queue_)
180
181
182Create a _Queue_.
183
184
185*/
186/** @pred nb_queue_close(+ _Queue_, - _Head_, ? _Tail_)
187
188
189Unify the queue _Queue_ with a difference list
190 _Head_- _Tail_. The queue will now be empty and no further
191elements can be added.
192
193
194*/
195/** @pred nb_queue_dequeue(+ _Queue_, - _Element_)
196
197
198Remove _Element_ from the front of the queue _Queue_. Fail if
199the queue is empty.
200
201
202*/
203/** @pred nb_queue_empty(+ _Queue_)
204
205
206Succeeds if _Queue_ is empty.
207
208
209*/
210/** @pred nb_queue_enqueue(+ _Queue_, + _Element_)
211
212
213Add _Element_ to the front of the queue _Queue_.
214
215
216*/
217/** @pred nb_queue_peek(+ _Queue_, - _Element_)
218
219
220 _Element_ is the front of the queue _Queue_. Fail if
221the queue is empty.
222
223
224*/
225/** @pred nb_queue_size(+ _Queue_, - _Size_)
226
227
228Unify _Size_ with the number of elements in the queue _Queue_.
229
230
231*/
232/** @} */
233
234
nb_beam(+ DefaultSize,- Beam)
nb_beam_add(+ Beam, + Key, + Value)
nb_beam_close(+ Beam)
nb_beam_del(+ Beam, - Key, - Value)
nb_beam_empty(+ Beam)
nb_beam_peek(+ Beam, - Key, - Value)
nb_beam_size(+ Beam, - Size)
nb_heap(+ DefaultSize,- Heap)
nb_heap_add(+ Heap, + Key, + Value)
nb_heap_close(+ Heap)
nb_heap_del(+ Heap, - Key, - Value)
nb_heap_empty(+ Heap)
nb_heap_peek(+ Heap, - Key, - Value)
nb_heap_size(+ Heap, - Size)
nb_queue(- Queue)
nb_queue_close(+ Queue, - Head, ? Tail)
nb_queue_dequeue(+ Queue, - Element)
nb_queue_empty(+ Queue)
nb_queue_enqueue(+ Queue, + Element)
nb_queue_peek(+ Queue, - Element)
nb_queue_size(+ Queue, - Size)