aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/base/bitmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/base/bitmap.h')
-rw-r--r--hicn-light/src/hicn/base/bitmap.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/hicn-light/src/hicn/base/bitmap.h b/hicn-light/src/hicn/base/bitmap.h
index 1159806c8..46d473ff8 100644
--- a/hicn-light/src/hicn/base/bitmap.h
+++ b/hicn-light/src/hicn/base/bitmap.h
@@ -66,6 +66,13 @@ bitmap_ensure_pos(bitmap_t ** bitmap, off_t pos)
}
/**
+ * @brief Returns the allocated size of a bitmap.
+ *
+ * @see listener_table_get_by_id
+ */
+#define bitmap_get_alloc_size(bitmap) vector_get_alloc_size(bitmap)
+
+/**
* @brief Retrieve the state of the i-th bit in the bitmap.
*
* @param[in] bitmap The bitmap to access.
@@ -76,6 +83,7 @@ int
bitmap_get(const bitmap_t * bitmap, off_t i)
{
size_t offset = i / BITMAP_WIDTH(bitmap);
+ assert(offset < bitmap_get_alloc_size(bitmap));
size_t pos = i % BITMAP_WIDTH(bitmap);
size_t shift = BITMAP_WIDTH(bitmap) - pos - 1;
return (bitmap[offset] >> shift) & 1;
@@ -100,16 +108,27 @@ bitmap_get(const bitmap_t * bitmap, off_t i)
*
* @return bool
*/
+#define bitmap_set(bitmap, i) \
+ _bitmap_set((bitmap_t**)&bitmap, i)
+
+/*
+ * @brief Returns whether the i-th bit is unset (equal to 0) in a bitmap (helper).
+ *
+ * @param[in] bitmap The bitmap to access.
+ * @param[in] i The bit position.
+ *
+ * @return bool
+ */
static inline
int
-bitmap_set(bitmap_t * bitmap, off_t i)
+_bitmap_set(bitmap_t ** bitmap, off_t i)
{
- if (bitmap_ensure_pos(&bitmap, i) < 0)
+ if (bitmap_ensure_pos(bitmap, i) < 0)
return -1;
size_t offset = i / BITMAP_WIDTH(bitmap);
size_t pos = i % BITMAP_WIDTH(bitmap);
size_t shift = BITMAP_WIDTH(bitmap) - pos - 1;
- bitmap[offset] |= 1ul << shift;
+ (*bitmap)[offset] |= 1ul << shift;
return 0;
}
@@ -186,8 +205,4 @@ END:
#define bitmap_free(bitmap) vector_free(bitmap)
-#ifdef WITH_TESTS
-#define bitmap_get_alloc_size(bitmap) vector_get_alloc_size(bitmap)
-#endif /* WITH_TESTS */
-
#endif /* UTIL_BITMAP_H */