Author: lupus
Date: 2006-03-20 08:51:09 -0500 (Mon, 20 Mar 2006)
New Revision: 58181

Modified:
   trunk/mono/mono/utils/ChangeLog
   trunk/mono/mono/utils/monobitset.c
   trunk/mono/mono/utils/monobitset.h
Log:


Mon Mar 20 14:50:35 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>

        * monobitset.c, monobitset.h: added mono_bitset_find_first_unset ().



Modified: trunk/mono/mono/utils/ChangeLog
===================================================================
--- trunk/mono/mono/utils/ChangeLog     2006-03-20 13:37:55 UTC (rev 58180)
+++ trunk/mono/mono/utils/ChangeLog     2006-03-20 13:51:09 UTC (rev 58181)
@@ -1,3 +1,8 @@
+
+Mon Mar 20 14:50:35 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>
+
+       * monobitset.c, monobitset.h: added mono_bitset_find_first_unset ().
+
 2006-03-16  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * monobitset.c: Guard inline asm with #ifdef __GNUC__.

Modified: trunk/mono/mono/utils/monobitset.c
===================================================================
--- trunk/mono/mono/utils/monobitset.c  2006-03-20 13:37:55 UTC (rev 58180)
+++ trunk/mono/mono/utils/monobitset.c  2006-03-20 13:51:09 UTC (rev 58181)
@@ -383,6 +383,22 @@
        return -1;
 }
 
+static int
+find_first_unset (gulong mask, gint nth_bit)
+{
+       do {
+               nth_bit++;
+               if (!(mask & ((gsize)1 << nth_bit))) {
+                       if (nth_bit == BITS_PER_CHUNK)
+                               /* On 64 bit platforms, 1 << 64 == 1 */
+                               return -1;
+                       else
+                               return nth_bit;
+               }
+       } while (nth_bit < BITS_PER_CHUNK);
+       return -1;
+}
+
 /*
  * mono_bitset_find_start:
  * @set: bitset ptr
@@ -470,6 +486,43 @@
 }
 
 /*
+ * mono_bitset_find_first_unset:
+ * @set: bitset ptr
+ * @pos: pos to search _after_ (not including)
+ *
+ * Returns position of first unset bit after @pos. If pos < 0 begin search from
+ * start. Return -1 if no bit set is found.
+ */
+int
+mono_bitset_find_first_unset (const MonoBitSet *set, gint pos) {
+       int j;
+       int bit;
+       int result, i;
+
+       if (pos < 0) {
+               j = 0;
+               bit = -1;
+       } else {
+               j = pos / BITS_PER_CHUNK;
+               bit = pos % BITS_PER_CHUNK;
+               g_return_val_if_fail (pos < set->size, -1);
+       }
+       /*g_print ("find first from %d (j: %d, bit: %d)\n", pos, j, bit);*/
+
+       if (set->data [j] != -1) {
+               result = find_first_unset (set->data [j], bit);
+               if (result != -1)
+                       return result + j * BITS_PER_CHUNK;
+       }
+       for (i = ++j; i < set->size / BITS_PER_CHUNK; ++i) {
+               if (set->data [i] != -1) {
+                       return find_first_unset (set->data [i], -1) + i * 
BITS_PER_CHUNK;
+               }
+       }
+       return -1;
+}
+
+/*
  * mono_bitset_clone:
  * @set: bitset ptr to clone
  * @new_size: number of bits the cloned bitset can hold

Modified: trunk/mono/mono/utils/monobitset.h
===================================================================
--- trunk/mono/mono/utils/monobitset.h  2006-03-20 13:37:55 UTC (rev 58180)
+++ trunk/mono/mono/utils/monobitset.h  2006-03-20 13:51:09 UTC (rev 58181)
@@ -57,6 +57,8 @@
 
 int         mono_bitset_find_last    (const MonoBitSet *set, gint pos);
 
+int         mono_bitset_find_first_unset (const MonoBitSet *set, gint pos);
+
 MonoBitSet* mono_bitset_clone        (const MonoBitSet *set, guint32 new_size);
 
 void        mono_bitset_copyto       (const MonoBitSet *src, MonoBitSet *dest);

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

Reply via email to