activemq-cpp-3.6.0
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 
96  public:
97 
107  void AND(const BitSet& set);
108 
117  void OR(const BitSet& set);
118 
125  void andNot(const BitSet& set);
126 
132  int cardinality();
133 
137  void clear();
138 
147  void clear(int index);
148 
161  void clear(int fromIndex, int toIndex);
162 
174  bool equals(const BitSet& set) const;
175 
184  void flip(int index);
185 
198  void flip(int fromIndex, int toIndex);
199 
211  bool get(int index) const;
212 
227  BitSet get(int fromIndex, int toIndex) const;
228 
238  bool intersects(const BitSet& set) const;
239 
245  bool isEmpty() const;
246 
253  int length() const;
254 
266  int nextClearBit(int index) const;
267 
279  int nextSetBit(int index) const;
280 
289  void set(int index);
290 
301  void set(int index, bool value);
302 
315  void set(int fromIndex, int toIndex);
316 
331  void set(int fromIndex, int toIndex, bool value);
332 
339  int size() const;
340 
350  std::string toString() const;
351 
364  void XOR(const BitSet& set);
365 
366  private:
367 
375  void ensureCapacity(int length);
376 
385  int getActualArrayLength() const;
386 
387  };
388 
389 }}
390 
391 #endif /* _DECAF_UTIL_BITSET_H_ */