activemq-cpp-3.8.2
BitSet.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DECAF_UTIL_BITSET_H_
19 #define _DECAF_UTIL_BITSET_H_
20 
21 #include <decaf/util/Config.h>
22 
23 #include <string>
24 
25 namespace decaf {
26 namespace util {
27 
46  class DECAF_API BitSet {
47  private:
48 
49  // The actual array of 64 bit bits elements
50  unsigned long long* bits;
51  int bitsSize;
52 
53  // Optimization, when the array is all zero there's no need to traverse
54  bool needClear;
55 
56  // Lazily maintained actual array length and state.
57  mutable int actualArrayLength;
58  mutable bool isLengthActual;
59 
60  private:
61 
62  BitSet(unsigned long long* bits, int bitsSize, bool needClear, int actualArrayLength, bool isLengthActual);
63 
64  public:
65 
69  BitSet();
70 
82  BitSet(int bitCount);
83 
87  BitSet(const BitSet& set);
88 
92  BitSet& operator= (const BitSet& set);
93 
94  virtual ~BitSet();
95 
102  bool operator==(const BitSet& other) const {
103  return this->equals(other);
104  }
105 
112  bool operator!=(const BitSet& other) const {
113  return !this->equals(other);
114  }
115 
116  public:
117 
127  void AND(const BitSet& set);
128 
137  void OR(const BitSet& set);
138 
145  void andNot(const BitSet& set);
146 
152  int cardinality();
153 
157  void clear();
158 
167  void clear(int index);
168 
181  void clear(int fromIndex, int toIndex);
182 
194  bool equals(const BitSet& set) const;
195 
204  void flip(int index);
205 
218  void flip(int fromIndex, int toIndex);
219 
231  bool get(int index) const;
232 
247  BitSet get(int fromIndex, int toIndex) const;
248 
258  bool intersects(const BitSet& set) const;
259 
265  bool isEmpty() const;
266 
273  int length() const;
274 
286  int nextClearBit(int index) const;
287 
299  int nextSetBit(int index) const;
300 
309  void set(int index);
310 
321  void set(int index, bool value);
322 
335  void set(int fromIndex, int toIndex);
336 
351  void set(int fromIndex, int toIndex, bool value);
352 
359  int size() const;
360 
370  std::string toString() const;
371 
384  void XOR(const BitSet& set);
385 
386  private:
387 
395  void ensureCapacity(int length);
396 
405  int getActualArrayLength() const;
406 
407  };
408 
409 }}
410 
411 #endif /* _DECAF_UTIL_BITSET_H_ */
#define DECAF_API
Definition: Config.h:29
This class implements a vector of bits that grows as needed.
Definition: BitSet.h:46
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25
bool operator!=(const BitSet &other) const
Boolean comparison operator !=.
Definition: BitSet.h:112
bool operator==(const BitSet &other) const
Boolean comparison operator ==.
Definition: BitSet.h:102