Add string-keyed map and fixed memory leak

This commit is contained in:
Sasha Koshka
2023-11-12 15:07:08 -05:00
parent edea2a350d
commit 854fbf371c
3 changed files with 199 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
#ifndef _XmdStringMap_h
#define _XmdStringMap_h
#include <X11/Intrinsic.h>
/* XmdStringMap is a hash map that is keyed by a string and can store any type
of element. */
typedef struct _XmdStringMap XmdStringMap;
/* XmdStringMapIterator is a function that can iterate over a string map. */
typedef Bool (*XmdStringMapIterator) (
XmdStringMap *map, String key, void *value);
/* XmdStringMapNew creates a new map.*/
XmdStringMap *XmdStringMapNew ();
/* XmdStringMapGet retrieves a value from a map. */
void *XmdStringMapGet (XmdStringMap *map, String key);
/* XmdStringMapSet sets a value in a map. The previous value associated with the
key, if it exists, is overwritten by the new value. If the value is set to
NULL, the key/value combination is deleted from the map. This function
returns the previous value associated with the key so it can be free'd if
necessary.
*/
void *XmdStringMapSet (XmdStringMap *map, String key, void *value);
/* XmdStringMapIterate calls iterator for each key/value pair in a map. */
void XmdStringMapIterate (XmdStringMap *map, XmdStringMapIterator iterator);
/* XmdStringMapLength returns the number of key/value entries stored in a map.
*/
Cardinal XmdStringMapLength (XmdStringMap *map);
/* XmdStringMapFree frees the map and any data associated with it. Note that
this will not free any of the map's values. */
void XmdStringMapFree (XmdStringMap *map);
#endif