diff --git a/include/QF/hash.h b/include/QF/hash.h index b63eb9dbf..67b17a8d2 100644 --- a/include/QF/hash.h +++ b/include/QF/hash.h @@ -139,6 +139,10 @@ unsigned long Hash_String (const char *str); */ unsigned long Hash_Buffer (const void *buf, int len); +/** return the number of elements in the table. +*/ +size_t Hash_NumElements (hashtab_t *tab); + /** return a list of all elements in the table. it is the caller's responsibilty to free() the array. Null terminated. */ diff --git a/include/QF/qfplist.h b/include/QF/qfplist.h index b891df574..c3ad78df8 100644 --- a/include/QF/qfplist.h +++ b/include/QF/qfplist.h @@ -157,6 +157,15 @@ plitem_t *PL_ObjectAtIndex (plitem_t *, int); */ plitem_t *PL_D_AllKeys (plitem_t *); +/** + \brief Retrieve the number of keys in a dictionalry + + \param dict The dictionary to get the number of keys of. + + \return Returns the number of keys in the dictionary. +*/ +int PL_D_NumKeys (plitem_t *); + /** \fn qboolean PL_D_AddObject (plitem_t *dict, plitem_t *key, plitem_t *value) @@ -182,6 +191,13 @@ qboolean PL_D_AddObject (plitem_t *, plitem_t *, plitem_t *); */ qboolean PL_A_AddObject (plitem_t *, plitem_t *); +/** + \param array The array to get the number of objects in + + \return number of objects in the array +*/ +int PL_A_NumObjects (plitem_t *array); + /** \fn qboolean PL_A_InsertObjectAtIndex (plitem_t *array, plitem_t *item, int index) \param array The array to add the item to diff --git a/libs/util/hash.c b/libs/util/hash.c index a64ed4871..bceb0a952 100644 --- a/libs/util/hash.c +++ b/libs/util/hash.c @@ -415,6 +415,12 @@ Hash_Free (hashtab_t *tab, void *ele) tab->free_ele (ele, tab->user_data); } +size_t +Hash_NumElements (hashtab_t *tab) +{ + return tab->num_ele; +} + void ** Hash_GetList (hashtab_t *tab) { diff --git a/libs/util/qfplist.c b/libs/util/qfplist.c index b10abb0c1..ff12427a9 100644 --- a/libs/util/qfplist.c +++ b/libs/util/qfplist.c @@ -179,6 +179,14 @@ PL_D_AllKeys (plitem_t *dict) return array; } +int +PL_D_NumKeys (plitem_t *dict) +{ + if (dict->type != QFDictionary) + return 0; + return Hash_NumElements ((hashtab_t *) dict->data); +} + plitem_t * PL_ObjectAtIndex (plitem_t *array, int index) { @@ -260,6 +268,14 @@ PL_A_AddObject (plitem_t *array, plitem_t *item) return PL_A_InsertObjectAtIndex (array, item, -1); } +int +PL_A_NumObjects (plitem_t *array) +{ + if (array->type != QFArray) + return 0; + return ((plarray_t *) array->data)->numvals; +} + static qboolean PL_SkipSpace (pldata_t *pl) {