main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 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
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <climits>
41
#include <cmath>
42
#include <iostream>
43
44
namespace
Gecode
{
namespace
Support {
45
50
template
<
class
A>
51
class
BitSetOffset
:
public
BitSetBase
{
52
protected
:
54
A&
a
;
56
int
_offset
;
57
public
:
59
BitSetOffset
(A&
a
,
unsigned
int
s,
int
o);
61
BitSetOffset
(A&
a
,
const
BitSetOffset
& bs);
63
~BitSetOffset
(
void
);
64
65
// As for the ordinary bitset, most operations can be inherited
66
// directly from BitSetBase. We only modify the operations that
67
// involve indices or the offset itself.
68
70
bool
get
(
int
i
)
const
;
72
void
set
(
int
i
);
74
void
clear
(
int
i
);
76
int
next
(
int
i
)
const
;
78
void
resize
(A&
a
,
unsigned
int
n
,
int
offset
,
bool
set
=
false
);
79
81
int
offset
(
void
)
const
;
83
int
max_bit
(
void
)
const
;
85
bool
valid
(
int
i
)
const
;
86
};
87
88
template
<
class
A>
89
forceinline
90
BitSetOffset<A>::BitSetOffset
(A& a0,
unsigned
int
s,
int
o)
91
:
BitSetBase
(a0,s),
a
(a0), _offset(o) {}
92
93
template
<
class
A>
94
forceinline
95
BitSetOffset<A>::BitSetOffset
(
A
& a0,
const
BitSetOffset<A>
& bs)
96
:
BitSetBase
(a0,bs),
a
(a0), _offset(bs._offset) {}
97
98
template
<
class
A>
99
forceinline
100
BitSetOffset<A>::~BitSetOffset
(
void
) {
101
dispose(
a
);
102
}
103
104
template
<
class
A>
105
forceinline
bool
106
BitSetOffset<A>::get
(
int
i
)
const
{
return
BitSetBase::get(
i
-_offset); }
107
108
template
<
class
A>
109
forceinline
void
110
BitSetOffset<A>::set
(
int
i
) { BitSetBase::set(
i
-_offset); }
111
112
template
<
class
A>
113
forceinline
void
114
BitSetOffset<A>::clear
(
int
i
) { BitSetBase::clear(
i
-_offset); }
115
116
template
<
class
A>
117
forceinline
int
118
BitSetOffset<A>::next
(
int
i
)
const
{
return
_offset + BitSetBase::next(
i
-_offset); }
119
120
template
<
class
A>
121
void
122
BitSetOffset<A>::resize
(
A
&
a
,
unsigned
int
n
,
int
offset
,
bool
set) {
123
BitSetBase::resize(
a
,
n
, set);
124
_offset =
offset
;
125
}
126
127
template
<
class
A>
128
forceinline
int
129
BitSetOffset<A>::offset
(
void
)
const
{
return
_offset; }
130
131
template
<
class
A>
132
forceinline
int
133
BitSetOffset<A>::max_bit
(
void
)
const
{
return
_offset +
size
() - 1; }
134
135
template
<
class
A>
136
forceinline
bool
137
BitSetOffset<A>::valid
(
int
i
)
const
{
return
_offset <=
i
&&
i
<= _offset + (int)
size
() - 1; }
138
139
template
<
class
A,
class
Char,
class
Traits>
140
std::basic_ostream<Char,Traits>&
141
operator <<
(std::basic_ostream<Char,Traits>& os,
const
BitSetOffset<A>
& bs) {
142
for
(
int
i
= bs.
offset
() ;
i
< bs.
offset
()+
static_cast<
int
>
(bs.
size
()) ;
i
++)
143
if
(bs.
get
(
i
))
144
os <<
i
<<
" "
;
145
return
os;
146
}
147
148
}}
149
150
// STATISTICS: support-any
151
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Gecode::Support::BitSetOffset::max_bit
int max_bit(void) const
Retrieve the maximum valid index.
Definition:
bitset-offset.hpp:133
Gecode::Float::Limits::valid
bool valid(const FloatVal &n)
Return whether float n is a valid number.
Definition:
limits.hpp:39
Gecode::Support::BitSetOffset::_offset
int _offset
Offset.
Definition:
bitset-offset.hpp:56
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.
Gecode::Support::BitSetOffset::offset
int offset(void) const
Retrieve the minimum valid index (the offset).
Definition:
bitset-offset.hpp:129
Gecode::Support::BitSetOffset::get
bool get(int i) const
Access value at bit i.
Definition:
bitset-offset.hpp:106
Gecode::Support::BitSetBase
Basic bitset support.
Definition:
bitset-base.hpp:190
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:118
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:122
Gecode::Support::BitSetBase::size
unsigned int size(void) const
Return size of bitset (number of bits)
Definition:
bitset-base.hpp:585
QueenArmies::A
IntSet * A
Position of a piece in a square board.
Definition:
queen-armies.cpp:46
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:90
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Gecode::Support::BitSetOffset::a
A & a
Allocator.
Definition:
bitset-offset.hpp:54
Gecode::Support::BitSetOffset::valid
bool valid(int i) const
Is the bit index valid for this bitset?
Definition:
bitset-offset.hpp:137
Gecode::Int::OffsetView::offset
int offset(void) const
Integer-precision integer scale view.
Definition:
view.hpp:642
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Support::BitSetOffset::clear
void clear(int i)
Clear bit i.
Definition:
bitset-offset.hpp:114
Gecode::Support::BitSetOffset::set
void set(int i)
Set bit i.
Definition:
bitset-offset.hpp:110
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Support::BitSetOffset
Bitsets with index offset.
Definition:
bitset-offset.hpp:51
Gecode::Support::BitSetOffset::~BitSetOffset
~BitSetOffset(void)
Destructor.
Definition:
bitset-offset.hpp:100