Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2893_BNLR/HeuristicLab.ExtLibs/HeuristicLab.Cecil/0.9.5/Mono.Cecil-0.9.5/Symbols/Mono.Cecil.Pdb/Microsoft.Cci.Pdb/BitSet.cs

Last change on this file was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 1.6 KB
Line 
1//-----------------------------------------------------------------------------
2//
3// Copyright (C) Microsoft Corporation.  All Rights Reserved.
4//
5//-----------------------------------------------------------------------------
6using System;
7
8namespace 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);
14    }
15
16    internal BitSet(int size) {
17      this.size = size;
18      words = new uint[size];
19    }
20
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);
25    }
26
27    internal void Set(int index) {
28      int word = index / 32;
29      if (word >= this.size) return;
30      words[word] |= GetBit(index);
31    }
32
33    internal void Clear(int index) {
34      int word = index / 32;
35      if (word >= this.size) return;
36      words[word] &= ~GetBit(index);
37    }
38
39    private uint GetBit(int index) {
40      return ((uint)1 << (index % 32));
41    }
42
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;
48      }
49      return o;
50    }
51
52    internal bool IsEmpty {
53      get { return size == 0; }
54    }
55
56    internal bool GetWord(int index, out uint word) {
57      if (index < size) {
58        word = ReverseBits(words[index]);
59        return true;
60      }
61      word = 0;
62      return false;
63    }
64
65    private int size;
66    private uint[] words;
67  }
68
69}
Note: See TracBrowser for help on using the repository browser.