1
#ifndef GIM_BITSET_H_INCLUDED
2
#define GIM_BITSET_H_INCLUDED
4
\author Francisco Leon Najera
7
-----------------------------------------------------------------------------
8
This source file is part of GIMPACT Library.
10
For the latest info, see http://gimpact.sourceforge.net/
12
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
13
email: projectileman@yahoo.com
15
This library is free software; you can redistribute it and/or
16
modify it under the terms of EITHER:
17
(1) The GNU Lesser General Public License as published by the Free
18
Software Foundation; either version 2.1 of the License, or (at
19
your option) any later version. The text of the GNU Lesser
20
General Public License is included with this library in the
21
file GIMPACT-LICENSE-LGPL.TXT.
22
(2) The BSD-style license that is included with this library in
23
the file GIMPACT-LICENSE-BSD.TXT.
24
(3) The zlib/libpng license that is included with this library in
25
the file GIMPACT-LICENSE-ZLIB.TXT.
27
This library is distributed in the hope that it will be useful,
28
but WITHOUT ANY WARRANTY; without even the implied warranty of
29
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
30
GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
32
-----------------------------------------------------------------------------
35
#include "gim_array.h"
38
#define GUINT_BIT_COUNT 32
39
#define GUINT_EXPONENT 5
44
gim_array<GUINT> m_container;
51
gim_bitset(GUINT bits_count)
60
inline bool resize(GUINT newsize)
62
GUINT oldsize = m_container.size();
63
m_container.resize(newsize/GUINT_BIT_COUNT + 1,false);
64
while(oldsize<m_container.size())
66
m_container[oldsize] = 0;
73
return m_container.size()*GUINT_BIT_COUNT;
78
for(GUINT i = 0;i<m_container.size();++i)
80
m_container[i] = 0xffffffff;
84
inline void clear_all()
86
for(GUINT i = 0;i<m_container.size();++i)
92
inline void set(GUINT bit_index)
98
m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1)));
102
inline char get(GUINT bit_index)
104
if(bit_index>=size())
108
char value = m_container[bit_index >> GUINT_EXPONENT] &
109
(1 << (bit_index & (GUINT_BIT_COUNT-1)));
113
inline void clear(GUINT bit_index)
115
m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1)));
123
#endif // GIM_CONTAINERS_H_INCLUDED