OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
BitSet.cpp
1/* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
4 *
5 * $Id$
6 */
7#include "antlr/BitSet.hpp"
8#include <string>
9
10#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
11namespace antlr {
12#endif
13
14BitSet::BitSet(unsigned int nbits)
15: storage(nbits)
16{
17 for (unsigned int i = 0; i < nbits ; i++ )
18 storage[i] = false;
19}
20
21BitSet::BitSet( const unsigned long* bits_, unsigned int nlongs )
22: storage(nlongs*32)
23{
24 for ( unsigned int i = 0 ; i < (nlongs * 32); i++)
25 storage[i] = (bits_[i>>5] & (1UL << (i&31))) ? true : false;
26}
27
28BitSet::~BitSet()
29{
30}
31
32void BitSet::add(unsigned int el)
33{
34 if( el >= storage.size() )
35 storage.resize( el+1, false );
36
37 storage[el] = true;
38}
39
40bool BitSet::member(unsigned int el) const
41{
42 if ( el >= storage.size())
43 return false;
44
45 return storage[el];
46}
47
48ANTLR_USE_NAMESPACE(std)vector<unsigned int> BitSet::toArray() const
49{
50 ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems;
51 for (unsigned int i = 0; i < storage.size(); i++)
52 {
53 if (storage[i])
54 elems.push_back(i);
55 }
56
57 return elems;
58}
59
60#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
61}
62#endif