1 /*
2  * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3  *
4  * Distributable under the terms of either the Apache License (Version 2.0) or
5  * the GNU Lesser General Public License, as specified in the COPYING file.
6  *
7  * Changes are Copyright(C) 2007, 2008 by Nokia Corporation and/or its subsidiary(-ies), all rights reserved.
8 */
9 #ifndef _lucene_util_BitSet_
10 #define _lucene_util_BitSet_
11 
12 #if defined(_LUCENE_PRAGMA_ONCE)
13 #   pragma once
14 #endif
15 
16 #include <QtCore/QString>
17 
18 #include "CLucene/store/Directory.h"
19 
CL_NS_DEF(util)20 CL_NS_DEF(util)
21 
22 class BitSet : LUCENE_BASE
23 {
24 public:
25 	// Create a bitset with the specified size
26 	BitSet (int32_t size);
27 	BitSet(CL_NS(store)::Directory* d, const QString& name);
28 	void write(CL_NS(store)::Directory* d, const QString& name);
29 
30 	// Destructor for the bit set
31 	~BitSet();
32 
33 	// get the value of the specified bit
34 	inline bool get(const int32_t bit) const
35     {
36 		return (bits[bit >> 3] & (1 << (bit & 7))) != 0;
37 	}
38 
39 	// set the value of the specified bit
40 	void set(int32_t bit, bool val = true);
41 
42 	///returns the size of the bitset
43 	int32_t size() const;
44 
45 	// Returns the total number of one bits in this BitSet. This is
46 	// efficiently computed and cached, so that, if the BitSet is not changed,
47     // no recomputation is done for repeated calls.
48 	int32_t count();
49 	BitSet *clone() const;
50 
51 protected:
52 	BitSet(const BitSet& copy);
53 
54 private:
55 	int32_t _size;
56 	int32_t _count;
57 	uint8_t *bits;
58 };
59 
60 CL_NS_END
61 
62 #endif
63