Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
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>
90  BitSetOffset<A>::BitSetOffset(A& a0, unsigned int s, int o)
91  : BitSetBase(a0,s), a(a0), _offset(o) {}
92 
93  template<class A>
96  : BitSetBase(a0,bs), a(a0), _offset(bs._offset) {}
97 
98  template<class A>
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 
int next(int i) const
Return position greater or equal i of next set bit (i is allowed to be equal to size) ...
bool valid(const FloatVal &n)
Return whether float n is a valid number.
Definition: limits.hpp:39
int offset(void) const
Retrieve the minimum valid index (the offset).
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 .
#define forceinline
Definition: config.hpp:185
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
void clear(int i)
Clear bit i.
unsigned int size(I &i)
Size of all ranges of range iterator i.
int max_bit(void) const
Retrieve the maximum valid index.
Gecode toplevel namespace
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
bool valid(int i) const
Is the bit index valid for this bitset?
Bitsets with index offset.