tests: Update python packages
[vpp.git] / src / vppinfra / bitmap.h
index d18cf30..459e6f2 100644 (file)
@@ -45,7 +45,6 @@
 #include <vppinfra/vec.h>
 #include <vppinfra/random.h>
 #include <vppinfra/error.h>
-#include <vppinfra/bitops.h>   /* for count_set_bits */
 
 typedef uword clib_bitmap_t;
 
@@ -115,6 +114,24 @@ clib_bitmap_is_equal (uword * a, uword * b)
 #define clib_bitmap_validate(v,n_bits) \
   clib_bitmap_vec_validate ((v), ((n_bits) - 1) / BITS (uword))
 
+/** Copy a bitmap
+    @param dst - copy to
+    @param src - copy from
+*/
+static_always_inline void
+clib_bitmap_copy (clib_bitmap_t **dst, const clib_bitmap_t *src)
+{
+  if (vec_len (src))
+    {
+      clib_bitmap_vec_validate (*dst, vec_len (src) - 1);
+      vec_copy (*dst, src);
+    }
+  else
+    {
+      vec_reset_length (*dst);
+    }
+}
+
 /* low-level routine to remove trailing zeros from a bitmap */
 always_inline uword *
 _clib_bitmap_remove_trailing_zeros (uword * a)
@@ -188,6 +205,14 @@ clib_bitmap_set (uword * ai, uword i, uword value)
   return ai;
 }
 
+always_inline u8
+clib_bitmap_will_expand (uword *ai, uword i)
+{
+  uword i0 = i / BITS (ai[0]);
+  return _vec_resize_will_expand (ai, 1, i0 * sizeof (ai[0]), 0,
+                                 sizeof (uword));
+}
+
 /** Gets the ith bit value from a bitmap
     @param ai - pointer to the bitmap
     @param i - the bit position to interrogate
@@ -364,25 +389,6 @@ clib_bitmap_set_region (uword * bitmap, uword i, uword value, uword n_bits)
         i != ~0;                                                       \
         i = clib_bitmap_next_set (ai, i + 1))
 
-#define clib_bitmap_foreach_old(i,ai,body)                             \
-do {                                                                   \
-  uword __bitmap_i, __bitmap_ai, __bitmap_len, __bitmap_first_set;     \
-  __bitmap_len = vec_len ((ai));                                       \
-  for (__bitmap_i = 0; __bitmap_i < __bitmap_len; __bitmap_i++)                \
-    {                                                                  \
-      __bitmap_ai = (ai)[__bitmap_i];                                  \
-      while (__bitmap_ai != 0)                                         \
-       {                                                               \
-         __bitmap_first_set = first_set (__bitmap_ai);                 \
-         (i) = (__bitmap_i * BITS ((ai)[0])                            \
-                + min_log2 (__bitmap_first_set));                      \
-         do { body; } while (0);                                       \
-         __bitmap_ai ^= __bitmap_first_set;                            \
-       }                                                               \
-    }                                                                  \
-} while (0)
-
-
 /** Return the lowest numbered set bit in a bitmap
     @param ai - pointer to the bitmap
     @returns lowest numbered set bit, or ~0 if the entire bitmap is zero
@@ -735,8 +741,7 @@ clib_bitmap_next_clear (uword * ai, uword i)
            return log2_first_set (t) + i0 * BITS (ai[0]);
        }
 
-      /* no clear bit left in bitmap, return bit just beyond bitmap */
-      return (i0 * BITS (ai[0])) + 1;
+      return i0 * BITS (ai[0]);
     }
   return i;
 }