[map] Add hb_map_update()
This commit is contained in:
parent
c350458539
commit
4f6079138d
|
@ -546,6 +546,7 @@ hb_map_get_population
|
||||||
hb_map_is_empty
|
hb_map_is_empty
|
||||||
hb_map_is_equal
|
hb_map_is_equal
|
||||||
hb_map_hash
|
hb_map_hash
|
||||||
|
hb_map_update
|
||||||
hb_map_next
|
hb_map_next
|
||||||
HB_MAP_VALUE_INVALID
|
HB_MAP_VALUE_INVALID
|
||||||
hb_map_t
|
hb_map_t
|
||||||
|
|
|
@ -341,6 +341,22 @@ hb_map_hash (const hb_map_t *map)
|
||||||
return map->hash ();
|
return map->hash ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hb_map_update:
|
||||||
|
* @map: A map
|
||||||
|
* @other: Another map
|
||||||
|
*
|
||||||
|
* Add the contents of @other to @map.
|
||||||
|
*
|
||||||
|
* Since: REPLACEME
|
||||||
|
**/
|
||||||
|
HB_EXTERN void
|
||||||
|
hb_map_update (hb_map_t *map,
|
||||||
|
const hb_map_t *other)
|
||||||
|
{
|
||||||
|
map->update (*other);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hb_map_next:
|
* hb_map_next:
|
||||||
* @map: A map
|
* @map: A map
|
||||||
|
|
|
@ -118,6 +118,10 @@ HB_EXTERN hb_bool_t
|
||||||
hb_map_has (const hb_map_t *map,
|
hb_map_has (const hb_map_t *map,
|
||||||
hb_codepoint_t key);
|
hb_codepoint_t key);
|
||||||
|
|
||||||
|
HB_EXTERN void
|
||||||
|
hb_map_update (hb_map_t *map,
|
||||||
|
const hb_map_t *other);
|
||||||
|
|
||||||
/* Pass -1 in for idx to get started. */
|
/* Pass -1 in for idx to get started. */
|
||||||
HB_EXTERN hb_bool_t
|
HB_EXTERN hb_bool_t
|
||||||
hb_map_next (const hb_map_t *map,
|
hb_map_next (const hb_map_t *map,
|
||||||
|
|
|
@ -308,6 +308,13 @@ struct hb_hashmap_t
|
||||||
|
|
||||||
unsigned int get_population () const { return population; }
|
unsigned int get_population () const { return population; }
|
||||||
|
|
||||||
|
void update (const hb_hashmap_t &other)
|
||||||
|
{
|
||||||
|
if (unlikely (!successful)) return;
|
||||||
|
|
||||||
|
hb_copy (other, *this);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Iterator
|
* Iterator
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -314,7 +314,7 @@ main (int argc, char **argv)
|
||||||
hb_codepoint_t k;
|
hb_codepoint_t k;
|
||||||
hb_codepoint_t v;
|
hb_codepoint_t v;
|
||||||
unsigned pop = 0;
|
unsigned pop = 0;
|
||||||
for (signed i;
|
for (signed i = -1;
|
||||||
m.next (&i, &k, &v);)
|
m.next (&i, &k, &v);)
|
||||||
{
|
{
|
||||||
pop++;
|
pop++;
|
||||||
|
@ -326,7 +326,19 @@ main (int argc, char **argv)
|
||||||
else if (k == 6) assert (v == 8);
|
else if (k == 6) assert (v == 8);
|
||||||
else assert (false);
|
else assert (false);
|
||||||
}
|
}
|
||||||
assert (pop = m.get_population ());
|
assert (pop == m.get_population ());
|
||||||
|
}
|
||||||
|
/* Test update */
|
||||||
|
{
|
||||||
|
hb_map_t m1, m2;
|
||||||
|
m1.set (1, 2);
|
||||||
|
m1.set (2, 4);
|
||||||
|
m2.set (1, 3);
|
||||||
|
|
||||||
|
m1.update (m2);
|
||||||
|
assert (m1.get_population () == 2);
|
||||||
|
assert (m1[1] == 3);
|
||||||
|
assert (m1[2] == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue