Click here to Skip to main content
15,891,761 members
Articles / Programming Languages / C#

Building .NET Coverage Tool

Rate me:
Please Sign up or sign in to vote.
4.94/5 (34 votes)
25 Aug 2009MIT8 min read 85.3K   2.3K   109  
This article is a walkthrough for building a .NET coverage tool
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation.  All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System;

namespace Microsoft.Cci.Pdb {
  internal struct BitSet {
    internal BitSet(BitAccess bits) {
      bits.ReadInt32(out size);    // 0..3 : Number of words
      words = new uint[size];
      bits.ReadUInt32(words);
    }

    internal BitSet(int size) {
      this.size = size;
      words = new uint[size];
    }

    internal bool IsSet(int index) {
      int word = index / 32;
      if (word >= this.size) return false;
      return ((words[word] & GetBit(index)) != 0);
    }

    internal void Set(int index) {
      int word = index / 32;
      if (word >= this.size) return;
      words[word] |= GetBit(index);
    }

    internal void Clear(int index) {
      int word = index / 32;
      if (word >= this.size) return;
      words[word] &= ~GetBit(index);
    }

    private uint GetBit(int index) {
      return ((uint)1 << (index % 32));
    }

    private uint ReverseBits(uint value) {
      uint o = 0;
      for (int i = 0; i < 32; i++) {
        o = (o << 1) | (value & 1);
        value >>= 1;
      }
      return o;
    }

    internal bool IsEmpty {
      get { return size == 0; }
    }

    internal bool GetWord(int index, out uint word) {
      if (index < size) {
        word = ReverseBits(words[index]);
        return true;
      }
      word = 0;
      return false;
    }

    private int size;
    private uint[] words;
  }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions