[Mono-list] [PATCH] BitVector32
Andrew Birkett
adb@tardis.ed.ac.uk
Fri, 21 Jun 2002 13:31:58 +0100 (BST)
(This is my first mono patch, please be gentle!)
Implemented the 'set' part of the BitVector32.Section indexer.
Renamed BitVector32 field from 'value' to 'bits' since 'value' has special
meaning in indexers. Also renamed indexer argument from 'bit' to 'mask'
since it is a mask
Index: BitVector32.cs
===================================================================
RCS file: /mono/mcs/class/System/System.Collections.Specialized/BitVector32.cs,v
retrieving revision 1.4
diff -u -r1.4 BitVector32.cs
--- BitVector32.cs 9 May 2002 20:05:33 -0000 1.4
+++ BitVector32.cs 21 Jun 2002 12:21:05 -0000
@@ -14,7 +14,7 @@
namespace System.Collections.Specialized {
public struct BitVector32 {
- int value;
+ int bits;
public struct Section {
private short mask;
@@ -60,35 +60,39 @@
public BitVector32 (BitVector32 source)
{
- value = source.value;
+ bits = source.bits;
}
public BitVector32 (int init)
{
- value = init;
+ bits = init;
}
// Properties
public int Data {
- get { return value; }
+ get { return bits; }
}
- [MonoTODO]
public int this [BitVector32.Section section] {
- get { return ((this.value >> section.Offset) & section.Mask); }
+ get { return ((bits >> section.Offset) & section.Mask); }
set {
- throw new NotImplementedException ();
+ if (value < 0)
+ throw new ArgumentException ("Section can't hold negative values");
+ if (value > section.Mask)
+ throw new ArgumentException ("Value too large to fit in section");
+ bits &= (~section.Mask << section.Offset);
+ bits |= (value << section.Offset);
}
}
- public bool this [int bit] {
- get { return (value & bit) == bit; }
+ public bool this [int mask] {
+ get { return (bits & mask) == mask; }
set {
if (value)
- this.value |= bit;
+ bits |= mask;
else
- this.value &= ~bit;
+ bits &= ~mask;
}
}
@@ -144,12 +148,12 @@
if (!(o is BitVector32))
return false;
- return value == ((BitVector32) o).value;
+ return bits == ((BitVector32) o).bits;
}
public override int GetHashCode ()
{
- return value.GetHashCode ();
+ return bits.GetHashCode ();
}
public override string ToString ()
@@ -159,12 +163,11 @@
public static string ToString (BitVector32 value)
{
- long val = (long) value.value;
StringBuilder b = new StringBuilder ();
b.Append ("BitVector32{");
long mask = (long) 0x80000000;
while (mask > 0) {
- b.Append (((val & mask) == 0) ? '0' : '1');
+ b.Append (((value.bits & mask) == 0) ? '0' : '1');
mask >>= 1;
}
b.Append ('}');
--
- www.tardis.ed.ac.uk/~adb -