aboutsummaryrefslogtreecommitdiffstats
path: root/lib/includes/hicn/util
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-07-08 16:10:13 +0000
committerMauro Sardara <msardara@cisco.com>2022-08-10 11:57:10 +0200
commit8f0a8bf572b9b8123121338a31462440bad65857 (patch)
treeecac67f0ad005b2eb0a1bd25c8f242497ffddea1 /lib/includes/hicn/util
parent8d27045832427a0ea345f48bfb2c42f46a357af1 (diff)
feat: add interest manifest serialization/deserialization
Also: add helpers for interest manifest Ref: HICN-738 Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: Ia531605148e00ccbe446da0f4f2d8caae2b098be Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib/includes/hicn/util')
-rw-r--r--lib/includes/hicn/util/bitmap.h48
-rw-r--r--lib/includes/hicn/util/types.h8
2 files changed, 31 insertions, 25 deletions
diff --git a/lib/includes/hicn/util/bitmap.h b/lib/includes/hicn/util/bitmap.h
index 15d47ac61..68541bc28 100644
--- a/lib/includes/hicn/util/bitmap.h
+++ b/lib/includes/hicn/util/bitmap.h
@@ -127,40 +127,46 @@ _bitmap_get_no_check (const bitmap_t *bitmap, off_t i)
#define bitmap_is_unset_no_check(bitmap, i) \
(_bitmap_get_no_check ((bitmap), (i)) == 0)
+static inline int
+_bitmap_set_no_check (bitmap_t *bitmap, off_t i)
+{
+ size_t offset = i / BITMAP_WIDTH (bitmap);
+ size_t pos = i % BITMAP_WIDTH (bitmap);
+ bitmap[offset] |= (bitmap_t) 1 << pos;
+ return 0;
+}
+
+static inline int
+_bitmap_set (bitmap_t **bitmap_ptr, off_t i)
+{
+ if (bitmap_ensure_pos (bitmap_ptr, i) < 0)
+ return -1;
+
+ bitmap_t *bitmap = *bitmap_ptr;
+ return _bitmap_set_no_check (bitmap, i);
+}
+
/*
- * @brief Returns whether the i-th bit is unset (equal to 0) in a bitmap.
+ * @brief Set i-th bit to 1 in a bitmap. Reallocate the vector if the bit
+ * position is greater than the vector length.
*
* @param[in] bitmap The bitmap to access.
* @param[in] i The bit position.
*
* @return bool
*/
-#define bitmap_set(bitmap, i) _bitmap_set ((bitmap_t **) &bitmap, i, 1)
-#define bitmap_set_no_check(bitmap, i) \
- _bitmap_set ((bitmap_t **) &bitmap, i, 0)
+#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).
+ * @brief Set i-th bit to 1 in a bitmap. Unsafe version, does not check
+ * boundaries.
*
* @param[in] bitmap The bitmap to access.
* @param[in] i The bit position.
*
* @return bool
*/
-static inline int
-_bitmap_set (bitmap_t **bitmap_ptr, off_t i, int check)
-{
- if (check && bitmap_ensure_pos (bitmap_ptr, i) < 0)
- return -1;
-
- bitmap_t *bitmap = *bitmap_ptr;
- size_t offset = i / BITMAP_WIDTH (bitmap);
- size_t pos = i % BITMAP_WIDTH (bitmap);
-
- bitmap[offset] |= (bitmap_t) 1 << pos;
- return 0;
-}
+#define bitmap_set_no_check(bitmap, i) _bitmap_set_no_check (bitmap, i)
#define bitmap_unset(bitmap, i) _bitmap_unset (bitmap, i, 1)
#define bitmap_unset_no_check(bitmap, i) _bitmap_unset (bitmap, i, 0)
@@ -306,11 +312,11 @@ bitmap_next_unset (const bitmap_t *bitmap, hicn_uword i)
#define bitmap_first_set(bitmap) bitmap_next_set (bitmap, 0)
#define bitmap_first_set_no_check(bitmap, size) \
- bitmap_next_set_no_checks (bitmap, 0, size)
+ bitmap_next_set_no_check (bitmap, 0, size)
#define bitmap_first_unset(bitmap) bitmap_next_unset (bitmap, 0)
#define bitmap_first_unset_no_check(bitmap, size) \
- bitmap_next_unset_no_checks (bitmap, 0, size)
+ bitmap_next_unset_no_check (bitmap, 0, size)
static inline void
bitmap_print (const bitmap_t *bitmap, size_t n_words)
diff --git a/lib/includes/hicn/util/types.h b/lib/includes/hicn/util/types.h
index c9cc878cf..a883b8220 100644
--- a/lib/includes/hicn/util/types.h
+++ b/lib/includes/hicn/util/types.h
@@ -44,21 +44,21 @@ typedef float f32;
#error "Impossible to detect architecture"
#endif
-#define hicn_uword_bits (1 << hicn_log2_uword_bits)
+#define _hicn_uword_bits (1 << hicn_log2_uword_bits)
/* Word types. */
-#if hicn_uword_bits == 64
+#if _hicn_uword_bits == 64
/* 64 bit word machines. */
typedef u64 hicn_uword;
+#define hicn_uword_bits 64
#else
/* 32 bit word machines. */
typedef u32 hicn_uword;
+#define hicn_uword_bits 32
#endif
typedef hicn_uword hicn_ip_csum_t;
-#define hicn_uword_bits (1 << hicn_log2_uword_bits)
-
/* Helper for avoiding warnings about type-punning */
#define UNION_CAST(x, destType) \
(((union { \