main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Feb 11 2025 17:33:26 for Gecode by
doxygen
1.12.0
gecode
support
dynamic-queue.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2009
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
namespace
Gecode
{
namespace
Support {
35
41
template
<
class
T,
class
A>
42
class
DynamicQueue
{
43
private
:
45
A& a;
47
int
limit;
49
int
fst;
51
int
lst;
53
T* q;
55
void
resize(
void
);
57
void
move(
int
& i);
58
public
:
60
DynamicQueue
(A& a);
62
~DynamicQueue
(
void
);
63
65
bool
empty
(
void
)
const
;
66
68
void
reset
(
void
);
69
71
T
pop
(
void
);
73
void
push
(
const
T&
x
);
74
private
:
76
static
void
*
operator
new
(
size_t
s)
throw
() { (void) s;
return
NULL; }
78
static
void
operator
delete
(
void
*
p
) { (void)
p
; };
80
DynamicQueue
(
const
DynamicQueue
& s) :
a
(s.
a
) {}
82
const
DynamicQueue
& operator =(
const
DynamicQueue
&) {
return
*
this
; }
83
};
84
85
86
template
<
class
T,
class
A>
87
forceinline
void
88
DynamicQueue<T,A>::move(
int
& i) {
89
i
= (
i
+1) & (limit - 1);
90
}
91
92
template
<
class
T,
class
A>
93
void
94
DynamicQueue<T,A>::resize(
void
) {
95
assert(fst == lst);
96
T* nq =
a
.template alloc<T>(limit << 1);
97
int
j=0;
98
for
(
int
i = fst;
i
<limit;
i
++)
99
nq[j++] = q[i];
100
for
(
int
i = 0;
i
<lst;
i
++)
101
nq[j++] = q[i];
102
a
.template free<T>(q,limit);
103
q = nq;
104
fst = 0;
105
lst = limit;
106
limit <<= 1;
107
}
108
109
template
<
class
T,
class
A>
110
forceinline
111
DynamicQueue<T,A>::DynamicQueue
(A& a0)
112
:
a
(a0), limit(8), fst(0), lst(0), q(
a
.template alloc<T>(limit)) {}
113
114
template
<
class
T,
class
A>
115
forceinline
116
DynamicQueue<T,A>::~DynamicQueue
(
void
) {
117
a
.free(q,limit);
118
}
119
120
template
<
class
T,
class
A>
121
forceinline
bool
122
DynamicQueue<T,A>::empty
(
void
)
const
{
123
return
fst == lst;
124
}
125
126
template
<
class
T,
class
A>
127
forceinline
void
128
DynamicQueue<T,A>::reset
(
void
) {
129
fst = lst = 0;
130
}
131
132
template
<
class
T,
class
A>
133
forceinline
T
134
DynamicQueue<T,A>::pop
(
void
) {
135
assert(!empty());
136
T
t
= q[fst];
137
move(fst);
138
return
t
;
139
}
140
141
template
<
class
T,
class
A>
142
forceinline
void
143
DynamicQueue<T,A>::push
(
const
T&
x
) {
144
q[lst] =
x
;
145
move(lst);
146
if
(fst == lst)
147
resize();
148
}
149
150
}}
151
152
// STATISTICS: support-any
t
NodeType t
Type of node.
Definition
bool-expr.cpp:230
p
int p
Number of positive literals for node type.
Definition
bool-expr.cpp:232
a
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Gecode::Support::DynamicQueue
Queue with arbitrary number of elements.
Definition
dynamic-queue.hpp:42
Gecode::Support::DynamicQueue::~DynamicQueue
~DynamicQueue(void)
Release memory.
Definition
dynamic-queue.hpp:116
Gecode::Support::DynamicQueue::push
void push(const T &x)
Push element x to queue.
Definition
dynamic-queue.hpp:143
Gecode::Support::DynamicQueue::empty
bool empty(void) const
Test whether queue is empty.
Definition
dynamic-queue.hpp:122
Gecode::Support::DynamicQueue::DynamicQueue
DynamicQueue(A &a)
Initialize queue.
Definition
dynamic-queue.hpp:111
Gecode::Support::DynamicQueue::pop
T pop(void)
Pop element added first from queue and return it.
Definition
dynamic-queue.hpp:134
Gecode::Support::DynamicQueue::reset
void reset(void)
Reset queue to be empty.
Definition
dynamic-queue.hpp:128
Gecode
Gecode toplevel namespace
Gecode::x
Post propagator for SetVar x
Definition
set.hh:767
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
forceinline
#define forceinline
Definition
config.hpp:187