HashMap: Make Lth_HashMapFind generic
Manifest: Fix Lth_Resource not handling char *master
parent
33e5162f05
commit
44c32b82b0
|
@ -17,6 +17,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
#include <ACS_ZDoom.h>
|
#include <ACS_ZDoom.h>
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,22 @@
|
||||||
#ifndef lithos3__Lth_hashmap_h
|
#ifndef lithos3__Lth_hashmap_h
|
||||||
#define lithos3__Lth_hashmap_h
|
#define lithos3__Lth_hashmap_h
|
||||||
|
|
||||||
|
#define Lth_GenFind(hashexpr) \
|
||||||
|
Lth_HashMapElem *elem = Lth_HashFindItr(map, (hashexpr)); \
|
||||||
|
if(elem == NULL) return NULL; \
|
||||||
|
return elem->value
|
||||||
|
|
||||||
|
#define Lth_HashMapFind(map, expr) \
|
||||||
|
_Generic((expr)+0, \
|
||||||
|
__str: Lth_HashMapFind_str, \
|
||||||
|
char *: Lth_HashMapFind_char, \
|
||||||
|
char const *: Lth_HashMapFind_char, \
|
||||||
|
wchar_t *: Lth_HashMapFind_wchar, \
|
||||||
|
wchar_t const *: Lth_HashMapFind_wchar, \
|
||||||
|
size_t: Lth_HashMapFind_hash, \
|
||||||
|
wchar_t: Lth_HashMapFind_hash, \
|
||||||
|
int: Lth_HashMapFind_hash)((map), (expr))
|
||||||
|
|
||||||
|
|
||||||
// Type Definitions ----------------------------------------------------------|
|
// Type Definitions ----------------------------------------------------------|
|
||||||
|
|
||||||
|
@ -36,7 +52,7 @@ typedef struct Lth_HashMapElem
|
||||||
// table
|
// table
|
||||||
//
|
//
|
||||||
// read-only
|
// read-only
|
||||||
// elements
|
// elem
|
||||||
//
|
//
|
||||||
typedef struct Lth_HashMap
|
typedef struct Lth_HashMap
|
||||||
{
|
{
|
||||||
|
@ -118,13 +134,37 @@ static inline Lth_HashMapElem *Lth_HashFindItr(Lth_HashMap *map, size_t hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lth_HashMapFind
|
// Lth_HashMapFind_char
|
||||||
//
|
//
|
||||||
static inline void *Lth_HashMapFind(Lth_HashMap *map, char const *key)
|
static inline void *Lth_HashMapFind_char(Lth_HashMap *map, char const *key)
|
||||||
{
|
{
|
||||||
Lth_HashMapElem *elem = Lth_HashFindItr(map, Lth_Hash_char(key));
|
Lth_GenFind(Lth_Hash_char(key));
|
||||||
if(elem == NULL) return NULL;
|
|
||||||
return elem->value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lth_HashMapFind_str
|
||||||
|
//
|
||||||
|
static inline void *Lth_HashMapFind_str(Lth_HashMap *map, __str key)
|
||||||
|
{
|
||||||
|
Lth_GenFind(Lth_Hash_str(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lth_HashMapFind_wchar
|
||||||
|
//
|
||||||
|
static inline void *Lth_HashMapFind_wchar(Lth_HashMap *map, wchar_t const *key)
|
||||||
|
{
|
||||||
|
Lth_GenFind(Lth_Hash_wchar(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lth_HashMapFind_hash
|
||||||
|
//
|
||||||
|
static inline void *Lth_HashMapFind_hash(Lth_HashMap *map, size_t key)
|
||||||
|
{
|
||||||
|
Lth_GenFind(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef Lth_GenFind
|
||||||
|
|
||||||
#endif//lithos3__Lth_hashmap_h
|
#endif//lithos3__Lth_hashmap_h
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
_Generic((val)+0, \
|
_Generic((val)+0, \
|
||||||
int: Lth_ManifestNew_Integ, \
|
int: Lth_ManifestNew_Integ, \
|
||||||
_Accum: Lth_ManifestNew_Fixed, \
|
_Accum: Lth_ManifestNew_Fixed, \
|
||||||
char const *: Lth_ManifestNew_Strng \
|
char *: Lth_ManifestNew_Strng, \
|
||||||
)((name), (val))
|
char const *: Lth_ManifestNew_Strng)((name), (val))
|
||||||
|
|
||||||
|
|
||||||
// Type Definitions ----------------------------------------------------------|
|
// Type Definitions ----------------------------------------------------------|
|
||||||
|
|
Loading…
Reference in New Issue