BitSet.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft. All rights reserved.
  4. // This code is licensed under the Microsoft Public License.
  5. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  6. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  7. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  8. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  9. //
  10. //-----------------------------------------------------------------------------
  11. using System;
  12. namespace Microsoft.Cci.Pdb {
  13. internal struct BitSet {
  14. internal BitSet(BitAccess bits) {
  15. bits.ReadInt32(out size); // 0..3 : Number of words
  16. words = new uint[size];
  17. bits.ReadUInt32(words);
  18. }
  19. //internal BitSet(int size) {
  20. // this.size = size;
  21. // words = new uint[size];
  22. //}
  23. internal bool IsSet(int index) {
  24. int word = index / 32;
  25. if (word >= this.size) return false;
  26. return ((words[word] & GetBit(index)) != 0);
  27. }
  28. //internal void Set(int index) {
  29. // int word = index / 32;
  30. // if (word >= this.size) return;
  31. // words[word] |= GetBit(index);
  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. private static uint GetBit(int index) {
  39. return ((uint)1 << (index % 32));
  40. }
  41. //private static uint ReverseBits(uint value) {
  42. // uint o = 0;
  43. // for (int i = 0; i < 32; i++) {
  44. // o = (o << 1) | (value & 1);
  45. // value >>= 1;
  46. // }
  47. // return o;
  48. //}
  49. internal bool IsEmpty {
  50. get { return size == 0; }
  51. }
  52. //internal bool GetWord(int index, out uint word) {
  53. // if (index < size) {
  54. // word = ReverseBits(words[index]);
  55. // return true;
  56. // }
  57. // word = 0;
  58. // return false;
  59. //}
  60. private int size;
  61. private uint[] words;
  62. }
  63. }