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
bitset-offset.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christopher Mears <chris.mears@monash.edu>
5
*
6
* Contributing authors:
7
* Mikael Lagerkvist <lagerkvist@gecode.org>
8
* Christian Schulte <schulte@gecode.org>
9
*
10
* Copyright:
11
* Mikael Lagerkvist, 2007
12
* Christopher Mears, 2012
13
* Christian Schulte, 2007
14
*
15
* Last modified:
16
* $Date: 2013-03-07 17:39:13 +0100 (Thu, 07 Mar 2013) $ by $Author: schulte $
17
* $Revision: 13458 $
18
*
19
* This file is part of Gecode, the generic constraint
20
* development environment:
21
* http://www.gecode.org
22
*
23
* Permission is hereby granted, free of charge, to any person obtaining
24
* a copy of this software and associated documentation files (the
25
* "Software"), to deal in the Software without restriction, including
26
* without limitation the rights to use, copy, modify, merge, publish,
27
* distribute, sublicense, and/or sell copies of the Software, and to
28
* permit persons to whom the Software is furnished to do so, subject to
29
* the following conditions:
30
*
31
* The above copyright notice and this permission notice shall be
32
* included in all copies or substantial portions of the Software.
33
*
34
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
*
42
*/
43
44
#include <climits>
45
#include <cmath>
46
#include <iostream>
47
48
namespace
Gecode
{
namespace
Support {
49
54
template
<
class
A>
55
class
BitSetOffset
:
public
BitSetBase
{
56
protected
:
58
A&
a
;
60
int
_offset
;
61
public
:
63
BitSetOffset
(A&
a
,
unsigned
int
s,
int
o);
65
BitSetOffset
(A&
a
,
const
BitSetOffset
& bs);
67
~BitSetOffset
(
void
);
68
69
// As for the ordinary bitset, most operations can be inherited
70
// directly from BitSetBase. We only modify the operations that
71
// involve indices or the offset itself.
72
74
bool
get
(
int
i
)
const
;
76
void
set
(
int
i
);
78
void
clear
(
int
i
);
80
int
next
(
int
i
)
const
;
82
void
resize
(A&
a
,
unsigned
int
n
,
int
offset
,
bool
set
=
false
);
83
85
int
offset
(
void
)
const
;
87
int
max_bit
(
void
)
const
;
89
bool
valid
(
int
i
)
const
;
90
};
91
92
template
<
class
A>
93
forceinline
94
BitSetOffset<A>::BitSetOffset
(A& a0,
unsigned
int
s,
int
o)
95
:
BitSetBase
(a0,s),
a
(a0), _offset(o) {}
96
97
template
<
class
A>
98
forceinline
99
BitSetOffset<A>::BitSetOffset
(
A
& a0,
const
BitSetOffset<A>
& bs)
100
:
BitSetBase
(a0,bs),
a
(a0), _offset(bs._offset) {}
101
102
template
<
class
A>
103
forceinline
104
BitSetOffset<A>::~BitSetOffset
(
void
) {
105
dispose(
a
);
106
}
107
108
template
<
class
A>
109
forceinline
bool
110
BitSetOffset<A>::get
(
int
i
)
const
{
return
BitSetBase::get(
i
-_offset); }
111
112
template
<
class
A>
113
forceinline
void
114
BitSetOffset<A>::set
(
int
i
) { BitSetBase::set(
i
-_offset); }
115
116
template
<
class
A>
117
forceinline
void
118
BitSetOffset<A>::clear
(
int
i
) { BitSetBase::clear(
i
-_offset); }
119
120
template
<
class
A>
121
forceinline
int
122
BitSetOffset<A>::next
(
int
i
)
const
{
return
_offset + BitSetBase::next(
i
-_offset); }
123
124
template
<
class
A>
125
void
126
BitSetOffset<A>::resize
(
A
&
a
,
unsigned
int
n
,
int
offset
,
bool
set) {
127
BitSetBase::resize(
a
,
n
, set);
128
_offset =
offset
;
129
}
130
131
template
<
class
A>
132
forceinline
int
133
BitSetOffset<A>::offset
(
void
)
const
{
return
_offset; }
134
135
template
<
class
A>
136
forceinline
int
137
BitSetOffset<A>::max_bit
(
void
)
const
{
return
_offset +
size
() - 1; }
138
139
template
<
class
A>
140
forceinline
bool
141
BitSetOffset<A>::valid
(
int
i
)
const
{
return
_offset <=
i
&&
i
<= _offset + (int)
size
() - 1; }
142
143
template
<
class
A,
class
Char,
class
Traits>
144
std::basic_ostream<Char,Traits>&
145
operator <<
(std::basic_ostream<Char,Traits>& os,
const
BitSetOffset<A>
& bs) {
146
for
(
int
i
= bs.
offset
() ;
i
< bs.
offset
()+
static_cast<
int
>
(bs.
size
()) ;
i
++)
147
if
(bs.
get
(
i
))
148
os <<
i
<<
" "
;
149
return
os;
150
}
151
152
}}
153
154
// STATISTICS: support-any
155
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Gecode::Support::BitSetOffset::max_bit
int max_bit(void) const
Retrieve the maximum valid index.
Definition:
bitset-offset.hpp:137
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Float::Limits::valid
bool valid(const FloatVal &n)
Return whether float n is a valid number.
Definition:
limits.hpp:43
Gecode::Support::BitSetOffset::_offset
int _offset
Offset.
Definition:
bitset-offset.hpp:60
Gecode
Gecode toplevel namespace
Gecode::Float::FloatView::operator<<
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
Definition:
print.hpp:62
Gecode::Support::BitSetOffset::offset
int offset(void) const
Retrieve the minimum valid index (the offset).
Definition:
bitset-offset.hpp:133
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::Support::BitSetOffset::get
bool get(int i) const
Access value at bit i.
Definition:
bitset-offset.hpp:110
Gecode::Support::BitSetBase
Basic bitset support.
Definition:
bitset-base.hpp:178
Gecode::Support::BitSetOffset::next
int next(int i) const
Return position greater or equal i of next set bit (i is allowed to be equal to size)
Definition:
bitset-offset.hpp:122
Gecode::Support::BitSetOffset::resize
void resize(A &a, unsigned int n, int offset, bool set=false)
Resize bitset to n elements with specified offset.
Definition:
bitset-offset.hpp:126
Gecode::Support::BitSetBase::size
unsigned int size(void) const
Return size of bitset (number of bits)
Definition:
bitset-base.hpp:525
QueenArmies::A
IntSet * A
Position of a piece in a square board.
Definition:
queen-armies.cpp:50
Gecode::Support::BitSetOffset::BitSetOffset
BitSetOffset(A &a, unsigned int s, int o)
Bit set with space for s bits with offset of \o.
Definition:
bitset-offset.hpp:94
Gecode::Support::BitSetOffset::a
A & a
Allocator.
Definition:
bitset-offset.hpp:58
Gecode::Support::BitSetOffset::valid
bool valid(int i) const
Is the bit index valid for this bitset?
Definition:
bitset-offset.hpp:141
Gecode::Int::OffsetView::offset
int offset(void) const
Integer-precision integer scale view.
Definition:
view.hpp:609
Gecode::Support::BitSetOffset::clear
void clear(int i)
Clear bit i.
Definition:
bitset-offset.hpp:118
Gecode::Support::BitSetOffset::set
void set(int i)
Set bit i.
Definition:
bitset-offset.hpp:114
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Support::BitSetOffset
Bitsets with index offset.
Definition:
bitset-offset.hpp:55
Gecode::Support::BitSetOffset::~BitSetOffset
~BitSetOffset(void)
Destructor.
Definition:
bitset-offset.hpp:104