Author: alanmc
Date: 2006-12-05 13:15:58 -0500 (Tue, 05 Dec 2006)
New Revision: 69058
Modified:
trunk/bitsharp/src/MonoTorrent.Client/BitField.cs
Log:
Some changes so that the last bits are always false (verify if this is
needed...) and a bug fix in the FromArray() methods so that truecount isn't
double-counted
Modified: trunk/bitsharp/src/MonoTorrent.Client/BitField.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/BitField.cs 2006-12-05 17:33:34 UTC
(rev 69057)
+++ trunk/bitsharp/src/MonoTorrent.Client/BitField.cs 2006-12-05 18:15:58 UTC
(rev 69058)
@@ -124,6 +124,7 @@
for (int i = 0; i < this.array.Length; i++)
this.array[i] = ~this.array[i];
+ SetLastBitsFalse();
return this;
}
@@ -138,9 +139,13 @@
if (value == null)
throw new ArgumentNullException("value");
+ if (this.length != value.length)
+ throw new ArgumentException("BitFields are of different
lengths", "value");
+
for (int i = 0; i < this.array.Length; i++)
this.array[i] &= value.array[i];
+ SetLastBitsFalse();
return this;
}
@@ -155,9 +160,13 @@
if (value == null)
throw new ArgumentNullException("value");
+ if (this.length != value.length)
+ throw new ArgumentException("BitFields are of different
lengths", "value");
+
for (int i = 0; i < this.array.Length; i++)
this.array[i] &= ~value.array[i];
+ SetLastBitsFalse();
return this;
}
@@ -172,9 +181,13 @@
if (value == null)
throw new ArgumentNullException("value");
+ if (this.length != value.length)
+ throw new ArgumentException("BitFields are of different
lengths", "value");
+
for (int i = 0; i < this.array.Length; i++)
this.array[i] |= value.array[i];
+ SetLastBitsFalse();
return this;
}
@@ -189,9 +202,13 @@
if (value == null)
throw new ArgumentNullException("value");
+ if (this.length != value.length)
+ throw new ArgumentException("BitFields are of different
lengths", "value");
+
for (int i = 0; i < this.array.Length; i++)
this.array[i] ^= value.array[i];
+ SetLastBitsFalse();
return this;
}
@@ -247,6 +264,7 @@
for (int i = 0; i < this.array.Length; i++)
this.array[i] = ~0;
this.trueCount = this.length;
+ SetLastBitsFalse();
}
else
@@ -255,7 +273,10 @@
this.array[i] = 0;
this.trueCount = 0;
}
+ }
+ private void SetLastBitsFalse()
+ {
// clear out the remaining space
int end = ((int)((this.length + 31) / 32)) * 32;
for (int i = this.length; i < end; ++i)
@@ -381,20 +402,17 @@
#warning Check the remaining bits in the last byte to make sure they're 0. use
the length parameter
internal void FromArray(byte[] buffer, int offset, int length)
{
- bool temp;
+ byte p = 128;
+ bool temp = false;
+ this.trueCount = 0;
+
if (buffer == null)
throw new ArgumentNullException("buffer");
- this.trueCount = 0;
- byte p = 128;
-
for (int i = 0; i < this.length; i++)
{
temp = ((buffer[offset] & p) != 0);
- if (temp)
- this.trueCount++;
-
- this[i] = temp;
+ this.Set(i, temp);
p >>= 1;
if (p != 0)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches