CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
hashtable_private.h
1#pragma once
2
3#include "hashtable.h"
4#include "cx/utils.h"
5
6typedef struct HTChunkInfo {
7 uint8 deleted[HT_SLOTS_PER_CHUNK >> 3]; // deleted slot bitmap
8 uint8 nalloc; // how many slots have been allocated for this chunk so far
9} HTChunkInfo;
10
11// Enable metadata for tables with at least this many index entries
12#define HT_METADATA_THRESHOLD 256
13
14_Static_assert((HT_SLOTS_PER_CHUNK >> 8) < sizeof(((HTChunkInfo*)0)->nalloc), "HT_SLOTS_PER_CHUNK too high to fit into nalloc");
15
16#define HT_IDXENT_SZ (sizeof(uint32))
17#define HT_IDXENTWITHMETA_SZ (HT_IDXENT_SZ + sizeof(uint8))
18#define HT_SLOT_CHUNK(slot) ((slot) >> HT_CHUNK_SHIFT)
19#define HT_SLOT_KEY_CHUNK_PTR(hdr, slot) ((uintptr)hdr->keystorage[HT_SLOT_CHUNK(slot)])
20#define HT_SLOT_VAL_CHUNK_PTR(hdr, slot) ((uintptr)hdr->valstorage[HT_SLOT_CHUNK(slot)])
21#define HT_SLOT_OFF(slot, elemsz) ((uintptr)((slot) & HT_CHUNK_MASK) * elemsz)
22#define HT_SLOT_KEY_PTR(hdr, slot) ((void*)(HT_SLOT_KEY_CHUNK_PTR(hdr, slot) + (size_t)((slot) & HT_CHUNK_MASK) * stGetSize(hdr->keytype)))
23#define HT_SLOT_VAL_PTR(hdr, slot) ((void*)(HT_SLOT_VAL_CHUNK_PTR(hdr, slot) + (size_t)((slot) & HT_CHUNK_MASK) * stGetSize(hdr->valtype)))
24
25#define HT_METADATA(hdr) ((uint8*)(&hdr->index[hdr->idxsz]))
26
27#define HT_DELETED_IDX(slot) ((slot & HT_CHUNK_MASK) >> 3)
28#define HT_DELETED_BIT(slot) (1 << (slot & 7))
29
30#define HT_SMALLHDR_OFFSET (offsetof(HashTableHeader, idxsz))
31#define HDRKEYOPS(hdr) ((hdr->flags & HTINT_Extended) ? &hdr->keytypeops : NULL)
32#define HDRVALOPS(hdr) ((hdr->flags & HTINT_Extended) ? &hdr->valtypeops : NULL)
33
34#define hashIndexDeleted (0xffffffffUL)
35#define hashIndexEmpty (0UL)
36
37uint32 _htNextSlot(_Inout_ HashTableHeader *hdr, uint32 slot);
Hash table container with type-safe generic key-value storage.
Other miscellaneous utilities.