main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
support
static-stack.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, 2002
8
*
9
* Last modified:
10
* $Date: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
11
* $Revision: 9692 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
namespace
Gecode
{
namespace
Support {
39
45
template
<
class
T,
class
A>
46
class
StaticStack
{
47
private
:
49
A& a;
51
int
n;
53
unsigned
int
tos;
55
T* stack;
56
public
:
58
StaticStack
(A&
a
,
int
n
);
60
~StaticStack
(
void
);
61
63
void
reset
(
void
);
65
bool
empty
(
void
)
const
;
67
int
entries
(
void
)
const
;
68
70
T
pop
(
void
);
72
T&
top
(
void
)
const
;
74
T&
last
(
void
)
const
;
76
void
push
(
const
T&
x
);
77
78
private
:
80
static
void
*
operator
new
(
size_t
s)
throw
() { (void) s;
return
NULL; }
82
static
void
operator
delete
(
void
*
p
) { (void)
p
; };
84
StaticStack
(
const
StaticStack
& s) :
a
(s.a) {}
86
const
StaticStack
& operator =(
const
StaticStack
&) {
return
*
this
; }
87
};
88
89
template
<
class
T,
class
A>
90
forceinline
91
StaticStack<T,A>::StaticStack
(A& a0,
int
n0)
92
:
a
(a0),
n
(n0), tos(0), stack(
a
.template alloc<T>(
n
)) {}
93
94
template
<
class
T,
class
A>
95
forceinline
96
StaticStack<T,A>::~StaticStack
(
void
) {
97
a
.free(stack,
n
);
98
}
99
100
template
<
class
T,
class
A>
101
forceinline
bool
102
StaticStack<T,A>::empty
(
void
)
const
{
103
return
tos==0;
104
}
105
106
template
<
class
T,
class
A>
107
forceinline
int
108
StaticStack<T,A>::entries
(
void
)
const
{
109
return
tos;
110
}
111
112
template
<
class
T,
class
A>
113
forceinline
void
114
StaticStack<T,A>::reset
(
void
) {
115
tos = 0;
116
}
117
118
template
<
class
T,
class
A>
119
forceinline
T
120
StaticStack<T,A>::pop
(
void
) {
121
assert((tos > 0) && (tos <=
static_cast<
unsigned
int
>
(
n
)));
122
return
stack[--tos];
123
}
124
125
template
<
class
T,
class
A>
126
forceinline
T&
127
StaticStack<T,A>::top
(
void
)
const
{
128
assert((tos > 0) && (tos <=
static_cast<
unsigned
int
>
(
n
)));
129
return
stack[tos-1];
130
}
131
132
template
<
class
T,
class
A>
133
forceinline
T&
134
StaticStack<T,A>::last
(
void
)
const
{
135
assert((tos >= 0) && (tos <
static_cast<
unsigned
int
>
(
n
)));
136
return
stack[tos];
137
}
138
139
template
<
class
T,
class
A>
140
forceinline
void
141
StaticStack<T,A>::push
(
const
T&
x
) {
142
assert(tos <
static_cast<
unsigned
int
>
(
n
));
143
stack[tos++] =
x
;
144
}
145
146
}}
147
148
// STATISTICS: support-any
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Support::StaticStack::~StaticStack
~StaticStack(void)
Release memory.
Definition:
static-stack.hpp:96
Gecode::Support::StaticStack::last
T & last(void) const
Return element that has just been popped.
Definition:
static-stack.hpp:134
Gecode::Support::StaticStack
Stack with fixed number of elements.
Definition:
static-stack.hpp:46
Gecode::Support::StaticStack::StaticStack
StaticStack(A &a, int n)
Initialize for n elements.
Definition:
static-stack.hpp:91
Gecode
Gecode toplevel namespace
Gecode::Support::StaticStack::reset
void reset(void)
Reset stack (pop all elements)
Definition:
static-stack.hpp:114
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::Support::StaticStack::entries
int entries(void) const
Return number of entries currently on stack.
Definition:
static-stack.hpp:108
Gecode::Support::StaticStack::empty
bool empty(void) const
Test whether stack is empty.
Definition:
static-stack.hpp:102
Gecode::Support::StaticStack::pop
T pop(void)
Pop topmost element from stack and return it.
Definition:
static-stack.hpp:120
Gecode::Support::StaticStack::top
T & top(void) const
Return element on top of stack.
Definition:
static-stack.hpp:127
Gecode::Support::StaticStack::push
void push(const T &x)
Push element x on top of stack.
Definition:
static-stack.hpp:141
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236