Author: alanmc
Date: 2008-02-02 20:33:29 -0500 (Sat, 02 Feb 2008)
New Revision: 94664

Modified:
   trunk/bitsharp/src/MonoTorrent/MonoTorrent.Common/BitField.cs
Log:
Added Bitfield (bool[]) constructor.
Fixed bug in FromArray (found in Nunit test).

Modified: trunk/bitsharp/src/MonoTorrent/MonoTorrent.Common/BitField.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/MonoTorrent.Common/BitField.cs       
2008-02-03 00:49:32 UTC (rev 94663)
+++ trunk/bitsharp/src/MonoTorrent/MonoTorrent.Common/BitField.cs       
2008-02-03 01:33:29 UTC (rev 94664)
@@ -86,6 +86,15 @@
             this.length = length;
             this.array = new int[(length + 31) / 32];
         }
+
+        public BitField(bool[] array)
+        {
+            this.length = array.Length;
+            this.array = new int[(array.Length + 31) / 32];
+            for (int i = 0; i < array.Length; i++)
+                Set(i, array[i]);
+        }
+
         #endregion
 
 
@@ -262,7 +271,6 @@
                 if ((this.array[index >> 5] & (1 << (index & 31))) == 0)// If 
it's not already true
                     trueCount++;                                        // 
Increase true count
                 this.array[index >> 5] |= (1 << (index & 31));
-
             }
             else
             {
@@ -432,7 +440,7 @@
             }
 
             // Make sure all extra bits are set to zero
-            for (int i = this.length; i < this.length + this.length % 8; i++)
+            for (int i = this.length; i < this.length + (8 - this.length % 8); 
i++)
             {
                 temp = ((buffer[offset] & p) != 0);
                 if (temp)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to