/* set_altcap.c - Probes set.h with a non-default DLIBC_SET_INITIAL_CAPACITY. The macro is read at include time, so exercising it needs a translation unit of its own. Every function in set.h is static inline, so this TU gets its own copies built around the smaller constant while the set_t layout stays identical to the one in test_set.c. That means a set created here is a perfectly ordinary set to the rest of the program. @attention This TU deliberately does not include dtest.h. The harness counters are file-scope statics, so an assertion made here would be tallied separately and never reach the summary. The probes below only gather observations, and test_set.c does the asserting. */ #define DLIBC_SET_INITIAL_CAPACITY 1 #include "../set.h" /* @brief Records the set's capacity after each of count successive insert() calls of distinct values, starting from a freshly created set. @param out A buffer of at least count size_t values, filled with the capacity observed after each insert. @param count The number of inserts to perform. @return 0 on success, -1 if out is NULL, count is 0, or any insert fails. @attention With DLIBC_SET_INITIAL_CAPACITY at 1, the expected sequence is 1, 2, 4, 4, 8, 8, 8, 8, ... */ int set_altcap_growth_sequence(size_t* out, size_t count) { if (!out || count == 0) { return -1; } set_t* set = set_create(sizeof(int)); if (!set) { return -1; } for (size_t i = 0; i < count; ++i) { int value = (int)i; if (set_insert(set, &value) != 0) { set_destroy(&set); return -1; } out[i] = set_capacity(set); } set_destroy(&set); return 0; } /* @brief Reports the capacity of a freshly created set in this translation unit. @return The initial capacity, or 0 if creation failed. */ size_t set_altcap_initial_capacity(void) { set_t* set = set_create(sizeof(int)); if (!set) { return 0; } size_t capacity = set_capacity(set); set_destroy(&set); return capacity; }