Add a few fns, fix docs to HashMap

This commit is contained in:
Stephen Seo 2019-02-13 13:38:27 +09:00
parent c335b280c9
commit e995c877c4
2 changed files with 19 additions and 2 deletions

View file

@ -305,3 +305,13 @@ void UDPC_HashMap_clear(UDPC_HashMap *hm)
UDPC_Deque_clear(hm->overflow); UDPC_Deque_clear(hm->overflow);
hm->size = 0; hm->size = 0;
} }
uint32_t UDPC_HashMap_get_size(UDPC_HashMap *hm)
{
return hm->size;
}
uint32_t UDPC_HashMap_get_capacity(UDPC_HashMap *hm)
{
return hm->capacity;
}

View file

@ -46,8 +46,9 @@ void UDPC_HashMap_destroy(UDPC_HashMap *hashMap);
* Note if size already equals capacity, the hash map's capacity is doubled * Note if size already equals capacity, the hash map's capacity is doubled
* with UDPC_HashMap_realloc(). realloc requires rehashing of all items which * with UDPC_HashMap_realloc(). realloc requires rehashing of all items which
* may be costly. * may be costly.
* If an item with the same key already exists in the hash map, it will be * It is possible to insert items with duplicate keys. In that case, the first
* replaced. * duplicate inserted will be the first returned with get() and first removed
* with remove().
* \return Internally managed pointer to inserted data, NULL on fail * \return Internally managed pointer to inserted data, NULL on fail
*/ */
void* UDPC_HashMap_insert(UDPC_HashMap *hm, uint32_t key, void *data); void* UDPC_HashMap_insert(UDPC_HashMap *hm, uint32_t key, void *data);
@ -70,6 +71,8 @@ void* UDPC_HashMap_get(UDPC_HashMap *hm, uint32_t key);
/*! /*!
* \brief Resizes the maximum capacity of a hash map * \brief Resizes the maximum capacity of a hash map
* Note on fail, the hash map is unchanged. * Note on fail, the hash map is unchanged.
* If newCapacity is less than the current size of the hash map, this function
* will fail.
* \return non-zero if resizing was successful * \return non-zero if resizing was successful
*/ */
int UDPC_HashMap_realloc(UDPC_HashMap *hm, uint32_t newCapacity); int UDPC_HashMap_realloc(UDPC_HashMap *hm, uint32_t newCapacity);
@ -79,4 +82,8 @@ int UDPC_HashMap_realloc(UDPC_HashMap *hm, uint32_t newCapacity);
*/ */
void UDPC_HashMap_clear(UDPC_HashMap *hm); void UDPC_HashMap_clear(UDPC_HashMap *hm);
uint32_t UDPC_HashMap_get_size(UDPC_HashMap *hm);
uint32_t UDPC_HashMap_get_capacity(UDPC_HashMap *hm);
#endif #endif