]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/BitSet.cpp
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / antlr2 / src / 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: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/BitSet.cpp#2 $
6 */
7 #include "antlr/BitSet.hpp"
8 #include <string>
9
10 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
11 namespace antlr {
12 #endif
13
14 BitSet::BitSet(unsigned int nbits)
15 : storage(nbits)
16 {
17 for (unsigned int i = 0; i < nbits ; i++ )
18 storage[i] = false;
19 }
20
21 BitSet::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
28 BitSet::~BitSet()
29 {
30 }
31
32 void BitSet::add(unsigned int el)
33 {
34 if( el >= storage.size() )
35 storage.resize( el+1, false );
36
37 storage[el] = true;
38 }
39
40 bool BitSet::member(unsigned int el) const
41 {
42 if ( el >= storage.size())
43 return false;
44
45 return storage[el];
46 }
47
48 ANTLR_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