smset.h: set handling (key-only storage)
Set functions handle key-only storage, which is implemented as a
Red-Black tree (O(n log n) maximum complexity for insert/read/delete).
Supported set modes (enum eSMS_Type):
SMS_I32: int32_t key
SMS_U32: uint32_t key
SMS_I: int64_t key
SMS_F: float (single-precision floating point) key
SMS_D: double (double-precision floating point) key
SMS_S: string key
Callback types for the sm_itr_*() functions:
typedef srt_bool (*srt_set_it_i32)(int32_t k, void *context);
typedef srt_bool (*srt_set_it_u32)(uint32_t k, void *context);
typedef srt_bool (*srt_set_it_i)(int64_t k, void *context);
typedef srt_bool (*srt_set_it_f)(float k, void *context);
typedef srt_bool (*srt_set_it_d)(double k, void *context);
typedef srt_bool (*srt_set_it_s)(const srt_string *, void *context);
srt_set *sms_alloc(enum eSMS_Type t, size_t initial_num_elems_reserve)
- Allocate set (heap)
- enum eSMS_Type t: set type
- size_t initial_num_elems_reserve: initial reserve
- Return (srt_set *): set
- 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_set *sms_alloca(enum eSMS_Type t, size_t n)
- Allocate set (stack)
- enum eSMS_Type t: set type
- size_t n: initial reserve
- Return (srt_set *): set
- 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 sms_capacity(const srt_set *s)
- Allocated space
- const srt_set *s: 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 sms_capacity_left(const srt_set *s)
- Preallocated space left
- const srt_set *s: 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 sms_clear(srt_set *s)
- Reset/clean set (keeping set type)
- srt_set *s: set
- Return (void): -
- Time complexity: O(1) for simple sets, O(n) for sets 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 sms_count_d(const srt_set *s, double k)
- Set element count/check (SMS_D)
- const srt_set *s: set
- double k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the set
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_count_f(const srt_set *s, float k)
- Set element count/check (SMS_F)
- const srt_set *s: set
- float k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the set
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_count_i(const srt_set *s, int64_t k)
- Set element count/check (SMS_I)
- const srt_set *s: set
- int64_t k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the set
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_count_i32(const srt_set *s, int32_t k)
- Set element count/check (SMS_I32)
- const srt_set *s: set
- int32_t k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the set
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_count_s(const srt_set *s, const srt_string *k)
- Set element count/check (SMS_S)
- const srt_set *s: set
- const srt_string *k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the set
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_count_u32(const srt_set *s, uint32_t k)
- Set element count/check (SMS_U32)
- const srt_set *s: set
- uint32_t k: key
- Return (size_t): S_TRUE: element found; S_FALSE: not in the set
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_set *sms_cpy(srt_set **s, const srt_set *src)
- Overwrite set with a set copy
- srt_set **s: output set
- const srt_set *src: input set
- Return (srt_set *): output set reference (optional usage)
- 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_bool sms_delete_d(srt_set *s, double k)
- Delete element (SMS_D)
- srt_set *s: set
- double k: key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_delete_f(srt_set *s, float k)
- Delete element (SMS_F)
- srt_set *s: set
- float k: key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_delete_i(srt_set *s, int64_t k)
- Delete element (SMS_I)
- srt_set *s: set
- int64_t k: key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_delete_i32(srt_set *s, int32_t k)
- Delete element (SMS_I32)
- srt_set *s: set
- int32_t k: key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_delete_s(srt_set *s, const srt_string *k)
- Delete element (SMS_S)
- srt_set *s: set
- const srt_string *k: key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_delete_u32(srt_set *s, uint32_t k)
- Delete element (SMS_U32)
- srt_set *s: set
- uint32_t k: key
- Return (srt_bool): S_TRUE: found and deleted; S_FALSE: not found
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_set *sms_dup(const srt_set *src)
- Duplicate set
- const srt_set *src: input set
- Return (srt_set *): output 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_bool sms_empty(const srt_set *s)
- Tells if a set is empty (zero elements)
- const srt_set *s: set
- Return (srt_bool): S_TRUE: empty vector; 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 sms_free(srt_map **s, ...)
- Free one or more sets (heap)
- srt_map **s: set
- ...: more sets (optional)
- Return (void): -
- Time complexity: O(1) for simple sets, O(n) for string sets
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_grow(srt_set **s, size_t extra_elems)
- Ensure space for extra elements
- srt_set **s: 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 sms_insert_d(srt_set **s, double k)
- Insert element (SMS_D)
- srt_set **s: set
- double k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_insert_f(srt_set **s, float k)
- Insert element (SMS_F)
- srt_set **s: set
- float k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_insert_i(srt_set **s, int64_t k)
- Insert element (SMS_I)
- srt_set **s: set
- int64_t k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_insert_i32(srt_set **s, int32_t k)
- Insert element (SMS_I32)
- srt_set **s: set
- int32_t k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_insert_s(srt_set **s, const srt_string *k)
- Insert element (SMS_S)
- srt_set **s: set
- const srt_string *k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
srt_bool sms_insert_u32(srt_set **s, uint32_t k)
- Insert element (SMS_U32)
- srt_set **s: set
- uint32_t k: key
- Return (srt_bool): S_TRUE: OK, S_FALSE: insertion error
- Time complexity: O(log n)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
double sms_it_d(const srt_set *s, srt_tndx i)
- Enumerate elements (SMS_D)
- const srt_set *s: set
- srt_tndx i: element, 0 to n - 1
- Return (double): double
- Time complexity: O(1)
- Space complexity: no extra space
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
float sms_it_f(const srt_set *s, srt_tndx i)
- Enumerate elements (SMS_F)
- const srt_set *s: set
- srt_tndx i: element, 0 to n - 1
- Return (float): float
- 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 sms_it_i(const srt_set *s, srt_tndx i)
- Enumerate elements (SMS_I)
- const srt_set *s: set
- srt_tndx i: element, 0 to n - 1
- Return (int32_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 sms_it_i32(const srt_set *s, srt_tndx i)
- Enumerate elements (SMS_I32)
- const srt_set *s: set
- srt_tndx 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)
int32_t sms_it_s(const srt_set *s, srt_tndx i)
- Enumerate elements (SMS_S)
- const srt_set *s: set
- srt_tndx i: element, 0 to n - 1
- Return (int32_t): 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 sms_it_u32(const srt_set *s, srt_tndx i)
- Enumerate elements (SMS_U32)
- const srt_set *s: set
- srt_tndx 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 sms_itr_d(const srt_set *s, double key_min, double key_max, srt_set_it_d f, void *context)
- Enumerate elements in a given key range (SMS_D)
- const srt_set *s: set
- double key_min: key lower bound
- double key_max: key upper bound
- srt_set_it_d f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(log n) + O(log m)
- Space complexity: additional 2 * O(log n) space required, allocated on the stack, i.e. fast
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_itr_f(const srt_set *s, float key_min, float key_max, srt_set_it_f f, void *context)
- Enumerate elements in a given key range (SMS_F)
- const srt_set *s: set
- float key_min: key lower bound
- float key_max: key upper bound
- srt_set_it_f f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(log n) + O(log m)
- Space complexity: additional 2 * O(log n) space required, allocated on the stack, i.e. fast
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_itr_i(const srt_set *s, int64_t key_min, int64_t key_max, srt_set_it_i f, void *context)
- Enumerate elements in a given key range (SMS_I)
- const srt_set *s: set
- int64_t key_min: key lower bound
- int64_t key_max: key upper bound
- srt_set_it_i f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(log n) + O(log m)
- Space complexity: additional 2 * O(log n) space required, allocated on the stack, i.e. fast
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_itr_i32(const srt_set *s, int32_t key_min, int32_t key_max, srt_set_it_i32 f, void *context)
- Enumerate elements in a given key range (SMS_I32)
- const srt_set *s: set
- int32_t key_min: key lower bound
- int32_t key_max: key upper bound
- srt_set_it_i32 f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(log n) + O(log m)
- Space complexity: additional 2 * O(log n) space required, allocated on the stack, i.e. fast
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_itr_s(const srt_set *s, const srt_string *key_min, const srt_string *key_max, srt_set_it_s f, void *context)
- Enumerate elements in a given key range (SMS_S)
- const srt_set *s: set
- const srt_string *key_min: key lower bound
- const srt_string *key_max: key upper bound
- srt_set_it_s f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(log n) + O(log m)
- Space complexity: additional 2 * O(log n) space required, allocated on the stack, i.e. fast
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_itr_u32(const srt_set *s, uint32_t key_min, uint32_t key_max, srt_set_it_u32 f, void *context)
- Enumerate elements in a given key range (SMS_U32)
- const srt_set *s: set
- uint32_t key_min: key lower bound
- uint32_t key_max: key upper bound
- srt_set_it_u32 f: callback function
- void *context: callback function context
- Return (size_t): Elements processed
- Time complexity: O(log n) + O(log m)
- Space complexity: additional 2 * O(log n) space required, allocated on the stack, i.e. fast
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_reserve(srt_set **s, size_t max_elems)
- Ensure space for elements
- srt_set **s: 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_set *sms_shrink(srt_set **s)
- Make the set use the minimum possible memory
- srt_set **s: set
- Return (srt_set *): set reference (optional usage)
- Time complexity: O(1) for allocators using memory reset
- Space complexity: O(n) for naive allocators
- Coverage: [1/2] test covered (test + Valgrind)
- Quality: [2/4] reviewed, clean (-Wall, style, speed)
size_t sms_size(const srt_set *s)
- Get set size
- const srt_set *s: set
- Return (size_t): 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)