aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/includes/hicn/util/set.h28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/includes/hicn/util/set.h b/lib/includes/hicn/util/set.h
index c7dd7bf09..b4673a673 100644
--- a/lib/includes/hicn/util/set.h
+++ b/lib/includes/hicn/util/set.h
@@ -77,6 +77,8 @@ int NAME ## _add(NAME ## _t * set, const T element); \
\
int NAME ## _remove(NAME ## _t * set, const T search, T * element); \
\
+int NAME ## _clear(NAME ## _t * set); \
+ \
int NAME ## _get(const NAME ## _t * set, const T search, T * element); \
\
int NAME ## _get_array(const NAME ## _t * set, T ** element); \
@@ -98,16 +100,7 @@ NAME ## _initialize(NAME ## _t * set) \
int \
NAME ## _finalize(NAME ## _t * set) \
{ \
- T * array; \
- int n = NAME ## _get_array(set, &array); \
- if (n < 0) \
- return -1; \
- for (unsigned i = 0; i < n; i++) { \
- T element = array[i]; \
- NAME ## _remove(set, element, NULL); \
- } \
- free(array); \
- return 0; \
+ return NAME ## _clear(set); \
} \
\
NAME ## _t * \
@@ -161,6 +154,21 @@ NAME ## _remove(NAME ## _t * set, const T search, T * element) \
} \
\
int \
+NAME ## _clear(NAME ## _t * set) \
+{ \
+ T * array; \
+ int n = NAME ## _get_array(set, &array); \
+ if (n < 0) \
+ return -1; \
+ for (unsigned i = 0; i < n; i++) { \
+ T element = array[i]; \
+ NAME ## _remove(set, element, NULL); \
+ } \
+ free(array); \
+ return 0; \
+} \
+ \
+int \
NAME ## _get(const NAME ## _t * set, const T search, T * element) \
{ \
T * found = tfind(search, &set->root, (cmp_t)CMP); \