mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
Add a strset "class"
It's just a wrapper around hashtab, but it makes checking if a string is in a set easy. Way overkill when only a few extensions are enabled, but more might come later.
This commit is contained in:
parent
31ead15e96
commit
ed3c5cb9ec
2 changed files with 32 additions and 0 deletions
|
@ -33,8 +33,35 @@
|
|||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "QF/hash.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static const char *
|
||||
strset_get_key (const void *_str, void *unused)
|
||||
{
|
||||
return (const char *)_str;
|
||||
}
|
||||
|
||||
strset_t *
|
||||
new_strset (const char * const *strings)
|
||||
{
|
||||
hashtab_t *tab = Hash_NewTable (61, strset_get_key, 0, 0);
|
||||
for ( ; *strings; strings++) {
|
||||
Hash_Add (tab, (void *) *strings);
|
||||
}
|
||||
return (strset_t *) tab;
|
||||
}
|
||||
void del_strset (strset_t *strset)
|
||||
{
|
||||
Hash_DelTable ((hashtab_t *) strset);
|
||||
}
|
||||
|
||||
int strset_contains (strset_t *strset, const char *str)
|
||||
{
|
||||
return Hash_Find ((hashtab_t *) strset, str) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
count_strings (const char * const *str)
|
||||
{
|
||||
|
|
|
@ -8,4 +8,9 @@ void merge_strings (const char **out, const char * const *in1,
|
|||
void prune_strings (const char * const *reference, const char **strings,
|
||||
uint32_t *count);
|
||||
|
||||
typedef struct strset_s strset_t;
|
||||
strset_t *new_strset (const char * const *strings);
|
||||
void del_strset (strset_t *strset);
|
||||
int strset_contains (strset_t *strset, const char *str);
|
||||
|
||||
#endif//__util_h
|
||||
|
|
Loading…
Reference in a new issue