Lucene++ - a full-featured, c++ search engine
API Documentation


OpenBitSet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
6 
7 #ifndef OPENBITSET_H
8 #define OPENBITSET_H
9 
10 #include "DocIdSet.h"
11 
12 namespace Lucene {
13 
19 class LPPAPI OpenBitSet : public DocIdSet {
20 public:
22  OpenBitSet(int64_t numBits = 64);
23 
33  OpenBitSet(LongArray bits, int32_t numWords);
34 
35  virtual ~OpenBitSet();
36 
38 
39 protected:
40  LongArray bits;
41  int32_t wlen; // number of words (elements) used in the array
42 
43 public:
45 
47  virtual bool isCacheable();
48 
50  int64_t capacity();
51 
54  int64_t size();
55 
57  bool isEmpty();
58 
60  LongArray getBits();
61 
63  void setBits(LongArray bits);
64 
66  int32_t getNumWords();
67 
69  void setNumWords(int32_t numWords);
70 
72  bool get(int32_t index);
73 
76  bool fastGet(int32_t index);
77 
79  bool get(int64_t index);
80 
83  bool fastGet(int64_t index);
84 
87  int32_t getBit(int32_t index);
88 
90  void set(int64_t index);
91 
94  void fastSet(int32_t index);
95 
98  void fastSet(int64_t index);
99 
103  void set(int64_t startIndex, int64_t endIndex);
104 
107  void fastClear(int32_t index);
108 
111  void fastClear(int64_t index);
112 
114  void clear(int64_t index);
115 
119  void clear(int32_t startIndex, int32_t endIndex);
120 
124  void clear(int64_t startIndex, int64_t endIndex);
125 
128  bool getAndSet(int32_t index);
129 
132  bool getAndSet(int64_t index);
133 
136  void fastFlip(int32_t index);
137 
140  void fastFlip(int64_t index);
141 
143  void flip(int64_t index);
144 
147  bool flipAndGet(int32_t index);
148 
151  bool flipAndGet(int64_t index);
152 
156  void flip(int64_t startIndex, int64_t endIndex);
157 
159  int64_t cardinality();
160 
163  static int64_t intersectionCount(const OpenBitSetPtr& a, const OpenBitSetPtr& b);
164 
167  static int64_t unionCount(const OpenBitSetPtr& a, const OpenBitSetPtr& b);
168 
171  static int64_t andNotCount(const OpenBitSetPtr& a, const OpenBitSetPtr& b);
172 
175  static int64_t xorCount(const OpenBitSetPtr& a, const OpenBitSetPtr& b);
176 
179  int32_t nextSetBit(int32_t index);
180 
183  int64_t nextSetBit(int64_t index);
184 
186 
188  void intersect(const OpenBitSetPtr& other);
189 
191  void _union(const OpenBitSetPtr& other);
192 
194  void remove(const OpenBitSetPtr& other);
195 
197  void _xor(const OpenBitSetPtr& other);
198 
200  void _and(const OpenBitSetPtr& other);
201 
203  void _or(const OpenBitSetPtr& other);
204 
206  void andNot(const OpenBitSetPtr& other);
207 
209  bool intersects(const OpenBitSetPtr& other);
210 
213  void ensureCapacityWords(int32_t numWords);
214 
217  void ensureCapacity(int64_t numBits);
218 
221 
223  static int32_t bits2words(int64_t numBits);
224 
226  virtual bool equals(const LuceneObjectPtr& other);
227 
228  virtual int32_t hashCode();
229 
230 protected:
231  int32_t expandingWordNum(int64_t index);
232 };
233 
234 }
235 
236 #endif
LUCENE_CLASS
#define LUCENE_CLASS(Name)
Definition: LuceneObject.h:24
Lucene::OpenBitSet::flipAndGet
bool flipAndGet(int64_t index)
Flips a bit and returns the resulting bit value. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::flip
void flip(int64_t startIndex, int64_t endIndex)
Flips a range of bits, expanding the set size if necessary.
Lucene::OpenBitSet::intersect
void intersect(const OpenBitSetPtr &other)
this = this AND other
Lucene::LuceneObjectPtr
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition: LuceneTypes.h:539
Lucene::OpenBitSet::fastClear
void fastClear(int64_t index)
Clears a bit. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::_union
void _union(const OpenBitSetPtr &other)
this = this OR other
Lucene::OpenBitSet::fastGet
bool fastGet(int32_t index)
Returns true or false for the specified bit index. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::bits
LongArray bits
Definition: OpenBitSet.h:37
Lucene::OpenBitSet::fastSet
void fastSet(int32_t index)
Sets the bit at the specified index. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::getBit
int32_t getBit(int32_t index)
Returns 1 if the bit is set, 0 if not. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::fastFlip
void fastFlip(int32_t index)
Flips a bit. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::setBits
void setBits(LongArray bits)
Sets a new long[] to use as the bit storage.
Lucene::OpenBitSet::flip
void flip(int64_t index)
Flips a bit, expanding the set size if necessary.
Lucene::OpenBitSet::fastClear
void fastClear(int32_t index)
Clears a bit. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::_or
void _or(const OpenBitSetPtr &other)
see union
Lucene::OpenBitSet::trimTrailingZeros
void trimTrailingZeros()
Lowers numWords, the number of words in use, by checking for trailing zero words.
Lucene::OpenBitSet::fastSet
void fastSet(int64_t index)
Sets the bit at the specified index. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::wlen
int32_t wlen
Definition: OpenBitSet.h:41
Lucene::OpenBitSet::clone
virtual LuceneObjectPtr clone(const LuceneObjectPtr &other=LuceneObjectPtr())
Return clone of this object.
DocIdSet.h
Lucene::OpenBitSet::set
void set(int64_t index)
Sets a bit, expanding the set size if necessary.
Lucene::OpenBitSet::expandingWordNum
int32_t expandingWordNum(int64_t index)
Lucene::OpenBitSet::hashCode
virtual int32_t hashCode()
Return hash code for this object.
Lucene::OpenBitSet::getNumWords
int32_t getNumWords()
Gets the number of longs in the array that are in use.
Lucene::DocIdSet
A DocIdSet contains a set of doc ids. Implementing classes must only implement iterator to provide ac...
Definition: DocIdSet.h:16
Lucene::OpenBitSet::nextSetBit
int64_t nextSetBit(int64_t index)
Returns the index of the first set bit starting at the index specified. -1 is returned if there are n...
Lucene
Definition: AbstractAllTermDocs.h:12
Lucene::OpenBitSet::clear
void clear(int64_t startIndex, int64_t endIndex)
Clears a range of bits. Clearing past the end does not change the size of the set.
Lucene::OpenBitSet::clear
void clear(int64_t index)
Clears a bit, allowing access beyond the current set size without changing the size.
Lucene::OpenBitSet::OpenBitSet
OpenBitSet(int64_t numBits=64)
Constructs an OpenBitSet large enough to hold numBits.
Lucene::OpenBitSet::getAndSet
bool getAndSet(int32_t index)
Sets a bit and returns the previous value. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::get
bool get(int32_t index)
Returns true or false for the specified bit index.
Lucene::OpenBitSet::fastGet
bool fastGet(int64_t index)
Returns true or false for the specified bit index. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::iterator
virtual DocIdSetIteratorPtr iterator()
Provides a DocIdSetIterator to access the set. This implementation can return null or EmptyDocIdSet....
Lucene::OpenBitSet::_xor
void _xor(const OpenBitSetPtr &other)
this = this XOR other
Lucene::OpenBitSet::cardinality
int64_t cardinality()
Lucene::OpenBitSet::isEmpty
bool isEmpty()
Returns true if there are no set bits.
Lucene::OpenBitSet::andNot
void andNot(const OpenBitSetPtr &other)
see remove
Lucene::DocIdSetIteratorPtr
boost::shared_ptr< DocIdSetIterator > DocIdSetIteratorPtr
Definition: LuceneTypes.h:324
Lucene::OpenBitSet::clear
void clear(int32_t startIndex, int32_t endIndex)
Clears a range of bits. Clearing past the end does not change the size of the set.
Lucene::OpenBitSetPtr
boost::shared_ptr< OpenBitSet > OpenBitSetPtr
Definition: LuceneTypes.h:543
Lucene::OpenBitSet::equals
virtual bool equals(const LuceneObjectPtr &other)
Returns true if both sets have the same bits set.
Lucene::OpenBitSet::flipAndGet
bool flipAndGet(int32_t index)
Flips a bit and returns the resulting bit value. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::getBits
LongArray getBits()
Returns the long[] storing the bits.
Lucene::OpenBitSet::capacity
int64_t capacity()
Returns the current capacity in bits (1 greater than the index of the last bit)
Lucene::OpenBitSet::fastFlip
void fastFlip(int64_t index)
Flips a bit. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet
An "open" BitSet implementation that allows direct access to the array of words storing the bits.
Definition: OpenBitSet.h:19
Lucene::OpenBitSet::nextSetBit
int32_t nextSetBit(int32_t index)
Returns the index of the first set bit starting at the index specified. -1 is returned if there are n...
Lucene::OpenBitSet::get
bool get(int64_t index)
Returns true or false for the specified bit index.
Lucene::OpenBitSet::isCacheable
virtual bool isCacheable()
This DocIdSet implementation is cacheable.
Lucene::OpenBitSet::size
int64_t size()
Returns the current capacity of this set. Included for compatibility. This is not equal to cardinalit...
Lucene::OpenBitSet::setNumWords
void setNumWords(int32_t numWords)
Sets the number of longs in the array that are in use.
Lucene::OpenBitSet::ensureCapacityWords
void ensureCapacityWords(int32_t numWords)
Expand the LongArray with the size given as a number of words (64 bit longs). getNumWords() is unchan...
Lucene::OpenBitSet::intersects
bool intersects(const OpenBitSetPtr &other)
Returns true if the sets have any elements in common.
Lucene::OpenBitSet::set
void set(int64_t startIndex, int64_t endIndex)
Sets a range of bits, expanding the set size if necessary.
Lucene::OpenBitSet::getAndSet
bool getAndSet(int64_t index)
Sets a bit and returns the previous value. The index should be less than the OpenBitSet size.
Lucene::OpenBitSet::remove
void remove(const OpenBitSetPtr &other)
Remove all elements set in other. this = this AND_NOT other.
Lucene::OpenBitSet::~OpenBitSet
virtual ~OpenBitSet()
Lucene::OpenBitSet::intersectionCount
static int64_t intersectionCount(const OpenBitSetPtr &a, const OpenBitSetPtr &b)
Returns the popcount or cardinality of the intersection of the two sets. Neither set is modified.
Lucene::OpenBitSet::_and
void _and(const OpenBitSetPtr &other)
see intersect
Lucene::OpenBitSet::unionCount
static int64_t unionCount(const OpenBitSetPtr &a, const OpenBitSetPtr &b)
Returns the popcount or cardinality of the union of the two sets. Neither set is modified.
Lucene::OpenBitSet::OpenBitSet
OpenBitSet(LongArray bits, int32_t numWords)
Constructs an OpenBitSet from an existing LongArray.
Lucene::OpenBitSet::bits2words
static int32_t bits2words(int64_t numBits)
Returns the number of 64 bit words it would take to hold numBits.
Lucene::OpenBitSet::ensureCapacity
void ensureCapacity(int64_t numBits)
Ensure that the LongArray is big enough to hold numBits, expanding it if necessary....
Lucene::OpenBitSet::andNotCount
static int64_t andNotCount(const OpenBitSetPtr &a, const OpenBitSetPtr &b)
Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))"....
Lucene::OpenBitSet::xorCount
static int64_t xorCount(const OpenBitSetPtr &a, const OpenBitSetPtr &b)
Returns the popcount or cardinality of the exclusive-or of the two sets. Neither set is modified.

clucene.sourceforge.net