dict_ref & dict_cref returns a pointer to struct pair_s instead of pair_t (which
is an array of struct pair_s). This will break API compatibility. However: it makes the user code cleaner as a level of indirection is removed. it uniformizes with the OA dict version
This commit is contained in:
1 parent
8265ccbb42
commit
8914d336a0
7 files changed
+32
-33
No files matched your search
+2
-2
@@ -42,9 +42,9 @@ int main(void)
|
||||
dict_str_it_t it;
|
||||
for(dict_str_it(it, h); !dict_str_end_p(it); dict_str_next(it)) {
|
||||
// Get a constant reference on the pair stored in the dictionnary
|
||||
const dict_str_pair_t *pair = dict_str_cref(it);
|
||||
const struct dict_str_pair_s *pair = dict_str_cref(it);
|
||||
printf ("Key=%s Value=%d\n",
|
||||
string_get_cstr((*pair)->key), (*pair)->value);
|
||||
string_get_cstr(pair->key), pair->value);
|
||||
}
|
||||
|
||||
// Clear variables
|
||||
|
||||
+3
-3
@@ -18,8 +18,8 @@ int main(void) {
|
||||
dict_m32_remove(h, 5); // h is now empty
|
||||
dict_m32_it_t it; // iterate over all dictionnary
|
||||
for (dict_m32_it (it, h) ; !dict_m32_end_p (it); dict_m32_next(it)) {
|
||||
dict_m32_pair_t *item = dict_m32_ref(it);
|
||||
(*item)->value = 1; // Set its value to 1
|
||||
struct dict_m32_pair_s *item = dict_m32_ref(it);
|
||||
item->value = 1; // Set its value to 1
|
||||
}
|
||||
dict_m32_clear(h); // h is cleared
|
||||
return 0;
|
||||
@@ -35,7 +35,7 @@ int main(void) {
|
||||
assert (is_missing);
|
||||
dict_m32_remove(h, 5); // h is now empty
|
||||
for M_EACH(item, h, M32_OPLIST) { // traverse each item
|
||||
(*item)->value = 1; // Set its value to 1
|
||||
item->value = 1; // Set its value to 1
|
||||
}
|
||||
} // h is cleared
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -76,8 +76,8 @@ int main(void)
|
||||
printf("Displaying Map by Iterator:\n");
|
||||
for (dict_map_it(it, mp); !dict_map_end_p(it); dict_map_next(it))
|
||||
{
|
||||
const dict_map_pair_t *cref = dict_map_cref(it);
|
||||
printf ("%d : %d\n", (*cref)->key, (*cref)->value);
|
||||
const struct dict_map_pair_s *cref = dict_map_cref(it);
|
||||
printf ("%d : %d\n", cref->key, cref->value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -48,13 +48,13 @@ int main(void)
|
||||
// Iterate over the dictionary container
|
||||
for M_EACH(p, *item, MY_DICT_OPLIST) {
|
||||
// Dictionary iterator are pair (key,value)
|
||||
if (my_integer_n_p((*p)->value)) {
|
||||
if (my_integer_n_p(p->value)) {
|
||||
printf ("It is a long long, value = %lld\n",
|
||||
*my_integer_get_n((*p)->value));
|
||||
*my_integer_get_n(p->value));
|
||||
}
|
||||
if (my_integer_z_p((*p)->value)) {
|
||||
if (my_integer_z_p(p->value)) {
|
||||
printf ("It is a mpz_t, value =");
|
||||
mpz_out_str(stdout, 10, *my_integer_get_z((*p)->value));
|
||||
mpz_out_str(stdout, 10, *my_integer_get_z(p->value));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user