Add _swap for dict

This commit is contained in:
Patrick Pelissier committed 2017-03-14 21:25:34 +01:00
1 parent dc87d7e137
commit 75c07d9ac7
2 files changed
+23

No files matched your search

+15
View File
@@ -99,6 +99,20 @@
} \
\
static inline void \
M_C3(dict_, name, _swap)(M_C3(dict_,name,_t) d1, \
M_C3(dict_,name,_t) d2) \
{ \
DICTI_CONTRACT(name, d1); \
DICTI_CONTRACT(name, d2); \
M_SWAP (size_t, d1->used, d2->used); \
M_SWAP (size_t, d1->lower_limit, d2->lower_limit); \
M_SWAP (size_t, d1->upper_limit, d2->upper_limit); \
M_C3(array_list_dict_pair_,name,_swap)(d1->table, d2->table); \
DICTI_CONTRACT(name, d1); \
DICTI_CONTRACT(name, d2); \
} \
\
static inline void \
M_C3(dict_, name, _move)(M_C3(dict_,name,_t) map, \
M_C3(dict_,name,_t) org) \
{ \
@@ -454,6 +468,7 @@
CLEAR(M_C3(dict_, type, _clear)), \
INIT_MOVE(M_C3(dict_, type, _init_move)), \
MOVE(M_C3(dict_, type, _move)), \
SWAP(M_C3(dict_, type, _swap)), \
TYPE(M_C3(dict_, type, _t)), \
SUBTYPE(M_C3(dict_pair_,type,_t)), \
IT_TYPE(M_C3(dict_it_,type,_t)), \
+8
View File
@@ -64,6 +64,14 @@ static void test_data(void)
dict_str_set_at(dict, *array_string_cget(v, i), *array_string_cget(v, (i+1) % data_size));
}
assert(dict_str_size(dict) == 1227176);
dict_str_t dict2;
dict_str_init (dict2);
dict_str_swap (dict, dict2);
assert(dict_str_size(dict) == 0);
assert(dict_str_size(dict2) == 1227176);
dict_str_clear (dict2);
dict_str_clear (dict);
}