shset.h: hash set handling (key-only storage)
Set functions handle key-only storage, which is implemented as a
hash table (O(n), with O(1) amortized time complexity for insert/
count/delete).
Supported set modes (enum eSHS_Type):
SHS_I32: int32_t key
SHS_U32: uint32_t key
SHS_I: int64_t key
SHS_F: float (single-precision floating point) key
SHS_D: double (double-precision floating point) key
SHS_S: string key
Callback types for the shs_itp_*() functions:
typedef srt_bool (*srt_hset_it_i32)(int32_t k, void *context);
typedef srt_bool (*srt_hset_it_u32)(uint32_t k, void *context);
typedef srt_bool (*srt_hset_it_i)(int64_t k, void *context);
typedef srt_bool (*srt_hset_it_f)(float k, void *context);
typedef srt_bool (*srt_hset_it_d)(double k, void *context);
typedef srt_bool (*srt_hset_it_s)(const srt_string *, void *context);
srt_hset *shs_alloc(enum eSHS_Type t, size_t init_size)
- Allocate hash set (heap)
- enum eSHS_Type t: set type
- size_t init_size: initial reserve
- Return (srt_hset *): hash set
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_hset *shs_alloca(enum eSHS_Type t, size_t n)
- Allocate hash set (stack)
- enum eSHS_Type t: set type
- size_t n: initial reserve
- Return (srt_hset *): map
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_capacity(const srt_hset *hs)
- Allocated space
- const srt_hset *hs: hash set
- Return (size_t): current allocated space (vector elements)
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_capacity_left(const srt_hset *hs)
- Preallocated space left
- const srt_hset *hs: hash set
- Return (size_t): allocated space left
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
void shs_clear(srt_hset *hs)
- Clear/reset map (keeping map type)
- srt_hset *hs: hash set
- Time complexity: O(1) for simple maps, O(n) for maps having nodes with strings
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_count_d(const srt_hset *hs, double k)
- Map element count/check (SHS_D)
- const srt_hset *hs: hash set
- double k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the hash set
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_count_f(const srt_hset *hs, float k)
- Map element count/check (SHS_F)
- const srt_hset *hs: hash set
- float k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the hash set
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_count_i(const srt_hset *hs, int64_t k)
- Map element count/check (SHS_I)
- const srt_hset *hs: hash set
- int64_t k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the hash set
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_count_i32(const srt_hset *hs, int32_t k)
- Map element count/check (SHS_I32)
- const srt_hset *hs: hash set
- int32_t k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the hash set
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_count_s(const srt_hset *hs, const srt_string *k)
- Map element count/check (SHS_S)
- const srt_hset *hs: hash set
- const srt_string *k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the hash set
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_count_u32(const srt_hset *hs, uint32_t k)
- Map element count/check (SHS_U32)
- const srt_hset *hs: hash set
- uint32_t k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the hash set
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_hset *shs_cpy(srt_hset **hs, const srt_hset *src)
- Overwrite map with a map copy
- srt_hset **hs: output map
- const srt_hset *src: input hash setoutput map reference (optional usage)
- Return (srt_hset *): O(n)
- Time complexity: 1
- Space complexity: 2
- Coverage: [0/2] basic (Coverity, clang analyzer)
- Quality: [0/4] not reviewed
srt_bool shs_delete_d(srt_hset *hs, double k)
- Delete map element (SHS_D)
- srt_hset *hs: hash set
- double k: double key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_delete_f(srt_hset *hs, float k)
- Delete map element (SHS_F)
- srt_hset *hs: hash set
- float k: float key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_delete_i(srt_hset *hs, int64_t k)
- Delete map element (SHS_I)
- srt_hset *hs: hash set
- int64_t k: int64_t key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_delete_i32(srt_hset *hs, int32_t k)
- Delete map element (SHS_I32)
- srt_hset *hs: hash set
- int32_t k: int32_t key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_delete_s(srt_hset *hs, const srt_string *k)
- Delete map element (SHS_S)
- srt_hset *hs: hash set
- const srt_string *k: string key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_delete_u32(srt_hset *hs, uint32_t k)
- Delete map element (SHS_U32)
- srt_hset *hs: hash set
- uint32_t k: int32_t key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_hset *shs_dup(const srt_hset *src)
- Duplicate hash set
- const srt_hset *src: input hash setoutput hash set
- Return (srt_hset *): O(n)
- Time complexity: 1
- Space complexity: 2
- Coverage: [0/2] basic (Coverity, clang analyzer)
- Quality: [0/4] not reviewed
srt_bool shs_empty(const srt_hset *hs)
- Tells if a hash set is empty (zero elements)
- const srt_hset *hs: hash set
- Return (srt_bool): S_TRUE: empty; S_FALSE: not empty
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
void shs_free(srt_hset **hs, ...)
- Free one or more hash sets
- srt_hset **hs: hash set
- ...: more hash sets (optional)
- Return (void): -
- Time complexity: O(1) for simple dmaps, O(n) for dmaps having nodes with strings
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_grow(srt_hset **hs, size_t extra_elems)
- Ensure space for extra elements
- srt_hset **hs: hash set
- size_t extra_elems: number of extra elements
- Return (size_t): extra size allocated
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_insert_d(srt_hset **hs, double k)
- Insert into hash set (SHS_D)
- srt_hset **hs: hash set
- double k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_insert_f(srt_hset **hs, float k)
- Insert into hash set (SHS_F)
- srt_hset **hs: hash set
- float k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_insert_i(srt_hset **hs, int64_t k)
- Insert into hash set (SHS_I)
- srt_hset **hs: hash set
- int64_t k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_insert_i32(srt_hset **hs, int32_t k)
- Insert into hash set (SHS_I32)
- srt_hset **hs: hash set
- int32_t k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_insert_s(srt_hset **hs, const srt_string *k)
- Insert into hash set (SHS_S)
- srt_hset **hs: hash set
- const srt_string *k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool shs_insert_u32(srt_hset **hs, uint32_t k)
- Insert into hash set (SHS_U32)
- srt_hset **hs: hash set
- uint32_t k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(n), O(1) average amortized
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
double shs_it_d(const srt_hset *hs, size_t i)
- Enumerate set keys (SHS_D)
- const srt_hset *hs: hash set
- size_t i: element, 0 to n - 1
- Return (double): int64_t
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [0/2] basic (Coverity, clang analyzer)
- Quality: [1/4] reviewed, with quality issues
float shs_it_f(const srt_hset *hs, size_t i)
- Enumerate set keys (SHS_F)
- const srt_hset *hs: hash set
- size_t i: element, 0 to n - 1
- Return (float): int64_t
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [0/2] basic (Coverity, clang analyzer)
- Quality: [1/4] reviewed, with quality issues
int64_t shs_it_i(const srt_hset *hs, size_t i)
- Enumerate set keys (SHS_I)
- const srt_hset *hs: hash set
- size_t i: element, 0 to n - 1
- Return (int64_t): int64_t
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
int32_t shs_it_i32(const srt_hset *hs, size_t i)
- Enumerate set keys (SHS_I32)
- const srt_hset *hs: hash set
- size_t i: element, 0 to n - 1
- Return (int32_t): int32_t
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
const srt_string *shs_it_s(const srt_hset *hs, size_t i)
- Enumerate set keys (SHS_S)
- const srt_hset *hs: hash set
- size_t i: element, 0 to n - 1
- Return (const srt_string *): string
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
uint32_t shs_it_u32(const srt_hset *hs, size_t i)
- Enumerate set keys (SHS_U32)
- const srt_hset *hs: hash set
- size_t i: element, 0 to n - 1
- Return (uint32_t): uint32_t
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_itp_d(const srt_hset *s, size_t begin, size_t end, srt_hset_it_d f, void *context)
- Enumerate set elements in portions (SHS_D)
- const srt_hset *s: set
- size_t begin: index start
- size_t end: index end
- srt_hset_it_d f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_itp_f(const srt_hset *s, size_t begin, size_t end, srt_hset_it_f f, void *context)
- Enumerate set elements in portions (SHS_F)
- const srt_hset *s: set
- size_t begin: index start
- size_t end: index end
- srt_hset_it_f f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_itp_i(const srt_hset *s, size_t begin, size_t end, srt_hset_it_i f, void *context)
- Enumerate set elements in portions (SHS_I)
- const srt_hset *s: set
- size_t begin: index start
- size_t end: index end
- srt_hset_it_i f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_itp_i32(const srt_hset *s, size_t begin, size_t end, srt_hset_it_i32 f, void *context)
- Enumerate set elements in portions (SHS_I32)
- const srt_hset *s: set
- size_t begin: index start
- size_t end: index end
- srt_hset_it_i32 f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_itp_s(const srt_hset *s, size_t begin, size_t end, srt_hset_it_s f, void *context)
- Enumerate set elements in portions (SHS_S)
- const srt_hset *s: set
- size_t begin: index start
- size_t end: index end
- srt_hset_it_s f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_itp_u32(const srt_hset *s, size_t begin, size_t end, srt_hset_it_u32 f, void *context)
- Enumerate set elements in portions (SHS_U32)
- const srt_hset *s: set
- size_t begin: index start
- size_t end: index end
- srt_hset_it_u32 f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_max_size(const srt_hset *hs)
- Get hmap size
- const srt_hset *hs: map
- Return (size_t): hash set current max number of elements
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_reserve(srt_hset **hs, size_t max_elems)
- Ensure space for elements
- srt_hset **hs: hash set
- size_t max_elems: absolute element reserve
- Return (size_t): reserved elements
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_hset *shs_shrink(srt_hset **hs)
- Make the hmap use the minimum possible memory
- srt_hset **hs: hash set
- Return (srt_hset *): hash set reference (optional usage)
- Time complexity: O(1) for allocators using memory remap
- Space complexity: O(n) for naive allocators
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t shs_size(const srt_hset *hs)
- Get hmap size
- const srt_hset *hs: map
- Return (size_t): hash set number of elements
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)