mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 22:48:21 +00:00
hashtable: static define macro
This commit is contained in:
@@ -15,7 +15,7 @@ typedef struct hashentry_t {
|
|||||||
} hashentry_t;
|
} hashentry_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t entrycount;
|
size_t entrycount; // for bookkeeping
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
hashentry_t **entries;
|
hashentry_t **entries;
|
||||||
} hashtable_t;
|
} hashtable_t;
|
||||||
@@ -30,4 +30,12 @@ int hashtable_destroy(hashtable_t *table);
|
|||||||
for (uintmax_t toffset = 0; toffset < (table)->capacity; ++toffset) \
|
for (uintmax_t toffset = 0; toffset < (table)->capacity; ++toffset) \
|
||||||
for (hashentry_t *entry = (table)->entries[toffset]; entry != NULL; entry = entry->next)
|
for (hashentry_t *entry = (table)->entries[toffset]; entry != NULL; entry = entry->next)
|
||||||
|
|
||||||
|
#define HASHTABLE_DEFINE_STATIC(name, size) \
|
||||||
|
static hashentry_t *entries_ht_##name[size]; \
|
||||||
|
static hashtable_t name = { \
|
||||||
|
.entrycount = 0, \
|
||||||
|
.capacity = size, \
|
||||||
|
.entries = entries_ht_##name \
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user