Add HashMapKeys() and HashMapValues() functions for convenience.

This commit is contained in:
Jordan Bancino 2023-07-18 00:15:29 +00:00
parent e592cd8e5c
commit ee267b077d
2 changed files with 73 additions and 0 deletions

View file

@ -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;
}