Add _equal_p method for OA dictionary.

This commit is contained in:
Patrick Pelissier committed 2018-07-01 22:44:56 +02:00
1 parent d1f2b62f66
commit 3765c0b0fb
2 files changed
+35 -5

No files matched your search

+30
View File
@@ -1429,6 +1429,36 @@ typedef enum {
DICTI_OA_CONTRACT(dict); \
} \
\
M_IF_METHOD(EQUAL, value_oplist)( \
static inline bool \
M_C(name, _equal_p)(dict_t dict1, dict_t dict2) \
{ \
DICTI_OA_CONTRACT(dict1); \
DICTI_OA_CONTRACT(dict2); \
/* NOTE: Key type has mandatory equal operator */ \
/* Easy case */ \
if (M_LIKELY (dict1->count != dict2->count)) \
return false; \
if (M_UNLIKELY (dict1->count == 0)) \
return true; \
/* Otherwise this is the slow path */ \
dict_it_t it; \
for(M_C(name, _it)(it, dict1) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)) { \
const struct M_C(name, _pair_s) *item = M_C(name, _cref)(it); \
value_type *ptr = M_C(name, _get)(dict2, item->key); \
if (ptr == NULL) \
return false; \
M_IF(isSet)(, \
if (M_GET_EQUAL value_oplist (item->value, *ptr) == false) \
return false; \
) \
} \
return true; \
} \
, /* no value equal */ ) \
\
DICTI_FUNC_ADDITIONAL_DEF2(name, key_type, key_oplist, value_type, value_oplist, 0, dict_t, dict_it_t)
+5 -5
View File
@@ -368,13 +368,13 @@ static void test_init_oa(void)
dict_oa_int_remove (d1, 17);
dict_oa_int_t d3;
dict_oa_int_init_set (d3, d1);
//assert (dict_oa_int_equal_p (d3, d1));
assert (dict_oa_int_equal_p (d3, d1));
dict_oa_int_set (d2, d1);
assert (dict_oa_int_get (d2, -10) == NULL);
assert (*dict_oa_int_get (d2, 10) == 11);
//assert (dict_oa_int_equal_p (d2, d1));
//assert (dict_oa_int_equal_p (d2, d3));
assert (dict_oa_int_equal_p (d2, d1));
assert (dict_oa_int_equal_p (d2, d3));
dict_oa_int_clear (d3);
dict_oa_int_set_at (d1, -10, -20);
@@ -384,11 +384,11 @@ static void test_init_oa(void)
assert (dict_oa_int_size (d1) == 101);
assert (*dict_oa_int_get (d1, -10) == -22);
//assert (!dict_oa_int_equal_p (d2, d1));
assert (!dict_oa_int_equal_p (d2, d1));
bool b = dict_oa_int_remove (d1, 0);
assert (dict_oa_int_size (d1) == 100);
assert (b);
//assert (!dict_oa_int_equal_p (d2, d1));
assert (!dict_oa_int_equal_p (d2, d1));
for(size_t i = 1; i < 100; i++) {
b = dict_oa_int_remove (d1, 2*i);