update MEF to preview 9
[mcs.git] / tools / pdb2mdb / BitSet.cs
bloba9ed7f76e6d8c559a5921e6d50b766b72b7c5099
1 //-----------------------------------------------------------------------------
2 //
3 // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 //
5 //-----------------------------------------------------------------------------
6 using System;
8 namespace Microsoft.Cci.Pdb {
9 internal struct BitSet {
10 internal BitSet(BitAccess bits) {
11 bits.ReadInt32(out size); // 0..3 : Number of words
12 words = new uint[size];
13 bits.ReadUInt32(words);
16 internal BitSet(int size) {
17 this.size = size;
18 words = new uint[size];
21 internal bool IsSet(int index) {
22 int word = index / 32;
23 if (word >= this.size) return false;
24 return ((words[word] & GetBit(index)) != 0);
27 internal void Set(int index) {
28 int word = index / 32;
29 if (word >= this.size) return;
30 words[word] |= GetBit(index);
33 internal void Clear(int index) {
34 int word = index / 32;
35 if (word >= this.size) return;
36 words[word] &= ~GetBit(index);
39 private uint GetBit(int index) {
40 return ((uint)1 << (index % 32));
43 private uint ReverseBits(uint value) {
44 uint o = 0;
45 for (int i = 0; i < 32; i++) {
46 o = (o << 1) | (value & 1);
47 value >>= 1;
49 return o;
52 internal bool IsEmpty {
53 get { return size == 0; }
56 internal bool GetWord(int index, out uint word) {
57 if (index < size) {
58 word = ReverseBits(words[index]);
59 return true;
61 word = 0;
62 return false;
65 private int size;
66 private uint[] words;