mirror of
https://git.telodendria.io/Telodendria/Cytoplasm.git
synced 2025-04-25 02:16:03 +00:00
Add HashMapKeys() and HashMapValues() functions for convenience.
This commit is contained in:
parent
e592cd8e5c
commit
ee267b077d
2 changed files with 73 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <Memory.h>
|
||||
#include <Str.h>
|
||||
#include <Array.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
@ -399,3 +400,57 @@ HashMapIterateFree(char *key, void *value)
|
|||
Free(value);
|
||||
}
|
||||
}
|
||||
|
||||
Array *
|
||||
HashMapKeys(HashMap * map)
|
||||
{
|
||||
Array *arr;
|
||||
|
||||
char *key;
|
||||
void *val;
|
||||
|
||||
if (!map)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
arr = ArrayCreate();
|
||||
if (!arr)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (HashMapIterate(map, &key, &val))
|
||||
{
|
||||
ArrayAdd(arr, key);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
Array *
|
||||
HashMapValues(HashMap *map)
|
||||
{
|
||||
Array *arr;
|
||||
|
||||
char *key;
|
||||
void *val;
|
||||
|
||||
if (!map)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
arr = ArrayCreate();
|
||||
if (!arr)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (HashMapIterate(map, &key, &val))
|
||||
{
|
||||
ArrayAdd(arr, val);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue