Generated on Sat Feb 7 2015 02:01:31 for Gecode by doxygen 1.8.9.1
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>
94  BitSetOffset<A>::BitSetOffset(A& a0, unsigned int s, int o)
95  : BitSetBase(a0,s), a(a0), _offset(o) {}
96 
97  template<class A>
100  : BitSetBase(a0,bs), a(a0), _offset(bs._offset) {}
101 
102  template<class A>
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
115 
116  template<class A>
117  forceinline void
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 
bool get(unsigned int i) const
Access value at bit i.
void clear(unsigned int i)
Clear bit i.
void resize(A &a, unsigned int n, int offset, bool set=false)
Resize bitset to n elements with specified offset.
Basic bitset support.
BitSetOffset(A &a, unsigned int s, int o)
Bit set with space for s bits with offset of .
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
bool get(int i) const
Access value at bit i.
void clear(int i)
Clear bit i.
int next(int i) const
Return position greater or equal i of next set bit (i is allowed to be equal to size) ...
unsigned int size(I &i)
Size of all ranges of range iterator i.
void set(unsigned int i)
Set bit i.
unsigned int next(unsigned int i) const
Return position greater or equal i of next set bit (i is allowed to be equal to size) ...
#define forceinline
Definition: config.hpp:132
bool valid(int i) const
Is the bit index valid for this bitset?
void set(int i)
Set bit i.
void resize(A &a, unsigned int n, bool setbits=false)
Resize bitset to n elememts.
int offset(void) const
Retrieve the minimum valid index (the offset).
Gecode toplevel namespace
int max_bit(void) const
Retrieve the maximum valid index.
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
Bitsets with index offset.