]> git.seodisparate.com - UDPConnection/commitdiff
Add a few fns, fix docs to HashMap
authorStephen Seo <seo.disparate@gmail.com>
Wed, 13 Feb 2019 04:38:27 +0000 (13:38 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 13 Feb 2019 04:38:36 +0000 (13:38 +0900)
src/UDPC_HashMap.c
src/UDPC_HashMap.h

index ef09703b8a148baa3ec1665418c99a3f9c60bc42..8dc9c5e824b2fc339388fc309725bbae9c2af5b5 100644 (file)
@@ -305,3 +305,13 @@ void UDPC_HashMap_clear(UDPC_HashMap *hm)
     UDPC_Deque_clear(hm->overflow);
     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;
+}
index c91caeb0c1458ff470941148ba7a80489dd36e4a..e58712c10219a8632fe97110e87686d8d4bd35aa 100644 (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
  * with UDPC_HashMap_realloc(). realloc requires rehashing of all items which
  * may be costly.
- * If an item with the same key already exists in the hash map, it will be
- * replaced.
+ * It is possible to insert items with duplicate keys. In that case, the first
+ * duplicate inserted will be the first returned with get() and first removed
+ * with remove().
  * \return Internally managed pointer to inserted data, NULL on fail
  */
 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
  * 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
  */
 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);
 
+uint32_t UDPC_HashMap_get_size(UDPC_HashMap *hm);
+
+uint32_t UDPC_HashMap_get_capacity(UDPC_HashMap *hm);
+
 #endif