From e8d757670402b29cfbe8b67fd9d557017467c7e1 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 4 Apr 2016 14:05:12 -0400 Subject: [PATCH] core/containers/set: Return status of set_insert() and set_remove() I use this status indicator in the playlist code fairly often, so let's return it directly rather than needing to code around it. Signed-off-by: Anna Schumaker --- include/core/containers/set.h | 8 ++++---- tests/core/containers/set.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/core/containers/set.h b/include/core/containers/set.h index 6174087f..2c4a8b1c 100644 --- a/include/core/containers/set.h +++ b/include/core/containers/set.h @@ -34,14 +34,14 @@ static inline void set_deinit(struct set *set) g_hash_table_destroy(set->s_set); } -static inline void set_insert(struct set *set, unsigned int value) +static inline bool set_insert(struct set *set, unsigned int value) { - g_hash_table_add(set->s_set, GUINT_TO_POINTER(value)); + return g_hash_table_add(set->s_set, GUINT_TO_POINTER(value)); } -static inline void set_remove(struct set *set, unsigned int value) +static inline bool set_remove(struct set *set, unsigned int value) { - g_hash_table_remove(set->s_set, GUINT_TO_POINTER(value)); + return g_hash_table_remove(set->s_set, GUINT_TO_POINTER(value)); } static inline void set_clear(struct set *set) diff --git a/tests/core/containers/set.c b/tests/core/containers/set.c index ff9350d8..bb7d09fd 100644 --- a/tests/core/containers/set.c +++ b/tests/core/containers/set.c @@ -14,8 +14,8 @@ void test_set() /* Insert N items. */ for (i = 0; i < N; i++) { - set_insert(&set, i); - set_insert(&set, i); + test_loop_equal(set_insert(&set, i), (bool)true, i); + test_loop_equal(set_insert(&set, i), (bool)false, i); test_loop_equal(set_size(&set), i + 1, i); test_loop_equal(set_has(&set, i), (bool)true, i); } test_loop_passed(); @@ -25,8 +25,8 @@ void test_set() /* Remove even items. */ for (i = 0; i < N; i += 2) { - set_remove(&set, i); - set_remove(&set, i); + test_loop_equal(set_remove(&set, i), (bool)true, i); + test_loop_equal(set_remove(&set, i), (bool)false, i); test_loop_equal(set_has(&set, i), (bool)false, i); } test_loop_passed(); test_equal(set_size(&set), N / 2);