activemq-cpp-3.9.5
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
25namespace decaf {
26namespace 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
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
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_ */
bool equals(const BitSet &set) const
Compares this object against the specified object.
void set(int fromIndex, int toIndex)
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to true.
void XOR(const BitSet &set)
Performs a logical XOR of this bit set with the bit set argument.
bool operator!=(const BitSet &other) const
Boolean comparison operator !=.
Definition BitSet.h:112
void set(int index, bool value)
Sets the bit at the specified index to the specified value.
void set(int index)
Sets the bit at the specified index to true.
void clear()
Sets all of the bits in this BitSet to false.
bool get(int index) const
Returns the value of the bit with the specified index.
BitSet get(int fromIndex, int toIndex) const
Returns a new BitSet composed of bits from this BitSet from fromIndex (inclusive) to toIndex (exclusi...
int nextClearBit(int index) const
Returns the index of the first bit that is set to false that occurs on or after the specified startin...
bool intersects(const BitSet &set) const
Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSe...
int cardinality()
Returns the number of bits set to true in this BitSet.
BitSet()
Creates a new BitSet whose bits are all false.
void set(int fromIndex, int toIndex, bool value)
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to the va...
std::string toString() const
Returns a string representation of this bit set.
int length() const
Returns the "logical size" of this BitSet: the index of the highest set bit in the BitSet plus one.
void flip(int fromIndex, int toIndex)
Sets each bit from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to the co...
bool operator==(const BitSet &other) const
Boolean comparison operator ==.
Definition BitSet.h:102
BitSet(int bitCount)
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the...
void OR(const BitSet &set)
Performs a logical OR of this bit set with the bit set argument.
int nextSetBit(int index) const
Returns the index of the first bit that is set to true that occurs on or after the specified starting...
bool isEmpty() const
Returns true if this BitSet contains no bits that are set to true.
void clear(int index)
Sets the bit specified by the index to false.
int size() const
Returns the number of bits of space actually in use by this BitSet to represent bit values.
void clear(int fromIndex, int toIndex)
Sets the bits from the specified fromIndex (inclusive) to the specified toIndex (exclusive) to false.
void andNot(const BitSet &set)
Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.
void AND(const BitSet &set)
Performs a logical AND of this target bit set with the argument bit set.
BitSet(const BitSet &set)
Copy Constructor.
void flip(int index)
Sets the bit at the specified index to the complement of its current value.
#define DECAF_API
Definition Config.h:29
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25