/* doc: <routine name="ht_free" export="shared"> doc: <summary>Free memory used internally by `ht' and `ht' itself assuming it was allocated by the runtime memory routines (i.e. not `eif_malloc' or `eif_calloc'.</summary> doc: <param name="ht" type="struct htable *">Table to initialize.</param> doc: <thread_safety>Not Safe</thread_safety> doc: <synchronization>None</synchronization> doc: </routine> */ rt_shared void ht_free(struct htable *ht) { REQUIRE("ht not null", ht); /* Free hash table arrays and descriptor */ ht_release (ht); eif_rt_xfree((char *) ht); }
/* doc: <routine name="ht_resize" return_type="int" export="shared"> doc: <summary>Resize `ht' to accomodate `new_size' many elements.</summary> doc: <param name="ht" type="struct htable *">Table to resize.</param> doc: <param name="new_size" type="size_t">New size. If smaller than existing size, no resizing is done.</param> doc: <return>0 if resizing was Ok, -1 otherwise.</return> doc: <thread_safety>Not Safe</thread_safety> doc: <synchronization>None</synchronization> doc: </routine> */ rt_shared int ht_resize(struct htable *ht, size_t new_size) { size_t l_capacity; /* Size of old H table */ size_t sval; /* Size of an H table item */ rt_uint_ptr *key; /* To loop over keys */ void * val, *l_value; /* To loop over values */ struct htable new_ht; REQUIRE("ht not null", ht); l_capacity = ht->h_capacity; if (l_capacity >= new_size) { return -1; /* Requested size is no bigger than what we have. */ } sval = ht->h_sval; if (-1 == ht_create(&new_ht, l_capacity * 2, sval)) { return -1; /* Extension of H table failed */ } key = ht->h_keys; /* Start of array of keys */ val = ht->h_values; /* Start of array of values */ /* Now loop over the whole table, inserting each item in the new one */ for (; l_capacity > 0; l_capacity--, key++, val = (char *) val + sval) { if (*key) { l_value = ht_first(&new_ht, *key); CHECK("Item found", l_value); memcpy (l_value, val, sval); } } /* Free old H table and set H table descriptor */ ht_release(ht); memcpy (ht, &new_ht, sizeof(struct htable)); return 0; /* Extension was ok */ }
/** * @brief release the pinyin dictionary * @details [long description] * */ void pinyin_destroy(PinTable * dict) { ht_release(dict); }