Massive changes, unit tests halted
Code format changes that significantly reduce file sizes Working towards many new features at the same time Callbacks are going to be optional Everything is still breaking
This commit is contained in:
1 parent
770ec1c4c7
commit
aa033b0316
71 files changed
+19023
-21074
No files matched your search
+2
-2
@@ -1,13 +1,13 @@
|
|||||||
# clang-format 9.0.0
|
# clang-format 9.0.0
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
AlignEscapedNewlines: Left
|
AlignEscapedNewlines: DontAlign
|
||||||
AllowShortFunctionsOnASingleLine: None
|
AllowShortFunctionsOnASingleLine: None
|
||||||
AllowShortIfStatementsOnASingleLine: Never
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
BreakBeforeBraces: Allman
|
BreakBeforeBraces: Allman
|
||||||
BreakStringLiterals: false
|
BreakStringLiterals: false
|
||||||
ColumnLimit: 80
|
ColumnLimit: 120
|
||||||
Cpp11BracedListStyle: false
|
Cpp11BracedListStyle: false
|
||||||
ForEachMacros: ["CMC_FOREACH", "CMC_FOREACH_REV"]
|
ForEachMacros: ["CMC_FOREACH", "CMC_FOREACH_REV"]
|
||||||
IndentCaseLabels: true
|
IndentCaseLabels: true
|
||||||
|
|||||||
+486
-521
File diff suppressed because it is too large.
Load diff
+440
-464
@@ -43,484 +43,460 @@
|
|||||||
/**
|
/**
|
||||||
* Core Deque implementation
|
* Core Deque implementation
|
||||||
*/
|
*/
|
||||||
#define CMC_CMC_DEQUE_CORE(PARAMS) \
|
#define CMC_CMC_DEQUE_CORE(PARAMS) \
|
||||||
CMC_CMC_DEQUE_CORE_HEADER(PARAMS) \
|
CMC_CMC_DEQUE_CORE_HEADER(PARAMS) \
|
||||||
CMC_CMC_DEQUE_CORE_SOURCE(PARAMS)
|
CMC_CMC_DEQUE_CORE_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_CMC_DEQUE_CORE_HEADER(PARAMS) \
|
#define CMC_CMC_DEQUE_CORE_HEADER(PARAMS) \
|
||||||
CMC_CMC_DEQUE_CORE_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), \
|
CMC_CMC_DEQUE_CORE_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_CMC_DEQUE_CORE_SOURCE(PARAMS) \
|
#define CMC_CMC_DEQUE_CORE_SOURCE(PARAMS) \
|
||||||
CMC_CMC_DEQUE_CORE_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), \
|
CMC_CMC_DEQUE_CORE_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Header
|
* Header
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
#define CMC_CMC_DEQUE_CORE_HEADER_(PFX, SNAME, V) \
|
#define CMC_CMC_DEQUE_CORE_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* Deque Structure */ \
|
/* Deque Structure */ \
|
||||||
struct SNAME \
|
struct SNAME \
|
||||||
{ \
|
{ \
|
||||||
/* Dynamic circular array of elements */ \
|
/* Dynamic circular array of elements */ \
|
||||||
V *buffer; \
|
V *buffer; \
|
||||||
\
|
\
|
||||||
/* Current circular array capacity */ \
|
/* Current circular array capacity */ \
|
||||||
size_t capacity; \
|
size_t capacity; \
|
||||||
\
|
\
|
||||||
/* Current amount of elements */ \
|
/* Current amount of elements */ \
|
||||||
size_t count; \
|
size_t count; \
|
||||||
\
|
\
|
||||||
/* Index representing the front of the deque */ \
|
/* Index representing the front of the deque */ \
|
||||||
size_t front; \
|
size_t front; \
|
||||||
\
|
\
|
||||||
/* Index representing the back of the deque */ \
|
/* Index representing the back of the deque */ \
|
||||||
size_t back; \
|
size_t back; \
|
||||||
\
|
\
|
||||||
/* Flags indicating errors or success */ \
|
/* Flags indicating errors or success */ \
|
||||||
int flag; \
|
int flag; \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val; \
|
struct CMC_DEF_FVAL(SNAME) * f_val; \
|
||||||
\
|
\
|
||||||
/* Custom allocation functions */ \
|
/* Custom allocation functions */ \
|
||||||
struct cmc_alloc_node *alloc; \
|
struct CMC_ALLOC_NODE_NAME *alloc; \
|
||||||
\
|
\
|
||||||
/* Custom callback functions */ \
|
/* Custom callback functions */ \
|
||||||
struct cmc_callbacks *callbacks; \
|
CMC_CALLBACKS_DECL; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_FVAL(SNAME) \
|
struct CMC_DEF_FVAL(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Comparator function */ \
|
/* Comparator function */ \
|
||||||
CMC_DEF_FTAB_CMP(V); \
|
CMC_DEF_FTAB_CMP(V); \
|
||||||
\
|
\
|
||||||
/* Copy function */ \
|
/* Copy function */ \
|
||||||
CMC_DEF_FTAB_CPY(V); \
|
CMC_DEF_FTAB_CPY(V); \
|
||||||
\
|
\
|
||||||
/* To string function */ \
|
/* To string function */ \
|
||||||
CMC_DEF_FTAB_STR(V); \
|
CMC_DEF_FTAB_STR(V); \
|
||||||
\
|
\
|
||||||
/* Free from memory function */ \
|
/* Free from memory function */ \
|
||||||
CMC_DEF_FTAB_FREE(V); \
|
CMC_DEF_FTAB_FREE(V); \
|
||||||
\
|
\
|
||||||
/* Hash function */ \
|
/* Hash function */ \
|
||||||
CMC_DEF_FTAB_HASH(V); \
|
CMC_DEF_FTAB_HASH(V); \
|
||||||
\
|
\
|
||||||
/* Priority function */ \
|
/* Priority function */ \
|
||||||
CMC_DEF_FTAB_PRI(V); \
|
CMC_DEF_FTAB_PRI(V); \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Collection Functions */ \
|
/* Collection Functions */ \
|
||||||
/* Collection Allocation and Deallocation */ \
|
/* Collection Allocation and Deallocation */ \
|
||||||
struct SNAME *CMC_(PFX, _new)(size_t capacity, \
|
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val); \
|
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||||
struct SNAME *CMC_(PFX, _new_custom)( \
|
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks); \
|
||||||
size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
void CMC_(PFX, _clear)(struct SNAME * _deque_); \
|
||||||
struct cmc_alloc_node * alloc, struct cmc_callbacks * callbacks); \
|
void CMC_(PFX, _free)(struct SNAME * _deque_); \
|
||||||
void CMC_(PFX, _clear)(struct SNAME * _deque_); \
|
/* Customization of Allocation and Callbacks */ \
|
||||||
void CMC_(PFX, _free)(struct SNAME * _deque_); \
|
void CMC_(PFX, _customize)(struct SNAME * _deque_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||||
/* Customization of Allocation and Callbacks */ \
|
struct CMC_CALLBACKS_NAME * callbacks); \
|
||||||
void CMC_(PFX, _customize)(struct SNAME * _deque_, \
|
/* Collection Input and Output */ \
|
||||||
struct cmc_alloc_node * alloc, \
|
bool CMC_(PFX, _push_front)(struct SNAME * _deque_, V value); \
|
||||||
struct cmc_callbacks * callbacks); \
|
bool CMC_(PFX, _push_back)(struct SNAME * _deque_, V value); \
|
||||||
/* Collection Input and Output */ \
|
bool CMC_(PFX, _pop_front)(struct SNAME * _deque_); \
|
||||||
bool CMC_(PFX, _push_front)(struct SNAME * _deque_, V value); \
|
bool CMC_(PFX, _pop_back)(struct SNAME * _deque_); \
|
||||||
bool CMC_(PFX, _push_back)(struct SNAME * _deque_, V value); \
|
/* Element Access */ \
|
||||||
bool CMC_(PFX, _pop_front)(struct SNAME * _deque_); \
|
V CMC_(PFX, _front)(struct SNAME * _deque_); \
|
||||||
bool CMC_(PFX, _pop_back)(struct SNAME * _deque_); \
|
V CMC_(PFX, _back)(struct SNAME * _deque_); \
|
||||||
/* Element Access */ \
|
/* Collection State */ \
|
||||||
V CMC_(PFX, _front)(struct SNAME * _deque_); \
|
bool CMC_(PFX, _contains)(struct SNAME * _deque_, V value); \
|
||||||
V CMC_(PFX, _back)(struct SNAME * _deque_); \
|
bool CMC_(PFX, _empty)(struct SNAME * _deque_); \
|
||||||
/* Collection State */ \
|
bool CMC_(PFX, _full)(struct SNAME * _deque_); \
|
||||||
bool CMC_(PFX, _contains)(struct SNAME * _deque_, V value); \
|
size_t CMC_(PFX, _count)(struct SNAME * _deque_); \
|
||||||
bool CMC_(PFX, _empty)(struct SNAME * _deque_); \
|
size_t CMC_(PFX, _capacity)(struct SNAME * _deque_); \
|
||||||
bool CMC_(PFX, _full)(struct SNAME * _deque_); \
|
int CMC_(PFX, _flag)(struct SNAME * _deque_); \
|
||||||
size_t CMC_(PFX, _count)(struct SNAME * _deque_); \
|
/* Collection Utility */ \
|
||||||
size_t CMC_(PFX, _capacity)(struct SNAME * _deque_); \
|
bool CMC_(PFX, _resize)(struct SNAME * _deque_, size_t capacity); \
|
||||||
int CMC_(PFX, _flag)(struct SNAME * _deque_); \
|
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _deque_); \
|
||||||
/* Collection Utility */ \
|
|
||||||
bool CMC_(PFX, _resize)(struct SNAME * _deque_, size_t capacity); \
|
|
||||||
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _deque_); \
|
|
||||||
bool CMC_(PFX, _equals)(struct SNAME * _deque1_, struct SNAME * _deque2_);
|
bool CMC_(PFX, _equals)(struct SNAME * _deque1_, struct SNAME * _deque2_);
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Source
|
* Source
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
#define CMC_CMC_DEQUE_CORE_SOURCE_(PFX, SNAME, V) \
|
#define CMC_CMC_DEQUE_CORE_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* Implementation Detail Functions */ \
|
/* Implementation Detail Functions */ \
|
||||||
/* None */ \
|
/* None */ \
|
||||||
\
|
\
|
||||||
struct SNAME *CMC_(PFX, _new)(size_t capacity, \
|
struct SNAME *CMC_(PFX, _new)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val) \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val) \
|
{ \
|
||||||
{ \
|
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL); \
|
||||||
return CMC_(PFX, _new_custom)(capacity, f_val, NULL, NULL); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||||
struct SNAME *CMC_(PFX, _new_custom)( \
|
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||||
size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
{ \
|
||||||
struct cmc_alloc_node * alloc, struct cmc_callbacks * callbacks) \
|
if (capacity < 1) \
|
||||||
{ \
|
return NULL; \
|
||||||
if (capacity < 1) \
|
\
|
||||||
return NULL; \
|
if (!f_val) \
|
||||||
\
|
return NULL; \
|
||||||
if (!f_val) \
|
\
|
||||||
return NULL; \
|
if (!alloc) \
|
||||||
\
|
alloc = &cmc_alloc_node_default; \
|
||||||
if (!alloc) \
|
\
|
||||||
alloc = &cmc_alloc_node_default; \
|
struct SNAME *_deque_ = alloc->malloc(sizeof(struct SNAME)); \
|
||||||
\
|
\
|
||||||
struct SNAME *_deque_ = alloc->malloc(sizeof(struct SNAME)); \
|
if (!_deque_) \
|
||||||
\
|
return NULL; \
|
||||||
if (!_deque_) \
|
\
|
||||||
return NULL; \
|
_deque_->buffer = alloc->calloc(capacity, sizeof(V)); \
|
||||||
\
|
\
|
||||||
_deque_->buffer = alloc->calloc(capacity, sizeof(V)); \
|
if (!_deque_->buffer) \
|
||||||
\
|
{ \
|
||||||
if (!_deque_->buffer) \
|
alloc->free(_deque_); \
|
||||||
{ \
|
return NULL; \
|
||||||
alloc->free(_deque_); \
|
} \
|
||||||
return NULL; \
|
\
|
||||||
} \
|
_deque_->capacity = capacity; \
|
||||||
\
|
_deque_->count = 0; \
|
||||||
_deque_->capacity = capacity; \
|
_deque_->front = 0; \
|
||||||
_deque_->count = 0; \
|
_deque_->back = 0; \
|
||||||
_deque_->front = 0; \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
_deque_->back = 0; \
|
_deque_->f_val = f_val; \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
_deque_->alloc = alloc; \
|
||||||
_deque_->f_val = f_val; \
|
CMC_CALLBACKS_ASSIGN(_deque_, callbacks); \
|
||||||
_deque_->alloc = alloc; \
|
\
|
||||||
_deque_->callbacks = callbacks; \
|
return _deque_; \
|
||||||
\
|
} \
|
||||||
return _deque_; \
|
\
|
||||||
} \
|
void CMC_(PFX, _clear)(struct SNAME * _deque_) \
|
||||||
\
|
{ \
|
||||||
void CMC_(PFX, _clear)(struct SNAME * _deque_) \
|
if (_deque_->f_val->free) \
|
||||||
{ \
|
{ \
|
||||||
if (_deque_->f_val->free) \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
_deque_->f_val->free(_deque_->buffer[i]); \
|
||||||
{ \
|
\
|
||||||
_deque_->f_val->free(_deque_->buffer[i]); \
|
i = (i + 1) % _deque_->capacity; \
|
||||||
\
|
} \
|
||||||
i = (i + 1) % _deque_->capacity; \
|
} \
|
||||||
} \
|
\
|
||||||
} \
|
memset(_deque_->buffer, 0, sizeof(V) * _deque_->capacity); \
|
||||||
\
|
\
|
||||||
memset(_deque_->buffer, 0, sizeof(V) * _deque_->capacity); \
|
_deque_->count = 0; \
|
||||||
\
|
_deque_->front = 0; \
|
||||||
_deque_->count = 0; \
|
_deque_->back = 0; \
|
||||||
_deque_->front = 0; \
|
\
|
||||||
_deque_->back = 0; \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
\
|
} \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
\
|
||||||
} \
|
void CMC_(PFX, _free)(struct SNAME * _deque_) \
|
||||||
\
|
{ \
|
||||||
void CMC_(PFX, _free)(struct SNAME * _deque_) \
|
if (_deque_->f_val->free) \
|
||||||
{ \
|
{ \
|
||||||
if (_deque_->f_val->free) \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
_deque_->f_val->free(_deque_->buffer[i]); \
|
||||||
{ \
|
\
|
||||||
_deque_->f_val->free(_deque_->buffer[i]); \
|
i = (i + 1) % _deque_->capacity; \
|
||||||
\
|
} \
|
||||||
i = (i + 1) % _deque_->capacity; \
|
} \
|
||||||
} \
|
\
|
||||||
} \
|
_deque_->alloc->free(_deque_->buffer); \
|
||||||
\
|
_deque_->alloc->free(_deque_); \
|
||||||
_deque_->alloc->free(_deque_->buffer); \
|
} \
|
||||||
_deque_->alloc->free(_deque_); \
|
\
|
||||||
} \
|
void CMC_(PFX, _customize)(struct SNAME * _deque_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||||
\
|
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||||
void CMC_(PFX, _customize)(struct SNAME * _deque_, \
|
{ \
|
||||||
struct cmc_alloc_node * alloc, \
|
if (!alloc) \
|
||||||
struct cmc_callbacks * callbacks) \
|
_deque_->alloc = &cmc_alloc_node_default; \
|
||||||
{ \
|
else \
|
||||||
if (!alloc) \
|
_deque_->alloc = alloc; \
|
||||||
_deque_->alloc = &cmc_alloc_node_default; \
|
\
|
||||||
else \
|
CMC_CALLBACKS_ASSIGN(_deque_, callbacks); \
|
||||||
_deque_->alloc = alloc; \
|
\
|
||||||
\
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
_deque_->callbacks = callbacks; \
|
} \
|
||||||
\
|
\
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
bool CMC_(PFX, _push_front)(struct SNAME * _deque_, V value) \
|
||||||
} \
|
{ \
|
||||||
\
|
if (CMC_(PFX, _full)(_deque_)) \
|
||||||
bool CMC_(PFX, _push_front)(struct SNAME * _deque_, V value) \
|
{ \
|
||||||
{ \
|
if (!CMC_(PFX, _resize)(_deque_, _deque_->capacity * 2)) \
|
||||||
if (CMC_(PFX, _full)(_deque_)) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
if (!CMC_(PFX, _resize)(_deque_, _deque_->capacity * 2)) \
|
\
|
||||||
return false; \
|
_deque_->front = (_deque_->front == 0) ? _deque_->capacity - 1 : _deque_->front - 1; \
|
||||||
} \
|
\
|
||||||
\
|
_deque_->buffer[_deque_->front] = value; \
|
||||||
_deque_->front = (_deque_->front == 0) ? _deque_->capacity - 1 \
|
\
|
||||||
: _deque_->front - 1; \
|
_deque_->count++; \
|
||||||
\
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
_deque_->buffer[_deque_->front] = value; \
|
\
|
||||||
\
|
CMC_CALLBACKS_CALL(_deque_, create); \
|
||||||
_deque_->count++; \
|
\
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
return true; \
|
||||||
\
|
} \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->create) \
|
\
|
||||||
_deque_->callbacks->create(); \
|
bool CMC_(PFX, _push_back)(struct SNAME * _deque_, V value) \
|
||||||
\
|
{ \
|
||||||
return true; \
|
if (CMC_(PFX, _full)(_deque_)) \
|
||||||
} \
|
{ \
|
||||||
\
|
if (!CMC_(PFX, _resize)(_deque_, _deque_->capacity * 2)) \
|
||||||
bool CMC_(PFX, _push_back)(struct SNAME * _deque_, V value) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
if (CMC_(PFX, _full)(_deque_)) \
|
\
|
||||||
{ \
|
_deque_->buffer[_deque_->back] = value; \
|
||||||
if (!CMC_(PFX, _resize)(_deque_, _deque_->capacity * 2)) \
|
\
|
||||||
return false; \
|
_deque_->back = (_deque_->back == _deque_->capacity - 1) ? 0 : _deque_->back + 1; \
|
||||||
} \
|
\
|
||||||
\
|
_deque_->count++; \
|
||||||
_deque_->buffer[_deque_->back] = value; \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
_deque_->back = \
|
CMC_CALLBACKS_CALL(_deque_, create); \
|
||||||
(_deque_->back == _deque_->capacity - 1) ? 0 : _deque_->back + 1; \
|
\
|
||||||
\
|
return true; \
|
||||||
_deque_->count++; \
|
} \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
\
|
||||||
\
|
bool CMC_(PFX, _pop_front)(struct SNAME * _deque_) \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->create) \
|
{ \
|
||||||
_deque_->callbacks->create(); \
|
if (CMC_(PFX, _empty)(_deque_)) \
|
||||||
\
|
{ \
|
||||||
return true; \
|
_deque_->flag = CMC_FLAG_EMPTY; \
|
||||||
} \
|
return false; \
|
||||||
\
|
} \
|
||||||
bool CMC_(PFX, _pop_front)(struct SNAME * _deque_) \
|
\
|
||||||
{ \
|
_deque_->buffer[_deque_->front] = (V){ 0 }; \
|
||||||
if (CMC_(PFX, _empty)(_deque_)) \
|
\
|
||||||
{ \
|
_deque_->front = (_deque_->front == _deque_->capacity - 1) ? 0 : _deque_->front + 1; \
|
||||||
_deque_->flag = CMC_FLAG_EMPTY; \
|
\
|
||||||
return false; \
|
_deque_->count--; \
|
||||||
} \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
_deque_->buffer[_deque_->front] = (V){ 0 }; \
|
CMC_CALLBACKS_CALL(_deque_, delete); \
|
||||||
\
|
\
|
||||||
_deque_->front = (_deque_->front == _deque_->capacity - 1) \
|
return true; \
|
||||||
? 0 \
|
} \
|
||||||
: _deque_->front + 1; \
|
\
|
||||||
\
|
bool CMC_(PFX, _pop_back)(struct SNAME * _deque_) \
|
||||||
_deque_->count--; \
|
{ \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
if (CMC_(PFX, _empty)(_deque_)) \
|
||||||
\
|
{ \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->delete) \
|
_deque_->flag = CMC_FLAG_EMPTY; \
|
||||||
_deque_->callbacks->delete (); \
|
return false; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
_deque_->back = (_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1; \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _pop_back)(struct SNAME * _deque_) \
|
_deque_->buffer[_deque_->back] = (V){ 0 }; \
|
||||||
{ \
|
\
|
||||||
if (CMC_(PFX, _empty)(_deque_)) \
|
_deque_->count--; \
|
||||||
{ \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
_deque_->flag = CMC_FLAG_EMPTY; \
|
\
|
||||||
return false; \
|
CMC_CALLBACKS_CALL(_deque_, delete); \
|
||||||
} \
|
\
|
||||||
\
|
return true; \
|
||||||
_deque_->back = \
|
} \
|
||||||
(_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1; \
|
\
|
||||||
\
|
V CMC_(PFX, _front)(struct SNAME * _deque_) \
|
||||||
_deque_->buffer[_deque_->back] = (V){ 0 }; \
|
{ \
|
||||||
\
|
if (CMC_(PFX, _empty)(_deque_)) \
|
||||||
_deque_->count--; \
|
{ \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
_deque_->flag = CMC_FLAG_EMPTY; \
|
||||||
\
|
return (V){ 0 }; \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->delete) \
|
} \
|
||||||
_deque_->callbacks->delete (); \
|
\
|
||||||
\
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
return true; \
|
\
|
||||||
} \
|
CMC_CALLBACKS_CALL(_deque_, read); \
|
||||||
\
|
\
|
||||||
V CMC_(PFX, _front)(struct SNAME * _deque_) \
|
return _deque_->buffer[_deque_->front]; \
|
||||||
{ \
|
} \
|
||||||
if (CMC_(PFX, _empty)(_deque_)) \
|
\
|
||||||
{ \
|
V CMC_(PFX, _back)(struct SNAME * _deque_) \
|
||||||
_deque_->flag = CMC_FLAG_EMPTY; \
|
{ \
|
||||||
return (V){ 0 }; \
|
if (CMC_(PFX, _empty)(_deque_)) \
|
||||||
} \
|
{ \
|
||||||
\
|
_deque_->flag = CMC_FLAG_EMPTY; \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
return (V){ 0 }; \
|
||||||
\
|
} \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->read) \
|
\
|
||||||
_deque_->callbacks->read(); \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
return _deque_->buffer[_deque_->front]; \
|
CMC_CALLBACKS_CALL(_deque_, read); \
|
||||||
} \
|
\
|
||||||
\
|
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1]; \
|
||||||
V CMC_(PFX, _back)(struct SNAME * _deque_) \
|
} \
|
||||||
{ \
|
\
|
||||||
if (CMC_(PFX, _empty)(_deque_)) \
|
bool CMC_(PFX, _contains)(struct SNAME * _deque_, V value) \
|
||||||
{ \
|
{ \
|
||||||
_deque_->flag = CMC_FLAG_EMPTY; \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
return (V){ 0 }; \
|
\
|
||||||
} \
|
bool result = false; \
|
||||||
\
|
\
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
\
|
{ \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->read) \
|
if (_deque_->f_val->cmp(_deque_->buffer[i], value) == 0) \
|
||||||
_deque_->callbacks->read(); \
|
{ \
|
||||||
\
|
result = true; \
|
||||||
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1 \
|
break; \
|
||||||
: _deque_->back - 1]; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
i = (i + 1) % _deque_->capacity; \
|
||||||
bool CMC_(PFX, _contains)(struct SNAME * _deque_, V value) \
|
} \
|
||||||
{ \
|
\
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
CMC_CALLBACKS_CALL(_deque_, read); \
|
||||||
\
|
\
|
||||||
bool result = false; \
|
return result; \
|
||||||
\
|
} \
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
\
|
||||||
{ \
|
bool CMC_(PFX, _empty)(struct SNAME * _deque_) \
|
||||||
if (_deque_->f_val->cmp(_deque_->buffer[i], value) == 0) \
|
{ \
|
||||||
{ \
|
return _deque_->count == 0; \
|
||||||
result = true; \
|
} \
|
||||||
break; \
|
\
|
||||||
} \
|
bool CMC_(PFX, _full)(struct SNAME * _deque_) \
|
||||||
\
|
{ \
|
||||||
i = (i + 1) % _deque_->capacity; \
|
return _deque_->count >= _deque_->capacity; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if (_deque_->callbacks && _deque_->callbacks->read) \
|
size_t CMC_(PFX, _count)(struct SNAME * _deque_) \
|
||||||
_deque_->callbacks->read(); \
|
{ \
|
||||||
\
|
return _deque_->count; \
|
||||||
return result; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
size_t CMC_(PFX, _capacity)(struct SNAME * _deque_) \
|
||||||
bool CMC_(PFX, _empty)(struct SNAME * _deque_) \
|
{ \
|
||||||
{ \
|
return _deque_->capacity; \
|
||||||
return _deque_->count == 0; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
int CMC_(PFX, _flag)(struct SNAME * _deque_) \
|
||||||
bool CMC_(PFX, _full)(struct SNAME * _deque_) \
|
{ \
|
||||||
{ \
|
return _deque_->flag; \
|
||||||
return _deque_->count >= _deque_->capacity; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _resize)(struct SNAME * _deque_, size_t capacity) \
|
||||||
size_t CMC_(PFX, _count)(struct SNAME * _deque_) \
|
{ \
|
||||||
{ \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
return _deque_->count; \
|
\
|
||||||
} \
|
if (_deque_->capacity == capacity) \
|
||||||
\
|
goto success; \
|
||||||
size_t CMC_(PFX, _capacity)(struct SNAME * _deque_) \
|
\
|
||||||
{ \
|
if (capacity < _deque_->count) \
|
||||||
return _deque_->capacity; \
|
{ \
|
||||||
} \
|
_deque_->flag = CMC_FLAG_INVALID; \
|
||||||
\
|
return false; \
|
||||||
int CMC_(PFX, _flag)(struct SNAME * _deque_) \
|
} \
|
||||||
{ \
|
\
|
||||||
return _deque_->flag; \
|
V *new_buffer = _deque_->alloc->malloc(sizeof(V) * capacity); \
|
||||||
} \
|
\
|
||||||
\
|
if (!new_buffer) \
|
||||||
bool CMC_(PFX, _resize)(struct SNAME * _deque_, size_t capacity) \
|
{ \
|
||||||
{ \
|
_deque_->flag = CMC_FLAG_ALLOC; \
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
return false; \
|
||||||
\
|
} \
|
||||||
if (_deque_->capacity == capacity) \
|
\
|
||||||
goto success; \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
\
|
{ \
|
||||||
if (capacity < _deque_->count) \
|
new_buffer[j] = _deque_->buffer[i]; \
|
||||||
{ \
|
\
|
||||||
_deque_->flag = CMC_FLAG_INVALID; \
|
i = (i + 1) % _deque_->capacity; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
_deque_->alloc->free(_deque_->buffer); \
|
||||||
V *new_buffer = _deque_->alloc->malloc(sizeof(V) * capacity); \
|
\
|
||||||
\
|
_deque_->buffer = new_buffer; \
|
||||||
if (!new_buffer) \
|
_deque_->capacity = capacity; \
|
||||||
{ \
|
_deque_->front = 0; \
|
||||||
_deque_->flag = CMC_FLAG_ALLOC; \
|
_deque_->back = _deque_->count; \
|
||||||
return false; \
|
\
|
||||||
} \
|
success: \
|
||||||
\
|
\
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
CMC_CALLBACKS_CALL(_deque_, resize); \
|
||||||
{ \
|
\
|
||||||
new_buffer[j] = _deque_->buffer[i]; \
|
return true; \
|
||||||
\
|
} \
|
||||||
i = (i + 1) % _deque_->capacity; \
|
\
|
||||||
} \
|
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _deque_) \
|
||||||
\
|
{ \
|
||||||
_deque_->alloc->free(_deque_->buffer); \
|
struct SNAME *result = CMC_(PFX, _new_custom)(_deque_->capacity, _deque_->f_val, _deque_->alloc, NULL); \
|
||||||
\
|
\
|
||||||
_deque_->buffer = new_buffer; \
|
if (!result) \
|
||||||
_deque_->capacity = capacity; \
|
{ \
|
||||||
_deque_->front = 0; \
|
_deque_->flag = CMC_FLAG_ERROR; \
|
||||||
_deque_->back = _deque_->count; \
|
return NULL; \
|
||||||
\
|
} \
|
||||||
success: \
|
\
|
||||||
\
|
CMC_CALLBACKS_ASSIGN(result, _deque_->callbacks); \
|
||||||
if (_deque_->callbacks && _deque_->callbacks->resize) \
|
\
|
||||||
_deque_->callbacks->resize(); \
|
if (_deque_->f_val->cpy) \
|
||||||
\
|
{ \
|
||||||
return true; \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
} \
|
{ \
|
||||||
\
|
result->buffer[j] = _deque_->f_val->cpy(_deque_->buffer[i]); \
|
||||||
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _deque_) \
|
\
|
||||||
{ \
|
i = (i + 1) % _deque_->capacity; \
|
||||||
struct SNAME *result = \
|
} \
|
||||||
CMC_(PFX, _new_custom)(_deque_->capacity, _deque_->f_val, \
|
} \
|
||||||
_deque_->alloc, _deque_->callbacks); \
|
else \
|
||||||
\
|
{ \
|
||||||
if (!result) \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
{ \
|
{ \
|
||||||
_deque_->flag = CMC_FLAG_ERROR; \
|
result->buffer[j] = _deque_->buffer[i]; \
|
||||||
return NULL; \
|
\
|
||||||
} \
|
i = (i + 1) % _deque_->capacity; \
|
||||||
\
|
} \
|
||||||
if (_deque_->f_val->cpy) \
|
} \
|
||||||
{ \
|
\
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
result->count = _deque_->count; \
|
||||||
{ \
|
result->front = 0; \
|
||||||
result->buffer[j] = _deque_->f_val->cpy(_deque_->buffer[i]); \
|
result->back = _deque_->count; \
|
||||||
\
|
\
|
||||||
i = (i + 1) % _deque_->capacity; \
|
_deque_->flag = CMC_FLAG_OK; \
|
||||||
} \
|
\
|
||||||
} \
|
return result; \
|
||||||
else \
|
} \
|
||||||
{ \
|
\
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
|
||||||
{ \
|
|
||||||
result->buffer[j] = _deque_->buffer[i]; \
|
|
||||||
\
|
|
||||||
i = (i + 1) % _deque_->capacity; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
result->count = _deque_->count; \
|
|
||||||
result->front = 0; \
|
|
||||||
result->back = _deque_->count; \
|
|
||||||
\
|
|
||||||
_deque_->flag = CMC_FLAG_OK; \
|
|
||||||
\
|
|
||||||
return result; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
bool CMC_(PFX, _equals)(struct SNAME * _deque1_, struct SNAME * _deque2_) \
|
bool CMC_(PFX, _equals)(struct SNAME * _deque1_, struct SNAME * _deque2_) \
|
||||||
{ \
|
{ \
|
||||||
_deque1_->flag = CMC_FLAG_OK; \
|
_deque1_->flag = CMC_FLAG_OK; \
|
||||||
_deque2_->flag = CMC_FLAG_OK; \
|
_deque2_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
if (_deque1_->count != _deque2_->count) \
|
if (_deque1_->count != _deque2_->count) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
size_t i, j, k; \
|
size_t i, j, k; \
|
||||||
for (i = _deque1_->front, j = _deque2_->front, k = 0; \
|
for (i = _deque1_->front, j = _deque2_->front, k = 0; k < _deque1_->count; k++) \
|
||||||
k < _deque1_->count; k++) \
|
{ \
|
||||||
{ \
|
if (_deque1_->f_val->cmp(_deque1_->buffer[i], _deque2_->buffer[j]) != 0) \
|
||||||
if (_deque1_->f_val->cmp(_deque1_->buffer[i], \
|
return false; \
|
||||||
_deque2_->buffer[j]) != 0) \
|
\
|
||||||
return false; \
|
i = (i + 1) % _deque1_->capacity; \
|
||||||
\
|
j = (j + 1) % _deque2_->capacity; \
|
||||||
i = (i + 1) % _deque1_->capacity; \
|
} \
|
||||||
j = (j + 1) % _deque2_->capacity; \
|
\
|
||||||
} \
|
return true; \
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_CMC_DEQUE_H */
|
#endif /* CMC_CMC_DEQUE_H */
|
||||||
+1338
-1397
File diff suppressed because it is too large.
Load diff
+755
-781
File diff suppressed because it is too large.
Load diff
+963
-1039
File diff suppressed because it is too large.
Load diff
+793
-867
File diff suppressed because it is too large.
Load diff
+581
-638
File diff suppressed because it is too large.
Load diff
+420
-472
@@ -43,494 +43,442 @@
|
|||||||
/**
|
/**
|
||||||
* Core Heap implementation
|
* Core Heap implementation
|
||||||
*/
|
*/
|
||||||
#define CMC_CMC_HEAP_CORE(PARAMS) \
|
#define CMC_CMC_HEAP_CORE(PARAMS) \
|
||||||
CMC_CMC_HEAP_CORE_HEADER(PARAMS) \
|
CMC_CMC_HEAP_CORE_HEADER(PARAMS) \
|
||||||
CMC_CMC_HEAP_CORE_SOURCE(PARAMS)
|
CMC_CMC_HEAP_CORE_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_CMC_HEAP_CORE_HEADER(PARAMS) \
|
#define CMC_CMC_HEAP_CORE_HEADER(PARAMS) \
|
||||||
CMC_CMC_HEAP_CORE_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), \
|
CMC_CMC_HEAP_CORE_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_CMC_HEAP_CORE_SOURCE(PARAMS) \
|
#define CMC_CMC_HEAP_CORE_SOURCE(PARAMS) \
|
||||||
CMC_CMC_HEAP_CORE_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), \
|
CMC_CMC_HEAP_CORE_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Header
|
* Header
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
#define CMC_CMC_HEAP_CORE_HEADER_(PFX, SNAME, V) \
|
#define CMC_CMC_HEAP_CORE_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* Heap Structure */ \
|
/* Heap Structure */ \
|
||||||
struct SNAME \
|
struct SNAME \
|
||||||
{ \
|
{ \
|
||||||
/* Dynamic array of elements */ \
|
/* Dynamic array of elements */ \
|
||||||
V *buffer; \
|
V *buffer; \
|
||||||
\
|
\
|
||||||
/* Current array capacity */ \
|
/* Current array capacity */ \
|
||||||
size_t capacity; \
|
size_t capacity; \
|
||||||
\
|
\
|
||||||
/* Current amount of elements in the heap */ \
|
/* Current amount of elements in the heap */ \
|
||||||
size_t count; \
|
size_t count; \
|
||||||
\
|
\
|
||||||
/* Heap order (MaxHeap or MinHeap) */ \
|
/* Heap order (MaxHeap or MinHeap) */ \
|
||||||
enum cmc_heap_order HO; \
|
enum cmc_heap_order HO; \
|
||||||
\
|
\
|
||||||
/* Flags indicating errors or success */ \
|
/* Flags indicating errors or success */ \
|
||||||
int flag; \
|
int flag; \
|
||||||
\
|
\
|
||||||
/* Value function table */ \
|
/* Value function table */ \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val; \
|
struct CMC_DEF_FVAL(SNAME) * f_val; \
|
||||||
\
|
\
|
||||||
/* Custom allocation functions */ \
|
/* Custom allocation functions */ \
|
||||||
struct cmc_alloc_node *alloc; \
|
struct CMC_ALLOC_NODE_NAME *alloc; \
|
||||||
\
|
\
|
||||||
/* Custom callback functions */ \
|
/* Custom callback functions */ \
|
||||||
struct cmc_callbacks *callbacks; \
|
CMC_CALLBACKS_DECL; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Value struct function table */ \
|
/* Value struct function table */ \
|
||||||
struct CMC_DEF_FVAL(SNAME) \
|
struct CMC_DEF_FVAL(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Comparator function */ \
|
/* Comparator function */ \
|
||||||
CMC_DEF_FTAB_CMP(V); \
|
CMC_DEF_FTAB_CMP(V); \
|
||||||
\
|
\
|
||||||
/* Copy function */ \
|
/* Copy function */ \
|
||||||
CMC_DEF_FTAB_CPY(V); \
|
CMC_DEF_FTAB_CPY(V); \
|
||||||
\
|
\
|
||||||
/* To string function */ \
|
/* To string function */ \
|
||||||
CMC_DEF_FTAB_STR(V); \
|
CMC_DEF_FTAB_STR(V); \
|
||||||
\
|
\
|
||||||
/* Free from memory function */ \
|
/* Free from memory function */ \
|
||||||
CMC_DEF_FTAB_FREE(V); \
|
CMC_DEF_FTAB_FREE(V); \
|
||||||
\
|
\
|
||||||
/* Hash function */ \
|
/* Hash function */ \
|
||||||
CMC_DEF_FTAB_HASH(V); \
|
CMC_DEF_FTAB_HASH(V); \
|
||||||
\
|
\
|
||||||
/* Priority function */ \
|
/* Priority function */ \
|
||||||
CMC_DEF_FTAB_PRI(V); \
|
CMC_DEF_FTAB_PRI(V); \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Collection Functions */ \
|
/* Collection Functions */ \
|
||||||
/* Collection Allocation and Deallocation */ \
|
/* Collection Allocation and Deallocation */ \
|
||||||
struct SNAME *CMC_(PFX, _new)(size_t capacity, enum cmc_heap_order HO, \
|
struct SNAME *CMC_(PFX, _new)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val); \
|
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||||
struct SNAME *CMC_(PFX, _new_custom)( \
|
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks); \
|
||||||
size_t capacity, enum cmc_heap_order HO, \
|
void CMC_(PFX, _clear)(struct SNAME * _heap_); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct cmc_alloc_node * alloc, \
|
void CMC_(PFX, _free)(struct SNAME * _heap_); \
|
||||||
struct cmc_callbacks * callbacks); \
|
/* Customization of Allocation and Callbacks */ \
|
||||||
void CMC_(PFX, _clear)(struct SNAME * _heap_); \
|
void CMC_(PFX, _customize)(struct SNAME * _heap_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||||
void CMC_(PFX, _free)(struct SNAME * _heap_); \
|
struct CMC_CALLBACKS_NAME * callbacks); \
|
||||||
/* Customization of Allocation and Callbacks */ \
|
/* Collection Input and Output */ \
|
||||||
void CMC_(PFX, _customize)(struct SNAME * _heap_, \
|
bool CMC_(PFX, _insert)(struct SNAME * _heap_, V value); \
|
||||||
struct cmc_alloc_node * alloc, \
|
bool CMC_(PFX, _remove)(struct SNAME * _heap_); \
|
||||||
struct cmc_callbacks * callbacks); \
|
/* Element Access */ \
|
||||||
/* Collection Input and Output */ \
|
V CMC_(PFX, _peek)(struct SNAME * _heap_); \
|
||||||
bool CMC_(PFX, _insert)(struct SNAME * _heap_, V value); \
|
/* Collection State */ \
|
||||||
bool CMC_(PFX, _remove)(struct SNAME * _heap_); \
|
bool CMC_(PFX, _contains)(struct SNAME * _heap_, V value); \
|
||||||
/* Element Access */ \
|
bool CMC_(PFX, _empty)(struct SNAME * _heap_); \
|
||||||
V CMC_(PFX, _peek)(struct SNAME * _heap_); \
|
bool CMC_(PFX, _full)(struct SNAME * _heap_); \
|
||||||
/* Collection State */ \
|
size_t CMC_(PFX, _count)(struct SNAME * _heap_); \
|
||||||
bool CMC_(PFX, _contains)(struct SNAME * _heap_, V value); \
|
size_t CMC_(PFX, _capacity)(struct SNAME * _heap_); \
|
||||||
bool CMC_(PFX, _empty)(struct SNAME * _heap_); \
|
int CMC_(PFX, _flag)(struct SNAME * _heap_); \
|
||||||
bool CMC_(PFX, _full)(struct SNAME * _heap_); \
|
/* Collection Utility */ \
|
||||||
size_t CMC_(PFX, _count)(struct SNAME * _heap_); \
|
bool CMC_(PFX, _resize)(struct SNAME * _heap_, size_t capacity); \
|
||||||
size_t CMC_(PFX, _capacity)(struct SNAME * _heap_); \
|
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _heap_); \
|
||||||
int CMC_(PFX, _flag)(struct SNAME * _heap_); \
|
|
||||||
/* Collection Utility */ \
|
|
||||||
bool CMC_(PFX, _resize)(struct SNAME * _heap_, size_t capacity); \
|
|
||||||
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _heap_); \
|
|
||||||
bool CMC_(PFX, _equals)(struct SNAME * _heap1_, struct SNAME * _heap2_);
|
bool CMC_(PFX, _equals)(struct SNAME * _heap1_, struct SNAME * _heap2_);
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Source
|
* Source
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
#define CMC_CMC_HEAP_CORE_SOURCE_(PFX, SNAME, V) \
|
#define CMC_CMC_HEAP_CORE_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* Implementation Detail Functions */ \
|
/* Implementation Detail Functions */ \
|
||||||
static void CMC_(PFX, _impl_float_up)(struct SNAME * _heap_, \
|
static void CMC_(PFX, _impl_float_up)(struct SNAME * _heap_, size_t index); \
|
||||||
size_t index); \
|
static void CMC_(PFX, _impl_float_down)(struct SNAME * _heap_, size_t index); \
|
||||||
static void CMC_(PFX, _impl_float_down)(struct SNAME * _heap_, \
|
\
|
||||||
size_t index); \
|
struct SNAME *CMC_(PFX, _new)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val) \
|
||||||
\
|
{ \
|
||||||
struct SNAME *CMC_(PFX, _new)(size_t capacity, enum cmc_heap_order HO, \
|
return CMC_(PFX, _new_custom)(capacity, HO, f_val, NULL, NULL); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val) \
|
} \
|
||||||
{ \
|
\
|
||||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default; \
|
struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, enum cmc_heap_order HO, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||||
\
|
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||||
if (capacity < 1) \
|
{ \
|
||||||
return NULL; \
|
if (capacity < 1) \
|
||||||
\
|
return NULL; \
|
||||||
if (HO != CMC_MIN_HEAP && HO != CMC_MAX_HEAP) \
|
\
|
||||||
return NULL; \
|
if (HO != CMC_MIN_HEAP && HO != CMC_MAX_HEAP) \
|
||||||
\
|
return NULL; \
|
||||||
if (!f_val) \
|
\
|
||||||
return NULL; \
|
if (!f_val) \
|
||||||
\
|
return NULL; \
|
||||||
struct SNAME *_heap_ = alloc->malloc(sizeof(struct SNAME)); \
|
\
|
||||||
\
|
if (!alloc) \
|
||||||
if (!_heap_) \
|
alloc = &cmc_alloc_node_default; \
|
||||||
return NULL; \
|
\
|
||||||
\
|
struct SNAME *_heap_ = alloc->malloc(sizeof(struct SNAME)); \
|
||||||
_heap_->buffer = alloc->calloc(capacity, sizeof(V)); \
|
\
|
||||||
\
|
if (!_heap_) \
|
||||||
if (!_heap_->buffer) \
|
return NULL; \
|
||||||
{ \
|
\
|
||||||
alloc->free(_heap_); \
|
_heap_->buffer = alloc->calloc(capacity, sizeof(V)); \
|
||||||
return NULL; \
|
\
|
||||||
} \
|
if (!_heap_->buffer) \
|
||||||
\
|
{ \
|
||||||
_heap_->capacity = capacity; \
|
alloc->free(_heap_); \
|
||||||
_heap_->count = 0; \
|
return NULL; \
|
||||||
_heap_->HO = HO; \
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
_heap_->f_val = f_val; \
|
_heap_->capacity = capacity; \
|
||||||
_heap_->alloc = alloc; \
|
_heap_->count = 0; \
|
||||||
_heap_->callbacks = NULL; \
|
_heap_->HO = HO; \
|
||||||
\
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
return _heap_; \
|
_heap_->f_val = f_val; \
|
||||||
} \
|
_heap_->alloc = alloc; \
|
||||||
\
|
CMC_CALLBACKS_ASSIGN(_heap_, callbacks); \
|
||||||
struct SNAME *CMC_(PFX, _new_custom)( \
|
\
|
||||||
size_t capacity, enum cmc_heap_order HO, \
|
return _heap_; \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct cmc_alloc_node * alloc, \
|
} \
|
||||||
struct cmc_callbacks * callbacks) \
|
\
|
||||||
{ \
|
void CMC_(PFX, _clear)(struct SNAME * _heap_) \
|
||||||
if (capacity < 1) \
|
{ \
|
||||||
return NULL; \
|
if (_heap_->f_val->free) \
|
||||||
\
|
{ \
|
||||||
if (HO != CMC_MIN_HEAP && HO != CMC_MAX_HEAP) \
|
for (size_t i = 0; i < _heap_->count; i++) \
|
||||||
return NULL; \
|
{ \
|
||||||
\
|
_heap_->f_val->free(_heap_->buffer[i]); \
|
||||||
if (!f_val) \
|
} \
|
||||||
return NULL; \
|
} \
|
||||||
\
|
\
|
||||||
if (!alloc) \
|
memset(_heap_->buffer, 0, sizeof(V) * _heap_->capacity); \
|
||||||
alloc = &cmc_alloc_node_default; \
|
\
|
||||||
\
|
_heap_->count = 0; \
|
||||||
struct SNAME *_heap_ = alloc->malloc(sizeof(struct SNAME)); \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
\
|
} \
|
||||||
if (!_heap_) \
|
\
|
||||||
return NULL; \
|
void CMC_(PFX, _free)(struct SNAME * _heap_) \
|
||||||
\
|
{ \
|
||||||
_heap_->buffer = alloc->calloc(capacity, sizeof(V)); \
|
if (_heap_->f_val->free) \
|
||||||
\
|
{ \
|
||||||
if (!_heap_->buffer) \
|
for (size_t i = 0; i < _heap_->count; i++) \
|
||||||
{ \
|
{ \
|
||||||
alloc->free(_heap_); \
|
_heap_->f_val->free(_heap_->buffer[i]); \
|
||||||
return NULL; \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
_heap_->capacity = capacity; \
|
_heap_->alloc->free(_heap_->buffer); \
|
||||||
_heap_->count = 0; \
|
_heap_->alloc->free(_heap_); \
|
||||||
_heap_->HO = HO; \
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
_heap_->f_val = f_val; \
|
void CMC_(PFX, _customize)(struct SNAME * _heap_, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||||
_heap_->alloc = alloc; \
|
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||||
_heap_->callbacks = callbacks; \
|
{ \
|
||||||
\
|
if (!alloc) \
|
||||||
return _heap_; \
|
_heap_->alloc = &cmc_alloc_node_default; \
|
||||||
} \
|
else \
|
||||||
\
|
_heap_->alloc = alloc; \
|
||||||
void CMC_(PFX, _clear)(struct SNAME * _heap_) \
|
\
|
||||||
{ \
|
CMC_CALLBACKS_ASSIGN(_heap_, callbacks); \
|
||||||
if (_heap_->f_val->free) \
|
\
|
||||||
{ \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
for (size_t i = 0; i < _heap_->count; i++) \
|
} \
|
||||||
{ \
|
\
|
||||||
_heap_->f_val->free(_heap_->buffer[i]); \
|
bool CMC_(PFX, _insert)(struct SNAME * _heap_, V value) \
|
||||||
} \
|
{ \
|
||||||
} \
|
if (CMC_(PFX, _full)(_heap_)) \
|
||||||
\
|
{ \
|
||||||
memset(_heap_->buffer, 0, sizeof(V) * _heap_->capacity); \
|
if (!CMC_(PFX, _resize)(_heap_, _heap_->count * 2)) \
|
||||||
\
|
return false; \
|
||||||
_heap_->count = 0; \
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
} \
|
_heap_->buffer[_heap_->count++] = value; \
|
||||||
\
|
\
|
||||||
void CMC_(PFX, _free)(struct SNAME * _heap_) \
|
if (_heap_->count > 1) \
|
||||||
{ \
|
{ \
|
||||||
if (_heap_->f_val->free) \
|
CMC_(PFX, _impl_float_up)(_heap_, _heap_->count - 1); \
|
||||||
{ \
|
} \
|
||||||
for (size_t i = 0; i < _heap_->count; i++) \
|
\
|
||||||
{ \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
_heap_->f_val->free(_heap_->buffer[i]); \
|
\
|
||||||
} \
|
if (_heap_->callbacks && _heap_->callbacks->create) \
|
||||||
} \
|
_heap_->callbacks->create(); \
|
||||||
\
|
\
|
||||||
_heap_->alloc->free(_heap_->buffer); \
|
return true; \
|
||||||
_heap_->alloc->free(_heap_); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _remove)(struct SNAME * _heap_) \
|
||||||
void CMC_(PFX, _customize)(struct SNAME * _heap_, \
|
{ \
|
||||||
struct cmc_alloc_node * alloc, \
|
if (CMC_(PFX, _empty)(_heap_)) \
|
||||||
struct cmc_callbacks * callbacks) \
|
{ \
|
||||||
{ \
|
_heap_->flag = CMC_FLAG_EMPTY; \
|
||||||
if (!alloc) \
|
return false; \
|
||||||
_heap_->alloc = &cmc_alloc_node_default; \
|
} \
|
||||||
else \
|
\
|
||||||
_heap_->alloc = alloc; \
|
_heap_->buffer[0] = _heap_->buffer[_heap_->count - 1]; \
|
||||||
\
|
_heap_->buffer[_heap_->count - 1] = (V){ 0 }; \
|
||||||
_heap_->callbacks = callbacks; \
|
\
|
||||||
\
|
_heap_->count--; \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
} \
|
CMC_(PFX, _impl_float_down)(_heap_, 0); \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _insert)(struct SNAME * _heap_, V value) \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
{ \
|
\
|
||||||
if (CMC_(PFX, _full)(_heap_)) \
|
if (_heap_->callbacks && _heap_->callbacks->delete) \
|
||||||
{ \
|
_heap_->callbacks->delete (); \
|
||||||
if (!CMC_(PFX, _resize)(_heap_, _heap_->count * 2)) \
|
\
|
||||||
return false; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
_heap_->buffer[_heap_->count++] = value; \
|
V CMC_(PFX, _peek)(struct SNAME * _heap_) \
|
||||||
\
|
{ \
|
||||||
if (_heap_->count > 1) \
|
if (CMC_(PFX, _empty)(_heap_)) \
|
||||||
{ \
|
{ \
|
||||||
CMC_(PFX, _impl_float_up)(_heap_, _heap_->count - 1); \
|
_heap_->flag = CMC_FLAG_EMPTY; \
|
||||||
} \
|
return (V){ 0 }; \
|
||||||
\
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
\
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
if (_heap_->callbacks && _heap_->callbacks->create) \
|
\
|
||||||
_heap_->callbacks->create(); \
|
if (_heap_->callbacks && _heap_->callbacks->read) \
|
||||||
\
|
_heap_->callbacks->read(); \
|
||||||
return true; \
|
\
|
||||||
} \
|
return _heap_->buffer[0]; \
|
||||||
\
|
} \
|
||||||
bool CMC_(PFX, _remove)(struct SNAME * _heap_) \
|
\
|
||||||
{ \
|
bool CMC_(PFX, _contains)(struct SNAME * _heap_, V value) \
|
||||||
if (CMC_(PFX, _empty)(_heap_)) \
|
{ \
|
||||||
{ \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
_heap_->flag = CMC_FLAG_EMPTY; \
|
\
|
||||||
return false; \
|
bool result = false; \
|
||||||
} \
|
\
|
||||||
\
|
for (size_t i = 0; i < _heap_->count; i++) \
|
||||||
_heap_->buffer[0] = _heap_->buffer[_heap_->count - 1]; \
|
{ \
|
||||||
_heap_->buffer[_heap_->count - 1] = (V){ 0 }; \
|
if (_heap_->f_val->cmp(_heap_->buffer[i], value) == 0) \
|
||||||
\
|
{ \
|
||||||
_heap_->count--; \
|
result = true; \
|
||||||
\
|
break; \
|
||||||
CMC_(PFX, _impl_float_down)(_heap_, 0); \
|
} \
|
||||||
\
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
\
|
if (_heap_->callbacks && _heap_->callbacks->read) \
|
||||||
if (_heap_->callbacks && _heap_->callbacks->delete) \
|
_heap_->callbacks->read(); \
|
||||||
_heap_->callbacks->delete (); \
|
\
|
||||||
\
|
return result; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _empty)(struct SNAME * _heap_) \
|
||||||
V CMC_(PFX, _peek)(struct SNAME * _heap_) \
|
{ \
|
||||||
{ \
|
return _heap_->count == 0; \
|
||||||
if (CMC_(PFX, _empty)(_heap_)) \
|
} \
|
||||||
{ \
|
\
|
||||||
_heap_->flag = CMC_FLAG_EMPTY; \
|
bool CMC_(PFX, _full)(struct SNAME * _heap_) \
|
||||||
return (V){ 0 }; \
|
{ \
|
||||||
} \
|
return _heap_->count >= _heap_->capacity; \
|
||||||
\
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
\
|
size_t CMC_(PFX, _count)(struct SNAME * _heap_) \
|
||||||
if (_heap_->callbacks && _heap_->callbacks->read) \
|
{ \
|
||||||
_heap_->callbacks->read(); \
|
return _heap_->count; \
|
||||||
\
|
} \
|
||||||
return _heap_->buffer[0]; \
|
\
|
||||||
} \
|
size_t CMC_(PFX, _capacity)(struct SNAME * _heap_) \
|
||||||
\
|
{ \
|
||||||
bool CMC_(PFX, _contains)(struct SNAME * _heap_, V value) \
|
return _heap_->capacity; \
|
||||||
{ \
|
} \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
\
|
||||||
\
|
int CMC_(PFX, _flag)(struct SNAME * _heap_) \
|
||||||
bool result = false; \
|
{ \
|
||||||
\
|
return _heap_->flag; \
|
||||||
for (size_t i = 0; i < _heap_->count; i++) \
|
} \
|
||||||
{ \
|
\
|
||||||
if (_heap_->f_val->cmp(_heap_->buffer[i], value) == 0) \
|
bool CMC_(PFX, _resize)(struct SNAME * _heap_, size_t capacity) \
|
||||||
{ \
|
{ \
|
||||||
result = true; \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
break; \
|
\
|
||||||
} \
|
if (_heap_->capacity == capacity) \
|
||||||
} \
|
goto success; \
|
||||||
\
|
\
|
||||||
if (_heap_->callbacks && _heap_->callbacks->read) \
|
if (capacity < _heap_->count) \
|
||||||
_heap_->callbacks->read(); \
|
{ \
|
||||||
\
|
_heap_->flag = CMC_FLAG_INVALID; \
|
||||||
return result; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _empty)(struct SNAME * _heap_) \
|
V *new_buffer = _heap_->alloc->realloc(_heap_->buffer, sizeof(V) * capacity); \
|
||||||
{ \
|
\
|
||||||
return _heap_->count == 0; \
|
if (!new_buffer) \
|
||||||
} \
|
{ \
|
||||||
\
|
_heap_->flag = CMC_FLAG_ALLOC; \
|
||||||
bool CMC_(PFX, _full)(struct SNAME * _heap_) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
return _heap_->count >= _heap_->capacity; \
|
\
|
||||||
} \
|
/* TODO zero out new slots */ \
|
||||||
\
|
\
|
||||||
size_t CMC_(PFX, _count)(struct SNAME * _heap_) \
|
_heap_->buffer = new_buffer; \
|
||||||
{ \
|
_heap_->capacity = capacity; \
|
||||||
return _heap_->count; \
|
\
|
||||||
} \
|
success: \
|
||||||
\
|
\
|
||||||
size_t CMC_(PFX, _capacity)(struct SNAME * _heap_) \
|
if (_heap_->callbacks && _heap_->callbacks->resize) \
|
||||||
{ \
|
_heap_->callbacks->resize(); \
|
||||||
return _heap_->capacity; \
|
\
|
||||||
} \
|
return true; \
|
||||||
\
|
} \
|
||||||
int CMC_(PFX, _flag)(struct SNAME * _heap_) \
|
\
|
||||||
{ \
|
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _heap_) \
|
||||||
return _heap_->flag; \
|
{ \
|
||||||
} \
|
struct SNAME *result = \
|
||||||
\
|
CMC_(PFX, _new_custom)(_heap_->capacity, _heap_->HO, _heap_->f_val, _heap_->alloc, NULL); \
|
||||||
bool CMC_(PFX, _resize)(struct SNAME * _heap_, size_t capacity) \
|
\
|
||||||
{ \
|
if (!result) \
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
{ \
|
||||||
\
|
_heap_->flag = CMC_FLAG_ERROR; \
|
||||||
if (_heap_->capacity == capacity) \
|
return NULL; \
|
||||||
goto success; \
|
} \
|
||||||
\
|
\
|
||||||
if (capacity < _heap_->count) \
|
CMC_CALLBACKS_ASSIGN(result, _heap_->callbacks); \
|
||||||
{ \
|
\
|
||||||
_heap_->flag = CMC_FLAG_INVALID; \
|
if (_heap_->f_val->cpy) \
|
||||||
return false; \
|
{ \
|
||||||
} \
|
for (size_t i = 0; i < _heap_->count; i++) \
|
||||||
\
|
result->buffer[i] = _heap_->f_val->cpy(_heap_->buffer[i]); \
|
||||||
V *new_buffer = \
|
} \
|
||||||
_heap_->alloc->realloc(_heap_->buffer, sizeof(V) * capacity); \
|
else \
|
||||||
\
|
|
||||||
if (!new_buffer) \
|
|
||||||
{ \
|
|
||||||
_heap_->flag = CMC_FLAG_ALLOC; \
|
|
||||||
return false; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* TODO zero out new slots */ \
|
|
||||||
\
|
|
||||||
_heap_->buffer = new_buffer; \
|
|
||||||
_heap_->capacity = capacity; \
|
|
||||||
\
|
|
||||||
success: \
|
|
||||||
\
|
|
||||||
if (_heap_->callbacks && _heap_->callbacks->resize) \
|
|
||||||
_heap_->callbacks->resize(); \
|
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
struct SNAME *CMC_(PFX, _copy_of)(struct SNAME * _heap_) \
|
|
||||||
{ \
|
|
||||||
struct SNAME *result = CMC_(PFX, _new_custom)( \
|
|
||||||
_heap_->capacity, _heap_->HO, _heap_->f_val, _heap_->alloc, \
|
|
||||||
_heap_->callbacks); \
|
|
||||||
\
|
|
||||||
if (!result) \
|
|
||||||
{ \
|
|
||||||
_heap_->flag = CMC_FLAG_ERROR; \
|
|
||||||
return NULL; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
if (_heap_->f_val->cpy) \
|
|
||||||
{ \
|
|
||||||
for (size_t i = 0; i < _heap_->count; i++) \
|
|
||||||
result->buffer[i] = _heap_->f_val->cpy(_heap_->buffer[i]); \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
memcpy(result->buffer, _heap_->buffer, sizeof(V) * _heap_->count); \
|
memcpy(result->buffer, _heap_->buffer, sizeof(V) * _heap_->count); \
|
||||||
\
|
\
|
||||||
result->count = _heap_->count; \
|
result->count = _heap_->count; \
|
||||||
\
|
\
|
||||||
_heap_->flag = CMC_FLAG_OK; \
|
_heap_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
return result; \
|
return result; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _equals)(struct SNAME * _heap1_, struct SNAME * _heap2_) \
|
bool CMC_(PFX, _equals)(struct SNAME * _heap1_, struct SNAME * _heap2_) \
|
||||||
{ \
|
{ \
|
||||||
_heap1_->flag = CMC_FLAG_OK; \
|
_heap1_->flag = CMC_FLAG_OK; \
|
||||||
_heap2_->flag = CMC_FLAG_OK; \
|
_heap2_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
if (_heap1_->count != _heap2_->count) \
|
if (_heap1_->count != _heap2_->count) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
for (size_t i = 0; i < _heap1_->count; i++) \
|
for (size_t i = 0; i < _heap1_->count; i++) \
|
||||||
{ \
|
{ \
|
||||||
if (_heap1_->f_val->cmp(_heap1_->buffer[i], _heap2_->buffer[i]) != \
|
if (_heap1_->f_val->cmp(_heap1_->buffer[i], _heap2_->buffer[i]) != 0) \
|
||||||
0) \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
|
||||||
static void CMC_(PFX, _impl_float_up)(struct SNAME * _heap_, size_t index) \
|
static void CMC_(PFX, _impl_float_up)(struct SNAME * _heap_, size_t index) \
|
||||||
{ \
|
{ \
|
||||||
/* Current index */ \
|
/* Current index */ \
|
||||||
size_t C = index; \
|
size_t C = index; \
|
||||||
V child = _heap_->buffer[C]; \
|
V child = _heap_->buffer[C]; \
|
||||||
V parent = _heap_->buffer[(index - 1) / 2]; \
|
V parent = _heap_->buffer[(index - 1) / 2]; \
|
||||||
\
|
\
|
||||||
int mod = _heap_->HO; \
|
int mod = _heap_->HO; \
|
||||||
\
|
\
|
||||||
while (C > 0 && _heap_->f_val->cmp(child, parent) * mod > 0) \
|
while (C > 0 && _heap_->f_val->cmp(child, parent) * mod > 0) \
|
||||||
{ \
|
{ \
|
||||||
/* Swap between C (current element) and its parent */ \
|
/* Swap between C (current element) and its parent */ \
|
||||||
V tmp = _heap_->buffer[C]; \
|
V tmp = _heap_->buffer[C]; \
|
||||||
_heap_->buffer[C] = _heap_->buffer[(C - 1) / 2]; \
|
_heap_->buffer[C] = _heap_->buffer[(C - 1) / 2]; \
|
||||||
_heap_->buffer[(C - 1) / 2] = tmp; \
|
_heap_->buffer[(C - 1) / 2] = tmp; \
|
||||||
\
|
\
|
||||||
/* Go to parent */ \
|
/* Go to parent */ \
|
||||||
C = (C - 1) / 2; \
|
C = (C - 1) / 2; \
|
||||||
\
|
\
|
||||||
/* Prevent the two lines below from accessing a negative index */ \
|
/* Prevent the two lines below from accessing a negative index */ \
|
||||||
if (C == 0) \
|
if (C == 0) \
|
||||||
break; \
|
break; \
|
||||||
\
|
\
|
||||||
child = _heap_->buffer[C]; \
|
child = _heap_->buffer[C]; \
|
||||||
parent = _heap_->buffer[(C - 1) / 2]; \
|
parent = _heap_->buffer[(C - 1) / 2]; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static void CMC_(PFX, _impl_float_down)(struct SNAME * _heap_, \
|
static void CMC_(PFX, _impl_float_down)(struct SNAME * _heap_, size_t index) \
|
||||||
size_t index) \
|
{ \
|
||||||
{ \
|
int mod = _heap_->HO; \
|
||||||
int mod = _heap_->HO; \
|
\
|
||||||
\
|
while (index < _heap_->count) \
|
||||||
while (index < _heap_->count) \
|
{ \
|
||||||
{ \
|
size_t L = 2 * index + 1; \
|
||||||
size_t L = 2 * index + 1; \
|
size_t R = 2 * index + 2; \
|
||||||
size_t R = 2 * index + 2; \
|
size_t C = index; \
|
||||||
size_t C = index; \
|
\
|
||||||
\
|
/* Determine if we swap with the left or right element */ \
|
||||||
/* Determine if we swap with the left or right element */ \
|
if (L < _heap_->count && _heap_->f_val->cmp(_heap_->buffer[L], _heap_->buffer[C]) * mod > 0) \
|
||||||
if (L < _heap_->count && \
|
{ \
|
||||||
_heap_->f_val->cmp(_heap_->buffer[L], _heap_->buffer[C]) * \
|
C = L; \
|
||||||
mod > \
|
} \
|
||||||
0) \
|
\
|
||||||
{ \
|
if (R < _heap_->count && _heap_->f_val->cmp(_heap_->buffer[R], _heap_->buffer[C]) * mod > 0) \
|
||||||
C = L; \
|
{ \
|
||||||
} \
|
C = R; \
|
||||||
\
|
} \
|
||||||
if (R < _heap_->count && \
|
\
|
||||||
_heap_->f_val->cmp(_heap_->buffer[R], _heap_->buffer[C]) * \
|
|
||||||
mod > \
|
|
||||||
0) \
|
|
||||||
{ \
|
|
||||||
C = R; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* Swap only if either left or right was picked, otherwise done */ \
|
/* Swap only if either left or right was picked, otherwise done */ \
|
||||||
if (C != index) \
|
if (C != index) \
|
||||||
{ \
|
{ \
|
||||||
V tmp = _heap_->buffer[index]; \
|
V tmp = _heap_->buffer[index]; \
|
||||||
_heap_->buffer[index] = _heap_->buffer[C]; \
|
_heap_->buffer[index] = _heap_->buffer[C]; \
|
||||||
_heap_->buffer[C] = tmp; \
|
_heap_->buffer[C] = tmp; \
|
||||||
\
|
\
|
||||||
index = C; \
|
index = C; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_CMC_HEAP_H */
|
#endif /* CMC_CMC_HEAP_H */
|
||||||
+828
-881
File diff suppressed because it is too large.
Load diff
+550
-581
File diff suppressed because it is too large.
Load diff
+531
-572
File diff suppressed because it is too large.
Load diff
+661
-713
File diff suppressed because it is too large.
Load diff
+781
-839
File diff suppressed because it is too large.
Load diff
+578
-624
File diff suppressed because it is too large.
Load diff
+1181
-1240
File diff suppressed because it is too large.
Load diff
+1259
-1322
File diff suppressed because it is too large.
Load diff
+7
-1
@@ -11,6 +11,12 @@
|
|||||||
#ifndef CMC_COR_ALLOC_H
|
#ifndef CMC_COR_ALLOC_H
|
||||||
#define CMC_COR_ALLOC_H
|
#define CMC_COR_ALLOC_H
|
||||||
|
|
||||||
|
#ifdef CMC_CAMEL_CASE
|
||||||
|
#define CMC_ALLOC_NODE_NAME CMCAllocNode
|
||||||
|
#else
|
||||||
|
#define CMC_ALLOC_NODE_NAME cmc_alloc_node
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +26,7 @@
|
|||||||
* functions. The cmc_alloc_node_default is the default heap allocator provided
|
* functions. The cmc_alloc_node_default is the default heap allocator provided
|
||||||
* by the standard library.
|
* by the standard library.
|
||||||
*/
|
*/
|
||||||
static struct cmc_alloc_node
|
static struct CMC_ALLOC_NODE_NAME
|
||||||
{
|
{
|
||||||
void *(*malloc)(size_t);
|
void *(*malloc)(size_t);
|
||||||
void *(*calloc)(size_t, size_t);
|
void *(*calloc)(size_t, size_t);
|
||||||
|
|||||||
+28
-4
@@ -8,8 +8,32 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CMC_COR_CALLBACK_H
|
#ifndef CMC_COR_CALLBACKS_H
|
||||||
#define CMC_COR_CALLBACK_H
|
#define CMC_COR_CALLBACKS_H
|
||||||
|
|
||||||
|
#ifdef CMC_CAMEL_CASE
|
||||||
|
#define CMC_CALLBACKS_NAME CMCCallbacks
|
||||||
|
#else
|
||||||
|
#define CMC_CALLBACKS_NAME cmc_callbacks
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CMC_NO_CALLBACKS
|
||||||
|
|
||||||
|
#define CMC_CALLBACKS_DECL
|
||||||
|
#define CMC_CALLBACKS_GET(ds) NULL /* Placeholder for STR */
|
||||||
|
#define CMC_CALLBACKS_ASSIGN(ds, cb)
|
||||||
|
#define CMC_CALLBACKS_CALL(ds, cb)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define CMC_CALLBACKS_DECL struct CMC_CALLBACKS_NAME *callbacks
|
||||||
|
#define CMC_CALLBACKS_GET(ds) (ds)->callbacks
|
||||||
|
#define CMC_CALLBACKS_ASSIGN(ds, cb) CMC_CALLBACKS_GET(ds) = cb
|
||||||
|
#define CMC_CALLBACKS_CALL(ds, cb) \
|
||||||
|
if (CMC_CALLBACKS_GET(ds) && CMC_CALLBACKS_GET(ds)->cb) \
|
||||||
|
CMC_CALLBACKS_GET(ds)->cb();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct cmc_callbacks
|
* struct cmc_callbacks
|
||||||
@@ -21,7 +45,7 @@
|
|||||||
* - delete : an element was successfully removed from the collection
|
* - delete : an element was successfully removed from the collection
|
||||||
* - resize : the collection was full and successfully resized
|
* - resize : the collection was full and successfully resized
|
||||||
*/
|
*/
|
||||||
struct cmc_callbacks
|
struct CMC_CALLBACKS_NAME
|
||||||
{
|
{
|
||||||
void (*create)(void);
|
void (*create)(void);
|
||||||
void (*read)(void);
|
void (*read)(void);
|
||||||
@@ -30,4 +54,4 @@ struct cmc_callbacks
|
|||||||
void (*resize)(void);
|
void (*resize)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CMC_COR_CALLBACK_H */
|
#endif /* CMC_COR_CALLBACKS_H */
|
||||||
+2
-4
@@ -37,9 +37,7 @@ enum cmc_flags
|
|||||||
*
|
*
|
||||||
* Maps the error codes to their character representation.
|
* Maps the error codes to their character representation.
|
||||||
*/
|
*/
|
||||||
const char *cmc_flags_to_str[10] = { "OK", "ALLOC", "EMPTY",
|
const char *cmc_flags_to_str[10] = { "OK", "ALLOC", "EMPTY", "NOT_FOUND", "INVALID",
|
||||||
"NOT_FOUND", "INVALID", "RANGE",
|
"RANGE", "DUPLICATE", "ERROR", "THREAD", "MUTEX" };
|
||||||
"DUPLICATE", "ERROR", "THREAD",
|
|
||||||
"MUTEX" };
|
|
||||||
|
|
||||||
#endif /* CMC_COR_FLAGS_H */
|
#endif /* CMC_COR_FLAGS_H */
|
||||||
+353
-374
@@ -24,422 +24,401 @@
|
|||||||
* The part 'INIT' gives a new way of initializing a collection. The collection
|
* The part 'INIT' gives a new way of initializing a collection. The collection
|
||||||
* struct is not heap allocated, only its internal structure (nodes, buffers).
|
* struct is not heap allocated, only its internal structure (nodes, buffers).
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_DEQUE_INIT(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_INIT(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_INIT_HEADER(PARAMS) \
|
CMC_EXT_CMC_DEQUE_INIT_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_INIT_SOURCE(PARAMS)
|
CMC_EXT_CMC_DEQUE_INIT_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_INIT_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_INIT_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_INIT_HEADER_( \
|
CMC_EXT_CMC_DEQUE_INIT_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_INIT_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_INIT_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_INIT_SOURCE_( \
|
CMC_EXT_CMC_DEQUE_INIT_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_INIT_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_DEQUE_INIT_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
struct SNAME CMC_(PFX, _init)(size_t capacity, \
|
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val); \
|
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||||
struct SNAME CMC_(PFX, _init_custom)( \
|
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks); \
|
||||||
size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
|
||||||
struct cmc_alloc_node * alloc, struct cmc_callbacks * callbacks); \
|
|
||||||
void CMC_(PFX, _release)(struct SNAME _deque_);
|
void CMC_(PFX, _release)(struct SNAME _deque_);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_INIT_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_DEQUE_INIT_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
struct SNAME CMC_(PFX, _init)(size_t capacity, \
|
struct SNAME CMC_(PFX, _init)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val) \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val) \
|
{ \
|
||||||
{ \
|
return CMC_(PFX, _init_custom)(capacity, f_val, NULL, NULL); \
|
||||||
return CMC_(PFX, _init_custom)(capacity, f_val, NULL, NULL); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
||||||
struct SNAME CMC_(PFX, _init_custom)( \
|
struct CMC_ALLOC_NODE_NAME * alloc, struct CMC_CALLBACKS_NAME * callbacks) \
|
||||||
size_t capacity, struct CMC_DEF_FVAL(SNAME) * f_val, \
|
{ \
|
||||||
struct cmc_alloc_node * alloc, struct cmc_callbacks * callbacks) \
|
struct SNAME _deque_ = { 0 }; \
|
||||||
{ \
|
\
|
||||||
struct SNAME _deque_ = { 0 }; \
|
if (capacity < 1) \
|
||||||
\
|
return _deque_; \
|
||||||
if (capacity < 1) \
|
\
|
||||||
return _deque_; \
|
if (!f_val) \
|
||||||
\
|
return _deque_; \
|
||||||
if (!f_val) \
|
\
|
||||||
return _deque_; \
|
if (!alloc) \
|
||||||
\
|
alloc = &cmc_alloc_node_default; \
|
||||||
if (!alloc) \
|
\
|
||||||
alloc = &cmc_alloc_node_default; \
|
_deque_.buffer = alloc->calloc(capacity, sizeof(V)); \
|
||||||
\
|
\
|
||||||
_deque_.buffer = alloc->calloc(capacity, sizeof(V)); \
|
if (!_deque_.buffer) \
|
||||||
\
|
return _deque_; \
|
||||||
if (!_deque_.buffer) \
|
\
|
||||||
return _deque_; \
|
_deque_.capacity = capacity; \
|
||||||
\
|
_deque_.count = 0; \
|
||||||
_deque_.capacity = capacity; \
|
_deque_.front = 0; \
|
||||||
_deque_.count = 0; \
|
_deque_.back = 0; \
|
||||||
_deque_.front = 0; \
|
_deque_.flag = CMC_FLAG_OK; \
|
||||||
_deque_.back = 0; \
|
_deque_.f_val = f_val; \
|
||||||
_deque_.flag = CMC_FLAG_OK; \
|
_deque_.alloc = alloc; \
|
||||||
_deque_.f_val = f_val; \
|
CMC_CALLBACKS_ASSIGN(&_deque_, callbacks); \
|
||||||
_deque_.alloc = alloc; \
|
\
|
||||||
_deque_.callbacks = callbacks; \
|
return _deque_; \
|
||||||
\
|
} \
|
||||||
return _deque_; \
|
\
|
||||||
} \
|
void CMC_(PFX, _release)(struct SNAME _deque_) \
|
||||||
\
|
{ \
|
||||||
void CMC_(PFX, _release)(struct SNAME _deque_) \
|
if (_deque_.f_val->free) \
|
||||||
{ \
|
{ \
|
||||||
if (_deque_.f_val->free) \
|
|
||||||
{ \
|
|
||||||
for (size_t i = _deque_.front, j = 0; j < _deque_.count; j++) \
|
for (size_t i = _deque_.front, j = 0; j < _deque_.count; j++) \
|
||||||
{ \
|
{ \
|
||||||
_deque_.f_val->free(_deque_.buffer[i]); \
|
_deque_.f_val->free(_deque_.buffer[i]); \
|
||||||
\
|
\
|
||||||
i = (i + 1) % _deque_.capacity; \
|
i = (i + 1) % _deque_.capacity; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
_deque_.alloc->free(_deque_.buffer); \
|
_deque_.alloc->free(_deque_.buffer); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ITER
|
* ITER
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_DEQUE_ITER(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_ITER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_ITER_HEADER(PARAMS) \
|
CMC_EXT_CMC_DEQUE_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_ITER_SOURCE(PARAMS)
|
CMC_EXT_CMC_DEQUE_ITER_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_ITER_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_ITER_HEADER_( \
|
CMC_EXT_CMC_DEQUE_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_ITER_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_ITER_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_ITER_SOURCE_( \
|
CMC_EXT_CMC_DEQUE_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_ITER_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_DEQUE_ITER_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* Deque Iterator */ \
|
/* Deque Iterator */ \
|
||||||
struct CMC_DEF_ITER(SNAME) \
|
struct CMC_DEF_ITER(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Target deque */ \
|
/* Target deque */ \
|
||||||
struct SNAME *target; \
|
struct SNAME *target; \
|
||||||
\
|
\
|
||||||
/* Cursor's position (index) */ \
|
/* Cursor's position (index) */ \
|
||||||
size_t cursor; \
|
size_t cursor; \
|
||||||
\
|
\
|
||||||
/* Keeps track of relative index to the iteration of elements */ \
|
/* Keeps track of relative index to the iteration of elements */ \
|
||||||
size_t index; \
|
size_t index; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the start of the iteration */ \
|
/* If the iterator has reached the start of the iteration */ \
|
||||||
bool start; \
|
bool start; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the end of the iteration */ \
|
/* If the iterator has reached the end of the iteration */ \
|
||||||
bool end; \
|
bool end; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Iterator Initialization */ \
|
/* Iterator Initialization */ \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
||||||
/* Iterator State */ \
|
/* Iterator State */ \
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Movement */ \
|
/* Iterator Movement */ \
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
size_t steps); \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \
|
||||||
size_t steps); \
|
/* Iterator Access */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
size_t index); \
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Access */ \
|
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_ITER_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_DEQUE_ITER_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = target->front; \
|
iter.cursor = target->front; \
|
||||||
iter.index = 0; \
|
iter.index = 0; \
|
||||||
iter.start = true; \
|
iter.start = true; \
|
||||||
iter.end = CMC_(PFX, _empty)(target); \
|
iter.end = CMC_(PFX, _empty)(target); \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
{ \
|
{ \
|
||||||
if (iter.target->back == 0) \
|
if (iter.target->back == 0) \
|
||||||
iter.cursor = iter.target->capacity - 1; \
|
iter.cursor = iter.target->capacity - 1; \
|
||||||
else \
|
else \
|
||||||
iter.cursor = iter.target->back - 1; \
|
iter.cursor = iter.target->back - 1; \
|
||||||
\
|
\
|
||||||
iter.index = iter.target->count - 1; \
|
iter.index = iter.target->count - 1; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.index = 0; \
|
iter.index = 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter.start = CMC_(PFX, _empty)(target); \
|
iter.start = CMC_(PFX, _empty)(target); \
|
||||||
iter.end = true; \
|
iter.end = true; \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->target->front; \
|
iter->cursor = iter->target->front; \
|
||||||
iter->index = 0; \
|
iter->index = 0; \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
iter->end = false; \
|
iter->end = false; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->target->back == 0) \
|
if (iter->target->back == 0) \
|
||||||
iter->cursor = iter->target->capacity - 1; \
|
iter->cursor = iter->target->capacity - 1; \
|
||||||
else \
|
else \
|
||||||
iter->cursor = iter->target->back - 1; \
|
iter->cursor = iter->target->back - 1; \
|
||||||
\
|
\
|
||||||
iter->index = iter->target->count - 1; \
|
iter->index = iter->target->count - 1; \
|
||||||
\
|
\
|
||||||
iter->start = false; \
|
iter->start = false; \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->end) \
|
if (iter->end) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->index + 1 == iter->target->count) \
|
if (iter->index + 1 == iter->target->count) \
|
||||||
{ \
|
{ \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor = (iter->cursor + 1) % (iter->target->capacity); \
|
iter->cursor = (iter->cursor + 1) % (iter->target->capacity); \
|
||||||
iter->index++; \
|
iter->index++; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->start) \
|
if (iter->start) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->index == 0) \
|
if (iter->index == 0) \
|
||||||
{ \
|
{ \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 \
|
iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1; \
|
||||||
: iter->cursor - 1; \
|
iter->index--; \
|
||||||
iter->index--; \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
/* Returns true only if the iterator moved */ \
|
||||||
/* Returns true only if the iterator moved */ \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
{ \
|
||||||
size_t steps) \
|
if (iter->end) \
|
||||||
{ \
|
return false; \
|
||||||
if (iter->end) \
|
\
|
||||||
return false; \
|
if (iter->index + 1 == iter->target->count) \
|
||||||
\
|
{ \
|
||||||
if (iter->index + 1 == iter->target->count) \
|
iter->end = true; \
|
||||||
{ \
|
return false; \
|
||||||
iter->end = true; \
|
} \
|
||||||
return false; \
|
\
|
||||||
} \
|
if (steps == 0 || iter->index + steps >= iter->target->count) \
|
||||||
\
|
return false; \
|
||||||
if (steps == 0 || iter->index + steps >= iter->target->count) \
|
\
|
||||||
return false; \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->index += steps; \
|
||||||
\
|
iter->cursor = (iter->cursor + steps) % iter->target->capacity; \
|
||||||
iter->index += steps; \
|
\
|
||||||
iter->cursor = (iter->cursor + steps) % iter->target->capacity; \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
/* Returns true only if the iterator moved */ \
|
||||||
\
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
/* Returns true only if the iterator moved */ \
|
{ \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
if (iter->start) \
|
||||||
size_t steps) \
|
return false; \
|
||||||
{ \
|
\
|
||||||
if (iter->start) \
|
if (iter->index == 0) \
|
||||||
return false; \
|
{ \
|
||||||
\
|
iter->start = true; \
|
||||||
if (iter->index == 0) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
iter->start = true; \
|
\
|
||||||
return false; \
|
if (steps == 0 || iter->index < steps) \
|
||||||
} \
|
return false; \
|
||||||
\
|
\
|
||||||
if (steps == 0 || iter->index < steps) \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
return false; \
|
\
|
||||||
\
|
iter->index -= steps; \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
\
|
||||||
\
|
/* Prevent underflow */ \
|
||||||
iter->index -= steps; \
|
if (iter->cursor < steps) \
|
||||||
\
|
iter->cursor += iter->target->capacity; \
|
||||||
/* Prevent underflow */ \
|
\
|
||||||
if (iter->cursor < steps) \
|
iter->cursor -= steps; \
|
||||||
iter->cursor += iter->target->capacity; \
|
\
|
||||||
\
|
return true; \
|
||||||
iter->cursor -= steps; \
|
} \
|
||||||
\
|
\
|
||||||
return true; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* Returns true only if the iterator was able to be positioned at the */ \
|
/* Returns true only if the iterator was able to be positioned at the */ \
|
||||||
/* given index */ \
|
/* given index */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \
|
||||||
size_t index) \
|
{ \
|
||||||
{ \
|
if (index >= iter->target->count) \
|
||||||
if (index >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->index > index) \
|
||||||
if (iter->index > index) \
|
return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \
|
||||||
return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \
|
else if (iter->index < index) \
|
||||||
else if (iter->index < index) \
|
return CMC_(PFX, _iter_advance)(iter, index - iter->index); \
|
||||||
return CMC_(PFX, _iter_advance)(iter, index - iter->index); \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return (V){ 0 }; \
|
||||||
return (V){ 0 }; \
|
\
|
||||||
\
|
return iter->target->buffer[iter->cursor]; \
|
||||||
return iter->target->buffer[iter->cursor]; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return NULL; \
|
||||||
return NULL; \
|
\
|
||||||
\
|
return &(iter->target->buffer[iter->cursor]); \
|
||||||
return &(iter->target->buffer[iter->cursor]); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
return iter->index; \
|
||||||
return iter->index; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STR
|
* STR
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_DEQUE_STR(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_STR(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_STR_HEADER(PARAMS) \
|
CMC_EXT_CMC_DEQUE_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_STR_SOURCE(PARAMS)
|
CMC_EXT_CMC_DEQUE_STR_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_STR_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_STR_HEADER_( \
|
CMC_EXT_CMC_DEQUE_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_STR_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_DEQUE_STR_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_DEQUE_STR_SOURCE_( \
|
CMC_EXT_CMC_DEQUE_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_STR_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_DEQUE_STR_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _deque_, FILE * fptr); \
|
bool CMC_(PFX, _to_string)(struct SNAME * _deque_, FILE * fptr); \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _deque_, FILE * fptr, \
|
bool CMC_(PFX, _print)(struct SNAME * _deque_, FILE * fptr, const char *start, const char *separator, \
|
||||||
const char *start, const char *separator, \
|
|
||||||
const char *end);
|
const char *end);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_DEQUE_STR_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_DEQUE_STR_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _deque_, FILE * fptr) \
|
bool CMC_(PFX, _to_string)(struct SNAME * _deque_, FILE * fptr) \
|
||||||
{ \
|
{ \
|
||||||
struct SNAME *d_ = _deque_; \
|
struct SNAME *d_ = _deque_; \
|
||||||
\
|
\
|
||||||
return 0 <= fprintf(fptr, \
|
return 0 <= fprintf(fptr, \
|
||||||
"struct %s<%s> " \
|
"struct %s<%s> " \
|
||||||
"at %p { " \
|
"at %p { " \
|
||||||
"buffer:%p, " \
|
"buffer:%p, " \
|
||||||
"capacity:%" PRIuMAX ", " \
|
"capacity:%" PRIuMAX ", " \
|
||||||
"count:%" PRIuMAX ", " \
|
"count:%" PRIuMAX ", " \
|
||||||
"front:%" PRIuMAX ", " \
|
"front:%" PRIuMAX ", " \
|
||||||
"back:%" PRIuMAX ", " \
|
"back:%" PRIuMAX ", " \
|
||||||
"flag:%d, " \
|
"flag:%d, " \
|
||||||
"f_val:%p, " \
|
"f_val:%p, " \
|
||||||
"alloc:%p, " \
|
"alloc:%p, " \
|
||||||
"callbacks:%p }", \
|
"callbacks:%p }", \
|
||||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), d_, \
|
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), d_, d_->buffer, d_->capacity, d_->count, \
|
||||||
d_->buffer, d_->capacity, d_->count, d_->front, \
|
d_->front, d_->back, d_->flag, d_->f_val, d_->alloc, CMC_CALLBACKS_GET(d_)); \
|
||||||
d_->back, d_->flag, d_->f_val, d_->alloc, \
|
} \
|
||||||
d_->callbacks); \
|
\
|
||||||
} \
|
bool CMC_(PFX, _print)(struct SNAME * _deque_, FILE * fptr, const char *start, const char *separator, \
|
||||||
\
|
const char *end) \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _deque_, FILE * fptr, \
|
{ \
|
||||||
const char *start, const char *separator, \
|
fprintf(fptr, "%s", start); \
|
||||||
const char *end) \
|
\
|
||||||
{ \
|
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
||||||
fprintf(fptr, "%s", start); \
|
{ \
|
||||||
\
|
if (!_deque_->f_val->str(fptr, _deque_->buffer[i])) \
|
||||||
for (size_t i = _deque_->front, j = 0; j < _deque_->count; j++) \
|
return false; \
|
||||||
{ \
|
\
|
||||||
if (!_deque_->f_val->str(fptr, _deque_->buffer[i])) \
|
i = (i + 1) % _deque_->capacity; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (j + 1 < _deque_->count) \
|
||||||
i = (i + 1) % _deque_->capacity; \
|
fprintf(fptr, "%s", separator); \
|
||||||
\
|
} \
|
||||||
if (j + 1 < _deque_->count) \
|
\
|
||||||
fprintf(fptr, "%s", separator); \
|
fprintf(fptr, "%s", end); \
|
||||||
} \
|
\
|
||||||
\
|
return true; \
|
||||||
fprintf(fptr, "%s", end); \
|
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_EXT_CMC_DEQUE_H */
|
#endif /* CMC_EXT_CMC_DEQUE_H */
|
||||||
+459
-484
@@ -24,524 +24,499 @@
|
|||||||
* The part 'INIT' gives a new way of initializing a collection. The collection
|
* The part 'INIT' gives a new way of initializing a collection. The collection
|
||||||
* struct is not heap allocated, only its internal structure (nodes, buffers).
|
* struct is not heap allocated, only its internal structure (nodes, buffers).
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HASHMAP_INIT(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_INIT(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_INIT_HEADER(PARAMS) \
|
CMC_EXT_CMC_HASHMAP_INIT_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_INIT_SOURCE(PARAMS)
|
CMC_EXT_CMC_HASHMAP_INIT_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_INIT_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_INIT_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_INIT_HEADER_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HASHMAP_INIT_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_SNAME(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_K(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_INIT_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_INIT_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_INIT_SOURCE_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HASHMAP_INIT_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_SNAME(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_K(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_INIT_HEADER_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMAP_INIT_HEADER_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, \
|
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
||||||
struct CMC_DEF_FKEY(SNAME) * f_key, \
|
struct CMC_DEF_FVAL(SNAME) * f_val); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val); \
|
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
||||||
struct SNAME CMC_(PFX, _init_custom)( \
|
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||||
size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
struct CMC_CALLBACKS_NAME * callbacks); \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct cmc_alloc_node * alloc, \
|
|
||||||
struct cmc_callbacks * callbacks); \
|
|
||||||
void CMC_(PFX, _release)(struct SNAME _map_);
|
void CMC_(PFX, _release)(struct SNAME _map_);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_INIT_SOURCE_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMAP_INIT_SOURCE_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, \
|
struct SNAME CMC_(PFX, _init)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
||||||
struct CMC_DEF_FKEY(SNAME) * f_key, \
|
struct CMC_DEF_FVAL(SNAME) * f_val) \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val) \
|
{ \
|
||||||
{ \
|
return CMC_(PFX, _init_custom)(capacity, load, f_key, f_val, NULL, NULL); \
|
||||||
return CMC_(PFX, _init_custom)(capacity, load, f_key, f_val, NULL, \
|
} \
|
||||||
NULL); \
|
\
|
||||||
} \
|
struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
||||||
\
|
struct CMC_DEF_FVAL(SNAME) * f_val, struct CMC_ALLOC_NODE_NAME * alloc, \
|
||||||
struct SNAME CMC_(PFX, _init_custom)( \
|
struct CMC_CALLBACKS_NAME * callbacks) \
|
||||||
size_t capacity, double load, struct CMC_DEF_FKEY(SNAME) * f_key, \
|
{ \
|
||||||
struct CMC_DEF_FVAL(SNAME) * f_val, struct cmc_alloc_node * alloc, \
|
struct SNAME _map_ = { 0 }; \
|
||||||
struct cmc_callbacks * callbacks) \
|
\
|
||||||
{ \
|
if (capacity == 0 || load <= 0 || load >= 1) \
|
||||||
struct SNAME _map_ = { 0 }; \
|
return _map_; \
|
||||||
\
|
\
|
||||||
if (capacity == 0 || load <= 0 || load >= 1) \
|
/* Prevent integer overflow */ \
|
||||||
return _map_; \
|
if (capacity >= UINTMAX_MAX * load) \
|
||||||
\
|
return _map_; \
|
||||||
/* Prevent integer overflow */ \
|
\
|
||||||
if (capacity >= UINTMAX_MAX * load) \
|
if (!f_key || !f_val) \
|
||||||
return _map_; \
|
return _map_; \
|
||||||
\
|
\
|
||||||
if (!f_key || !f_val) \
|
size_t real_capacity = CMC_(PFX, _impl_calculate_size)(capacity / load); \
|
||||||
return _map_; \
|
\
|
||||||
\
|
if (!alloc) \
|
||||||
size_t real_capacity = \
|
alloc = &cmc_alloc_node_default; \
|
||||||
CMC_(PFX, _impl_calculate_size)(capacity / load); \
|
\
|
||||||
\
|
_map_.buffer = alloc->calloc(real_capacity, sizeof(struct CMC_DEF_ENTRY(SNAME))); \
|
||||||
if (!alloc) \
|
\
|
||||||
alloc = &cmc_alloc_node_default; \
|
if (!_map_.buffer) \
|
||||||
\
|
return _map_; \
|
||||||
_map_.buffer = \
|
\
|
||||||
alloc->calloc(real_capacity, sizeof(struct CMC_DEF_ENTRY(SNAME))); \
|
_map_.count = 0; \
|
||||||
\
|
_map_.capacity = real_capacity; \
|
||||||
if (!_map_.buffer) \
|
_map_.load = load; \
|
||||||
return _map_; \
|
_map_.flag = CMC_FLAG_OK; \
|
||||||
\
|
_map_.f_key = f_key; \
|
||||||
_map_.count = 0; \
|
_map_.f_val = f_val; \
|
||||||
_map_.capacity = real_capacity; \
|
_map_.alloc = alloc; \
|
||||||
_map_.load = load; \
|
CMC_CALLBACKS_ASSIGN(&_map_, callbacks); \
|
||||||
_map_.flag = CMC_FLAG_OK; \
|
\
|
||||||
_map_.f_key = f_key; \
|
return _map_; \
|
||||||
_map_.f_val = f_val; \
|
} \
|
||||||
_map_.alloc = alloc; \
|
\
|
||||||
_map_.callbacks = callbacks; \
|
void CMC_(PFX, _release)(struct SNAME _map_) \
|
||||||
\
|
{ \
|
||||||
return _map_; \
|
if (_map_.f_key->free || _map_.f_val->free) \
|
||||||
} \
|
{ \
|
||||||
\
|
for (size_t i = 0; i < _map_.capacity; i++) \
|
||||||
void CMC_(PFX, _release)(struct SNAME _map_) \
|
{ \
|
||||||
{ \
|
struct CMC_DEF_ENTRY(SNAME) *entry = &(_map_.buffer[i]); \
|
||||||
if (_map_.f_key->free || _map_.f_val->free) \
|
\
|
||||||
{ \
|
if (entry->state == CMC_ES_FILLED) \
|
||||||
for (size_t i = 0; i < _map_.capacity; i++) \
|
{ \
|
||||||
{ \
|
if (_map_.f_key->free) \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = &(_map_.buffer[i]); \
|
_map_.f_key->free(entry->key); \
|
||||||
\
|
if (_map_.f_val->free) \
|
||||||
if (entry->state == CMC_ES_FILLED) \
|
_map_.f_val->free(entry->value); \
|
||||||
{ \
|
} \
|
||||||
if (_map_.f_key->free) \
|
} \
|
||||||
_map_.f_key->free(entry->key); \
|
} \
|
||||||
if (_map_.f_val->free) \
|
\
|
||||||
_map_.f_val->free(entry->value); \
|
_map_.alloc->free(_map_.buffer); \
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
_map_.alloc->free(_map_.buffer); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ITER
|
* ITER
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HASHMAP_ITER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_ITER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_ITER_HEADER(PARAMS) \
|
CMC_EXT_CMC_HASHMAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_ITER_SOURCE(PARAMS)
|
CMC_EXT_CMC_HASHMAP_ITER_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_ITER_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HASHMAP_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_SNAME(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_K(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_ITER_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_ITER_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HASHMAP_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_SNAME(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_K(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_ITER_HEADER_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMAP_ITER_HEADER_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
/* HashMap Iterator */ \
|
/* HashMap Iterator */ \
|
||||||
struct CMC_DEF_ITER(SNAME) \
|
struct CMC_DEF_ITER(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Target hashmap */ \
|
/* Target hashmap */ \
|
||||||
struct SNAME *target; \
|
struct SNAME *target; \
|
||||||
\
|
\
|
||||||
/* Cursor's position (index) */ \
|
/* Cursor's position (index) */ \
|
||||||
size_t cursor; \
|
size_t cursor; \
|
||||||
\
|
\
|
||||||
/* Keeps track of relative index to the iteration of elements */ \
|
/* Keeps track of relative index to the iteration of elements */ \
|
||||||
size_t index; \
|
size_t index; \
|
||||||
\
|
\
|
||||||
/* The index of the first element */ \
|
/* The index of the first element */ \
|
||||||
size_t first; \
|
size_t first; \
|
||||||
\
|
\
|
||||||
/* The index of the last element */ \
|
/* The index of the last element */ \
|
||||||
size_t last; \
|
size_t last; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the start of the iteration */ \
|
/* If the iterator has reached the start of the iteration */ \
|
||||||
bool start; \
|
bool start; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the end of the iteration */ \
|
/* If the iterator has reached the end of the iteration */ \
|
||||||
bool end; \
|
bool end; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Iterator Initialization */ \
|
/* Iterator Initialization */ \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
||||||
/* Iterator State */ \
|
/* Iterator State */ \
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Movement */ \
|
/* Iterator Movement */ \
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
size_t steps); \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \
|
||||||
size_t steps); \
|
/* Iterator Access */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
size_t index); \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Access */ \
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_ITER_SOURCE_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMAP_ITER_SOURCE_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.index = 0; \
|
iter.index = 0; \
|
||||||
iter.first = 0; \
|
iter.first = 0; \
|
||||||
iter.last = 0; \
|
iter.last = 0; \
|
||||||
iter.start = true; \
|
iter.start = true; \
|
||||||
iter.end = CMC_(PFX, _empty)(target); \
|
iter.end = CMC_(PFX, _empty)(target); \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = 0; i < target->capacity; i++) \
|
for (size_t i = 0; i < target->capacity; i++) \
|
||||||
{ \
|
{ \
|
||||||
if (target->buffer[i].state == CMC_ES_FILLED) \
|
if (target->buffer[i].state == CMC_ES_FILLED) \
|
||||||
{ \
|
{ \
|
||||||
iter.first = i; \
|
iter.first = i; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter.cursor = iter.first; \
|
iter.cursor = iter.first; \
|
||||||
\
|
\
|
||||||
for (size_t i = target->capacity; i > 0; i--) \
|
for (size_t i = target->capacity; i > 0; i--) \
|
||||||
{ \
|
{ \
|
||||||
if (target->buffer[i - 1].state == CMC_ES_FILLED) \
|
if (target->buffer[i - 1].state == CMC_ES_FILLED) \
|
||||||
{ \
|
{ \
|
||||||
iter.last = i - 1; \
|
iter.last = i - 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.index = 0; \
|
iter.index = 0; \
|
||||||
iter.first = 0; \
|
iter.first = 0; \
|
||||||
iter.last = 0; \
|
iter.last = 0; \
|
||||||
iter.start = CMC_(PFX, _empty)(target); \
|
iter.start = CMC_(PFX, _empty)(target); \
|
||||||
iter.end = true; \
|
iter.end = true; \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = 0; i < target->capacity; i++) \
|
for (size_t i = 0; i < target->capacity; i++) \
|
||||||
{ \
|
{ \
|
||||||
if (target->buffer[i].state == CMC_ES_FILLED) \
|
if (target->buffer[i].state == CMC_ES_FILLED) \
|
||||||
{ \
|
{ \
|
||||||
iter.first = i; \
|
iter.first = i; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
for (size_t i = target->capacity; i > 0; i--) \
|
for (size_t i = target->capacity; i > 0; i--) \
|
||||||
{ \
|
{ \
|
||||||
if (target->buffer[i - 1].state == CMC_ES_FILLED) \
|
if (target->buffer[i - 1].state == CMC_ES_FILLED) \
|
||||||
{ \
|
{ \
|
||||||
iter.last = i - 1; \
|
iter.last = i - 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter.cursor = iter.last; \
|
iter.cursor = iter.last; \
|
||||||
iter.index = target->count - 1; \
|
iter.index = target->count - 1; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->first; \
|
iter->cursor = iter->first; \
|
||||||
iter->index = 0; \
|
iter->index = 0; \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->last; \
|
iter->cursor = iter->last; \
|
||||||
iter->index = iter->target->count - 1; \
|
iter->index = iter->target->count - 1; \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->end) \
|
if (iter->end) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->index + 1 == iter->target->count) \
|
if (iter->index + 1 == iter->target->count) \
|
||||||
{ \
|
{ \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ENTRY(SNAME) *scan = \
|
struct CMC_DEF_ENTRY(SNAME) *scan = &(iter->target->buffer[iter->cursor]); \
|
||||||
&(iter->target->buffer[iter->cursor]); \
|
\
|
||||||
\
|
iter->index++; \
|
||||||
iter->index++; \
|
\
|
||||||
\
|
while (1) \
|
||||||
while (1) \
|
{ \
|
||||||
{ \
|
iter->cursor++; \
|
||||||
iter->cursor++; \
|
scan = &(iter->target->buffer[iter->cursor]); \
|
||||||
scan = &(iter->target->buffer[iter->cursor]); \
|
\
|
||||||
\
|
if (scan->state == CMC_ES_FILLED) \
|
||||||
if (scan->state == CMC_ES_FILLED) \
|
break; \
|
||||||
break; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (iter->start) \
|
||||||
if (iter->start) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->index == 0) \
|
||||||
if (iter->index == 0) \
|
{ \
|
||||||
{ \
|
iter->start = true; \
|
||||||
iter->start = true; \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
\
|
||||||
\
|
struct CMC_DEF_ENTRY(SNAME) *scan = &(iter->target->buffer[iter->cursor]); \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *scan = \
|
\
|
||||||
&(iter->target->buffer[iter->cursor]); \
|
iter->index--; \
|
||||||
\
|
\
|
||||||
iter->index--; \
|
while (1) \
|
||||||
\
|
{ \
|
||||||
while (1) \
|
iter->cursor--; \
|
||||||
{ \
|
scan = &(iter->target->buffer[iter->cursor]); \
|
||||||
iter->cursor--; \
|
\
|
||||||
scan = &(iter->target->buffer[iter->cursor]); \
|
if (scan->state == CMC_ES_FILLED) \
|
||||||
\
|
break; \
|
||||||
if (scan->state == CMC_ES_FILLED) \
|
} \
|
||||||
break; \
|
\
|
||||||
} \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
/* Returns true only if the iterator moved */ \
|
||||||
\
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
/* Returns true only if the iterator moved */ \
|
{ \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
if (iter->end) \
|
||||||
size_t steps) \
|
return false; \
|
||||||
{ \
|
\
|
||||||
if (iter->end) \
|
if (iter->index + 1 == iter->target->count) \
|
||||||
return false; \
|
{ \
|
||||||
\
|
iter->end = true; \
|
||||||
if (iter->index + 1 == iter->target->count) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
iter->end = true; \
|
\
|
||||||
return false; \
|
if (steps == 0 || iter->index + steps >= iter->target->count) \
|
||||||
} \
|
return false; \
|
||||||
\
|
\
|
||||||
if (steps == 0 || iter->index + steps >= iter->target->count) \
|
for (size_t i = 0; i < steps; i++) \
|
||||||
return false; \
|
CMC_(PFX, _iter_next)(iter); \
|
||||||
\
|
\
|
||||||
for (size_t i = 0; i < steps; i++) \
|
return true; \
|
||||||
CMC_(PFX, _iter_next)(iter); \
|
} \
|
||||||
\
|
\
|
||||||
return true; \
|
/* Returns true only if the iterator moved */ \
|
||||||
} \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
\
|
{ \
|
||||||
/* Returns true only if the iterator moved */ \
|
if (iter->start) \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
return false; \
|
||||||
size_t steps) \
|
\
|
||||||
{ \
|
if (iter->index == 0) \
|
||||||
if (iter->start) \
|
{ \
|
||||||
return false; \
|
iter->start = true; \
|
||||||
\
|
return false; \
|
||||||
if (iter->index == 0) \
|
} \
|
||||||
{ \
|
\
|
||||||
iter->start = true; \
|
if (steps == 0 || iter->index < steps) \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
\
|
||||||
\
|
for (size_t i = 0; i < steps; i++) \
|
||||||
if (steps == 0 || iter->index < steps) \
|
CMC_(PFX, _iter_prev)(iter); \
|
||||||
return false; \
|
\
|
||||||
\
|
return true; \
|
||||||
for (size_t i = 0; i < steps; i++) \
|
} \
|
||||||
CMC_(PFX, _iter_prev)(iter); \
|
\
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* Returns true only if the iterator was able to be positioned at the */ \
|
/* Returns true only if the iterator was able to be positioned at the */ \
|
||||||
/* given index */ \
|
/* given index */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \
|
||||||
size_t index) \
|
{ \
|
||||||
{ \
|
if (index >= iter->target->count) \
|
||||||
if (index >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->index > index) \
|
||||||
if (iter->index > index) \
|
return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \
|
||||||
return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \
|
else if (iter->index < index) \
|
||||||
else if (iter->index < index) \
|
return CMC_(PFX, _iter_advance)(iter, index - iter->index); \
|
||||||
return CMC_(PFX, _iter_advance)(iter, index - iter->index); \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return (K){ 0 }; \
|
||||||
return (K){ 0 }; \
|
\
|
||||||
\
|
return iter->target->buffer[iter->cursor].key; \
|
||||||
return iter->target->buffer[iter->cursor].key; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return (V){ 0 }; \
|
||||||
return (V){ 0 }; \
|
\
|
||||||
\
|
return iter->target->buffer[iter->cursor].value; \
|
||||||
return iter->target->buffer[iter->cursor].value; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return NULL; \
|
||||||
return NULL; \
|
\
|
||||||
\
|
return &(iter->target->buffer[iter->cursor].value); \
|
||||||
return &(iter->target->buffer[iter->cursor].value); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
return iter->index; \
|
||||||
return iter->index; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STR
|
* STR
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HASHMAP_STR(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_STR(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_STR_HEADER(PARAMS) \
|
CMC_EXT_CMC_HASHMAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_STR_SOURCE(PARAMS)
|
CMC_EXT_CMC_HASHMAP_STR_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_STR_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HASHMAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_SNAME(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_K(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_STR_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HASHMAP_STR_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HASHMAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_SNAME(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_K(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_STR_HEADER_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMAP_STR_HEADER_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr); \
|
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr); \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, \
|
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, const char *start, const char *separator, \
|
||||||
const char *start, const char *separator, \
|
|
||||||
const char *end, const char *key_val_sep);
|
const char *end, const char *key_val_sep);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMAP_STR_SOURCE_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMAP_STR_SOURCE_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr) \
|
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr) \
|
||||||
{ \
|
{ \
|
||||||
struct SNAME *m_ = _map_; \
|
struct SNAME *m_ = _map_; \
|
||||||
\
|
\
|
||||||
return 0 <= fprintf(fptr, \
|
return 0 <= fprintf(fptr, \
|
||||||
"struct %s<%s, %s> " \
|
"struct %s<%s, %s> " \
|
||||||
"at %p { " \
|
"at %p { " \
|
||||||
"buffer:%p, " \
|
"buffer:%p, " \
|
||||||
"capacity:%" PRIuMAX ", " \
|
"capacity:%" PRIuMAX ", " \
|
||||||
"count:%" PRIuMAX ", " \
|
"count:%" PRIuMAX ", " \
|
||||||
"load:%lf, " \
|
"load:%lf, " \
|
||||||
"flag:%d, " \
|
"flag:%d, " \
|
||||||
"f_key:%p, " \
|
"f_key:%p, " \
|
||||||
"f_val:%p, " \
|
"f_val:%p, " \
|
||||||
"alloc:%p, " \
|
"alloc:%p, " \
|
||||||
"callbacks:%p }", \
|
"callbacks:%p }", \
|
||||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), \
|
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \
|
||||||
CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \
|
m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, CMC_CALLBACKS_GET(m_)); \
|
||||||
m_->count, m_->load, m_->flag, m_->f_key, \
|
} \
|
||||||
m_->f_val, m_->alloc, m_->callbacks); \
|
\
|
||||||
} \
|
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, const char *start, const char *separator, \
|
||||||
\
|
const char *end, const char *key_val_sep) \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, \
|
{ \
|
||||||
const char *start, const char *separator, \
|
fprintf(fptr, "%s", start); \
|
||||||
const char *end, const char *key_val_sep) \
|
\
|
||||||
{ \
|
size_t last = 0; \
|
||||||
fprintf(fptr, "%s", start); \
|
for (size_t i = _map_->capacity; i > 0; i--) \
|
||||||
\
|
{ \
|
||||||
size_t last = 0; \
|
if ((_map_->buffer[i - 1]).state == CMC_ES_FILLED) \
|
||||||
for (size_t i = _map_->capacity; i > 0; i--) \
|
{ \
|
||||||
{ \
|
last = i - 1; \
|
||||||
if ((_map_->buffer[i - 1]).state == CMC_ES_FILLED) \
|
break; \
|
||||||
{ \
|
} \
|
||||||
last = i - 1; \
|
} \
|
||||||
break; \
|
\
|
||||||
} \
|
for (size_t i = 0; i < _map_->capacity; i++) \
|
||||||
} \
|
{ \
|
||||||
\
|
struct CMC_DEF_ENTRY(SNAME) *entry = &(_map_->buffer[i]); \
|
||||||
for (size_t i = 0; i < _map_->capacity; i++) \
|
\
|
||||||
{ \
|
if (entry->state == CMC_ES_FILLED) \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = &(_map_->buffer[i]); \
|
{ \
|
||||||
\
|
if (!_map_->f_key->str(fptr, entry->key)) \
|
||||||
if (entry->state == CMC_ES_FILLED) \
|
return false; \
|
||||||
{ \
|
\
|
||||||
if (!_map_->f_key->str(fptr, entry->key)) \
|
fprintf(fptr, "%s", key_val_sep); \
|
||||||
return false; \
|
\
|
||||||
\
|
if (!_map_->f_val->str(fptr, entry->value)) \
|
||||||
fprintf(fptr, "%s", key_val_sep); \
|
return false; \
|
||||||
\
|
\
|
||||||
if (!_map_->f_val->str(fptr, entry->value)) \
|
if (i + 1 < last) \
|
||||||
return false; \
|
fprintf(fptr, "%s", separator); \
|
||||||
\
|
} \
|
||||||
if (i + 1 < last) \
|
} \
|
||||||
fprintf(fptr, "%s", separator); \
|
\
|
||||||
} \
|
fprintf(fptr, "%s", end); \
|
||||||
} \
|
\
|
||||||
\
|
return true; \
|
||||||
fprintf(fptr, "%s", end); \
|
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_EXT_CMC_HASHMAP_H */
|
#endif /* CMC_EXT_CMC_HASHMAP_H */
|
||||||
+409
-423
@@ -21,451 +21,437 @@
|
|||||||
/**
|
/**
|
||||||
* ITER
|
* ITER
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_ITER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_ITER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER(PARAMS) \
|
CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE(PARAMS)
|
CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER_( \
|
CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE_( \
|
CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_HEADER_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
/* HashMultiMap Iterator */ \
|
/* HashMultiMap Iterator */ \
|
||||||
struct CMC_DEF_ITER(SNAME) \
|
struct CMC_DEF_ITER(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Target hashmultimap */ \
|
/* Target hashmultimap */ \
|
||||||
struct SNAME *target; \
|
struct SNAME *target; \
|
||||||
\
|
\
|
||||||
/* Current entry */ \
|
/* Current entry */ \
|
||||||
struct CMC_DEF_ENTRY(SNAME) * curr_entry; \
|
struct CMC_DEF_ENTRY(SNAME) * curr_entry; \
|
||||||
\
|
\
|
||||||
/* Cursor`s position (index) */ \
|
/* Cursor`s position (index) */ \
|
||||||
size_t cursor; \
|
size_t cursor; \
|
||||||
\
|
\
|
||||||
/* Keeps track of relative index to the iteration of elements */ \
|
/* Keeps track of relative index to the iteration of elements */ \
|
||||||
size_t index; \
|
size_t index; \
|
||||||
\
|
\
|
||||||
/* The index of the first element */ \
|
/* The index of the first element */ \
|
||||||
size_t first; \
|
size_t first; \
|
||||||
\
|
\
|
||||||
/* The index of the last element */ \
|
/* The index of the last element */ \
|
||||||
size_t last; \
|
size_t last; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the start of the iteration */ \
|
/* If the iterator has reached the start of the iteration */ \
|
||||||
bool start; \
|
bool start; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the end of the iteration */ \
|
/* If the iterator has reached the end of the iteration */ \
|
||||||
bool end; \
|
bool end; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Iterator Initialization */ \
|
/* Iterator Initialization */ \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
||||||
/* Iterator State */ \
|
/* Iterator State */ \
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Movement */ \
|
/* Iterator Movement */ \
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
size_t steps); \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \
|
||||||
size_t steps); \
|
/* Iterator Access */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
size_t index); \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Access */ \
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_ITER_SOURCE_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.curr_entry = NULL; \
|
iter.curr_entry = NULL; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.index = 0; \
|
iter.index = 0; \
|
||||||
iter.first = 0; \
|
iter.first = 0; \
|
||||||
iter.last = 0; \
|
iter.last = 0; \
|
||||||
iter.start = true; \
|
iter.start = true; \
|
||||||
iter.end = CMC_(PFX, _empty)(target); \
|
iter.end = CMC_(PFX, _empty)(target); \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = 0; i < target->capacity; i++) \
|
for (size_t i = 0; i < target->capacity; i++) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0]; \
|
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0]; \
|
||||||
\
|
\
|
||||||
if (entry && entry != CMC_ENTRY_DELETED) \
|
if (entry && entry != CMC_ENTRY_DELETED) \
|
||||||
{ \
|
{ \
|
||||||
iter.curr_entry = target->buffer[i][0]; \
|
iter.curr_entry = target->buffer[i][0]; \
|
||||||
iter.first = i; \
|
iter.first = i; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter.cursor = iter.first; \
|
iter.cursor = iter.first; \
|
||||||
\
|
\
|
||||||
for (size_t i = target->capacity; i > 0; i--) \
|
for (size_t i = target->capacity; i > 0; i--) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][1]; \
|
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][1]; \
|
||||||
\
|
\
|
||||||
if (entry && entry != CMC_ENTRY_DELETED) \
|
if (entry && entry != CMC_ENTRY_DELETED) \
|
||||||
{ \
|
{ \
|
||||||
iter.last = i - 1; \
|
iter.last = i - 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.curr_entry = NULL; \
|
iter.curr_entry = NULL; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.index = 0; \
|
iter.index = 0; \
|
||||||
iter.first = 0; \
|
iter.first = 0; \
|
||||||
iter.last = 0; \
|
iter.last = 0; \
|
||||||
iter.start = CMC_(PFX, _empty)(target); \
|
iter.start = CMC_(PFX, _empty)(target); \
|
||||||
iter.end = true; \
|
iter.end = true; \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = 0; i < target->capacity; i++) \
|
for (size_t i = 0; i < target->capacity; i++) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0]; \
|
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i][0]; \
|
||||||
\
|
\
|
||||||
if (entry && entry != CMC_ENTRY_DELETED) \
|
if (entry && entry != CMC_ENTRY_DELETED) \
|
||||||
{ \
|
{ \
|
||||||
iter.first = i; \
|
iter.first = i; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
for (size_t i = target->capacity; i > 0; i--) \
|
for (size_t i = target->capacity; i > 0; i--) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][1]; \
|
struct CMC_DEF_ENTRY(SNAME) *entry = target->buffer[i - 1][1]; \
|
||||||
\
|
\
|
||||||
if (entry && entry != CMC_ENTRY_DELETED) \
|
if (entry && entry != CMC_ENTRY_DELETED) \
|
||||||
{ \
|
{ \
|
||||||
iter.curr_entry = target->buffer[i - 1][1]; \
|
iter.curr_entry = target->buffer[i - 1][1]; \
|
||||||
iter.last = i - 1; \
|
iter.last = i - 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter.cursor = iter.last; \
|
iter.cursor = iter.last; \
|
||||||
iter.index = target->count - 1; \
|
iter.index = target->count - 1; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->first; \
|
iter->cursor = iter->first; \
|
||||||
iter->index = 0; \
|
iter->index = 0; \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->curr_entry = iter->target->buffer[iter->first][0]; \
|
iter->curr_entry = iter->target->buffer[iter->first][0]; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->last; \
|
iter->cursor = iter->last; \
|
||||||
iter->index = iter->target->count - 1; \
|
iter->index = iter->target->count - 1; \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
iter->curr_entry = iter->target->buffer[iter->last][1]; \
|
iter->curr_entry = iter->target->buffer[iter->last][1]; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->end) \
|
if (iter->end) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->curr_entry->next != NULL) \
|
if (iter->curr_entry->next != NULL) \
|
||||||
{ \
|
{ \
|
||||||
iter->curr_entry = iter->curr_entry->next; \
|
iter->curr_entry = iter->curr_entry->next; \
|
||||||
iter->index++; \
|
iter->index++; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
if (iter->cursor == iter->last) \
|
if (iter->cursor == iter->last) \
|
||||||
{ \
|
{ \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->cursor++; \
|
iter->cursor++; \
|
||||||
\
|
\
|
||||||
while (iter->target->buffer[iter->cursor][0] == NULL) \
|
while (iter->target->buffer[iter->cursor][0] == NULL) \
|
||||||
iter->cursor++; \
|
iter->cursor++; \
|
||||||
\
|
\
|
||||||
iter->curr_entry = iter->target->buffer[iter->cursor][0]; \
|
iter->curr_entry = iter->target->buffer[iter->cursor][0]; \
|
||||||
\
|
\
|
||||||
iter->index++; \
|
iter->index++; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->start) \
|
if (iter->start) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->curr_entry->prev != NULL) \
|
if (iter->curr_entry->prev != NULL) \
|
||||||
{ \
|
{ \
|
||||||
iter->curr_entry = iter->curr_entry->prev; \
|
iter->curr_entry = iter->curr_entry->prev; \
|
||||||
iter->index--; \
|
iter->index--; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
if (iter->cursor == iter->first) \
|
if (iter->cursor == iter->first) \
|
||||||
{ \
|
{ \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->cursor--; \
|
iter->cursor--; \
|
||||||
\
|
\
|
||||||
while (iter->target->buffer[iter->cursor][1] == NULL) \
|
while (iter->target->buffer[iter->cursor][1] == NULL) \
|
||||||
iter->cursor--; \
|
iter->cursor--; \
|
||||||
\
|
\
|
||||||
iter->curr_entry = iter->target->buffer[iter->cursor][1]; \
|
iter->curr_entry = iter->target->buffer[iter->cursor][1]; \
|
||||||
\
|
\
|
||||||
iter->index--; \
|
iter->index--; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* Returns true only if the iterator moved */ \
|
/* Returns true only if the iterator moved */ \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
size_t steps) \
|
{ \
|
||||||
{ \
|
if (iter->end) \
|
||||||
if (iter->end) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->index + 1 == iter->target->count) \
|
||||||
if (iter->index + 1 == iter->target->count) \
|
{ \
|
||||||
{ \
|
iter->end = true; \
|
||||||
iter->end = true; \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
if (steps == 0 || iter->index + steps >= iter->target->count) \
|
||||||
if (steps == 0 || iter->index + steps >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
for (size_t i = 0; i < steps; i++) \
|
||||||
for (size_t i = 0; i < steps; i++) \
|
CMC_(PFX, _iter_next)(iter); \
|
||||||
CMC_(PFX, _iter_next)(iter); \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
/* Returns true only if the iterator moved */ \
|
||||||
/* Returns true only if the iterator moved */ \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
{ \
|
||||||
size_t steps) \
|
if (iter->start) \
|
||||||
{ \
|
return false; \
|
||||||
if (iter->start) \
|
\
|
||||||
return false; \
|
if (iter->index == 0) \
|
||||||
\
|
{ \
|
||||||
if (iter->index == 0) \
|
iter->start = true; \
|
||||||
{ \
|
return false; \
|
||||||
iter->start = true; \
|
} \
|
||||||
return false; \
|
\
|
||||||
} \
|
if (steps == 0 || iter->index < steps) \
|
||||||
\
|
return false; \
|
||||||
if (steps == 0 || iter->index < steps) \
|
\
|
||||||
return false; \
|
for (size_t i = 0; i < steps; i++) \
|
||||||
\
|
CMC_(PFX, _iter_prev)(iter); \
|
||||||
for (size_t i = 0; i < steps; i++) \
|
\
|
||||||
CMC_(PFX, _iter_prev)(iter); \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
/* Returns true only if the iterator was able to be positioned at the */ \
|
||||||
\
|
/* given index */ \
|
||||||
/* Returns true only if the iterator was able to be positioned at the */ \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \
|
||||||
/* given index */ \
|
{ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
if (index >= iter->target->count) \
|
||||||
size_t index) \
|
return false; \
|
||||||
{ \
|
\
|
||||||
if (index >= iter->target->count) \
|
if (iter->index > index) \
|
||||||
return false; \
|
return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \
|
||||||
\
|
else if (iter->index < index) \
|
||||||
if (iter->index > index) \
|
return CMC_(PFX, _iter_advance)(iter, index - iter->index); \
|
||||||
return CMC_(PFX, _iter_rewind)(iter, iter->index - index); \
|
\
|
||||||
else if (iter->index < index) \
|
return true; \
|
||||||
return CMC_(PFX, _iter_advance)(iter, index - iter->index); \
|
} \
|
||||||
\
|
\
|
||||||
return true; \
|
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
} \
|
{ \
|
||||||
\
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
K CMC_(PFX, _iter_key)(struct CMC_DEF_ITER(SNAME) * iter) \
|
return (K){ 0 }; \
|
||||||
{ \
|
\
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return iter->curr_entry->key; \
|
||||||
return (K){ 0 }; \
|
} \
|
||||||
\
|
\
|
||||||
return iter->curr_entry->key; \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
} \
|
{ \
|
||||||
\
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
return (V){ 0 }; \
|
||||||
{ \
|
\
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return iter->curr_entry->value; \
|
||||||
return (V){ 0 }; \
|
} \
|
||||||
\
|
\
|
||||||
return iter->curr_entry->value; \
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
} \
|
{ \
|
||||||
\
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
return NULL; \
|
||||||
{ \
|
\
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return &(iter->curr_entry->value); \
|
||||||
return NULL; \
|
} \
|
||||||
\
|
\
|
||||||
return &(iter->curr_entry->value); \
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
} \
|
{ \
|
||||||
\
|
return iter->index; \
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
|
||||||
{ \
|
|
||||||
return iter->index; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STR
|
* STR
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_STR(PARAMS) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_STR(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER(PARAMS) \
|
CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE(PARAMS)
|
CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER_( \
|
CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE_( \
|
CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_K(PARAMS), \
|
CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr); \
|
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr); \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, \
|
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, const char *start, const char *separator, \
|
||||||
const char *start, const char *separator, \
|
|
||||||
const char *end, const char *key_val_sep);
|
const char *end, const char *key_val_sep);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE_(PFX, SNAME, K, V) \
|
#define CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE_(PFX, SNAME, K, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr) \
|
bool CMC_(PFX, _to_string)(struct SNAME * _map_, FILE * fptr) \
|
||||||
{ \
|
{ \
|
||||||
struct SNAME *m_ = _map_; \
|
struct SNAME *m_ = _map_; \
|
||||||
\
|
\
|
||||||
return 0 <= fprintf(fptr, \
|
return 0 <= fprintf(fptr, \
|
||||||
"struct %s<%s, %s> " \
|
"struct %s<%s, %s> " \
|
||||||
"at %p { " \
|
"at %p { " \
|
||||||
"buffer:%p, " \
|
"buffer:%p, " \
|
||||||
"capacity:%" PRIuMAX ", " \
|
"capacity:%" PRIuMAX ", " \
|
||||||
"count:%" PRIuMAX ", " \
|
"count:%" PRIuMAX ", " \
|
||||||
"load:%lf, " \
|
"load:%lf, " \
|
||||||
"flag:%d, " \
|
"flag:%d, " \
|
||||||
"f_key:%p, " \
|
"f_key:%p, " \
|
||||||
"f_val:%p, " \
|
"f_val:%p, " \
|
||||||
"alloc:%p, " \
|
"alloc:%p, " \
|
||||||
"callbacks:%p }", \
|
"callbacks:%p }", \
|
||||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), \
|
CMC_TO_STRING(SNAME), CMC_TO_STRING(K), CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \
|
||||||
CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \
|
m_->count, m_->load, m_->flag, m_->f_key, m_->f_val, m_->alloc, CMC_CALLBACKS_GET(m_)); \
|
||||||
m_->count, m_->load, m_->flag, m_->f_key, \
|
} \
|
||||||
m_->f_val, m_->alloc, m_->callbacks); \
|
\
|
||||||
} \
|
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, const char *start, const char *separator, \
|
||||||
\
|
const char *end, const char *key_val_sep) \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _map_, FILE * fptr, \
|
{ \
|
||||||
const char *start, const char *separator, \
|
fprintf(fptr, "%s", start); \
|
||||||
const char *end, const char *key_val_sep) \
|
\
|
||||||
{ \
|
size_t last = 0; \
|
||||||
fprintf(fptr, "%s", start); \
|
for (size_t i = _map_->capacity; i > 0; i--) \
|
||||||
\
|
{ \
|
||||||
size_t last = 0; \
|
struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i - 1][1]; \
|
||||||
for (size_t i = _map_->capacity; i > 0; i--) \
|
\
|
||||||
{ \
|
if (entry && entry != CMC_ENTRY_DELETED) \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *entry = _map_->buffer[i - 1][1]; \
|
{ \
|
||||||
\
|
last = i - 1; \
|
||||||
if (entry && entry != CMC_ENTRY_DELETED) \
|
break; \
|
||||||
{ \
|
} \
|
||||||
last = i - 1; \
|
} \
|
||||||
break; \
|
\
|
||||||
} \
|
for (size_t i = 0; i < _map_->capacity; i++) \
|
||||||
} \
|
{ \
|
||||||
\
|
struct CMC_DEF_ENTRY(SNAME) *scan = _map_->buffer[i][0]; \
|
||||||
for (size_t i = 0; i < _map_->capacity; i++) \
|
\
|
||||||
{ \
|
while (scan != NULL) \
|
||||||
struct CMC_DEF_ENTRY(SNAME) *scan = _map_->buffer[i][0]; \
|
{ \
|
||||||
\
|
if (!_map_->f_key->str(fptr, scan->key)) \
|
||||||
while (scan != NULL) \
|
return false; \
|
||||||
{ \
|
\
|
||||||
if (!_map_->f_key->str(fptr, scan->key)) \
|
fprintf(fptr, "%s", key_val_sep); \
|
||||||
return false; \
|
\
|
||||||
\
|
if (!_map_->f_val->str(fptr, scan->value)) \
|
||||||
fprintf(fptr, "%s", key_val_sep); \
|
return false; \
|
||||||
\
|
\
|
||||||
if (!_map_->f_val->str(fptr, scan->value)) \
|
scan = scan->next; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (i + 1 < last) \
|
||||||
scan = scan->next; \
|
fprintf(fptr, "%s", separator); \
|
||||||
\
|
} \
|
||||||
if (i + 1 < last) \
|
} \
|
||||||
fprintf(fptr, "%s", separator); \
|
\
|
||||||
} \
|
fprintf(fptr, "%s", end); \
|
||||||
} \
|
\
|
||||||
\
|
return true; \
|
||||||
fprintf(fptr, "%s", end); \
|
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_EXT_CMC_HASHMULTIMAP_H */
|
#endif /* CMC_EXT_CMC_HASHMULTIMAP_H */
|
||||||
+630
-679
File diff suppressed because it is too large.
Load diff
+597
-638
File diff suppressed because it is too large.
Load diff
+258
-271
@@ -18,301 +18,288 @@
|
|||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HEAP_PARTS ITER, STR
|
#define CMC_EXT_CMC_HEAP_PARTS ITER, STR
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_ITER(PARAMS) \
|
#define CMC_EXT_CMC_HEAP_ITER(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_ITER_HEADER(PARAMS) \
|
CMC_EXT_CMC_HEAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_ITER_SOURCE(PARAMS)
|
CMC_EXT_CMC_HEAP_ITER_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_ITER_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HEAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_ITER_HEADER_( \
|
CMC_EXT_CMC_HEAP_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_ITER_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HEAP_ITER_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_ITER_SOURCE_( \
|
CMC_EXT_CMC_HEAP_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_ITER_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_HEAP_ITER_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* Heap Iterator */ \
|
/* Heap Iterator */ \
|
||||||
struct CMC_DEF_ITER(SNAME) \
|
struct CMC_DEF_ITER(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Target heap */ \
|
/* Target heap */ \
|
||||||
struct SNAME *target; \
|
struct SNAME *target; \
|
||||||
\
|
\
|
||||||
/* Cursor's position (index) */ \
|
/* Cursor's position (index) */ \
|
||||||
size_t cursor; \
|
size_t cursor; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the start of the iteration */ \
|
/* If the iterator has reached the start of the iteration */ \
|
||||||
bool start; \
|
bool start; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the end of the iteration */ \
|
/* If the iterator has reached the end of the iteration */ \
|
||||||
bool end; \
|
bool end; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Iterator Initialization */ \
|
/* Iterator Initialization */ \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
||||||
/* Iterator State */ \
|
/* Iterator State */ \
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Movement */ \
|
/* Iterator Movement */ \
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
size_t steps); \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \
|
||||||
size_t steps); \
|
/* Iterator Access */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
size_t index); \
|
|
||||||
/* Iterator Access */ \
|
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_ITER_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_HEAP_ITER_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.start = true; \
|
iter.start = true; \
|
||||||
iter.end = CMC_(PFX, _empty)(target); \
|
iter.end = CMC_(PFX, _empty)(target); \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.start = CMC_(PFX, _empty)(target); \
|
iter.start = CMC_(PFX, _empty)(target); \
|
||||||
iter.end = true; \
|
iter.end = true; \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
iter.cursor = target->count - 1; \
|
iter.cursor = target->count - 1; \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = 0; \
|
iter->cursor = 0; \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->target->count - 1; \
|
iter->cursor = iter->target->count - 1; \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->end) \
|
if (iter->end) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->cursor + 1 == iter->target->count) \
|
if (iter->cursor + 1 == iter->target->count) \
|
||||||
{ \
|
{ \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor++; \
|
iter->cursor++; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->start) \
|
if (iter->start) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->cursor == 0) \
|
if (iter->cursor == 0) \
|
||||||
{ \
|
{ \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor--; \
|
iter->cursor--; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* Returns true only if the iterator moved */ \
|
/* Returns true only if the iterator moved */ \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
size_t steps) \
|
{ \
|
||||||
{ \
|
if (iter->end) \
|
||||||
if (iter->end) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->cursor + 1 == iter->target->count) \
|
||||||
if (iter->cursor + 1 == iter->target->count) \
|
{ \
|
||||||
{ \
|
iter->end = true; \
|
||||||
iter->end = true; \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
||||||
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->end) \
|
||||||
if (iter->end) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
\
|
||||||
\
|
iter->cursor += steps; \
|
||||||
iter->cursor += steps; \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
/* Returns true only if the iterator moved */ \
|
||||||
/* Returns true only if the iterator moved */ \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
{ \
|
||||||
size_t steps) \
|
if (iter->start) \
|
||||||
{ \
|
return false; \
|
||||||
if (iter->start) \
|
\
|
||||||
return false; \
|
if (iter->cursor == 0) \
|
||||||
\
|
{ \
|
||||||
if (iter->cursor == 0) \
|
iter->start = true; \
|
||||||
{ \
|
return false; \
|
||||||
iter->start = true; \
|
} \
|
||||||
return false; \
|
\
|
||||||
} \
|
if (steps == 0 || iter->cursor < steps) \
|
||||||
\
|
return false; \
|
||||||
if (steps == 0 || iter->cursor < steps) \
|
\
|
||||||
return false; \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->cursor -= steps; \
|
||||||
\
|
\
|
||||||
iter->cursor -= steps; \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* Returns true only if the iterator was able to be positioned at the */ \
|
/* Returns true only if the iterator was able to be positioned at the */ \
|
||||||
/* given index */ \
|
/* given index */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \
|
||||||
size_t index) \
|
{ \
|
||||||
{ \
|
if (index >= iter->target->count) \
|
||||||
if (index >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->cursor > index) \
|
||||||
if (iter->cursor > index) \
|
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
||||||
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
else if (iter->cursor < index) \
|
||||||
else if (iter->cursor < index) \
|
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
||||||
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return (V){ 0 }; \
|
||||||
return (V){ 0 }; \
|
\
|
||||||
\
|
return iter->target->buffer[iter->cursor]; \
|
||||||
return iter->target->buffer[iter->cursor]; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
return iter->cursor; \
|
||||||
return iter->cursor; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STR
|
* STR
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_HEAP_STR(PARAMS) \
|
#define CMC_EXT_CMC_HEAP_STR(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_STR_HEADER(PARAMS) \
|
CMC_EXT_CMC_HEAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_STR_SOURCE(PARAMS)
|
CMC_EXT_CMC_HEAP_STR_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_STR_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_HEAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HEAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_STR_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_HEAP_STR_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_HEAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_HEAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_STR_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_HEAP_STR_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr); \
|
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr); \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, \
|
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, const char *start, const char *separator, \
|
||||||
const char *start, const char *separator, \
|
|
||||||
const char *end);
|
const char *end);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_HEAP_STR_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_HEAP_STR_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr) \
|
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr) \
|
||||||
{ \
|
{ \
|
||||||
struct SNAME *h_ = _heap_; \
|
struct SNAME *h_ = _heap_; \
|
||||||
const char *t = h_->HO == 1 ? "MaxHeap" : "MinHeap"; \
|
const char *t = h_->HO == 1 ? "MaxHeap" : "MinHeap"; \
|
||||||
\
|
\
|
||||||
return 0 <= fprintf(fptr, \
|
return 0 <= fprintf(fptr, \
|
||||||
"struct %s<%s> " \
|
"struct %s<%s> " \
|
||||||
"at %p { " \
|
"at %p { " \
|
||||||
"buffer:%p, " \
|
"buffer:%p, " \
|
||||||
"capacity:%" PRIuMAX ", " \
|
"capacity:%" PRIuMAX ", " \
|
||||||
"count:%" PRIuMAX ", " \
|
"count:%" PRIuMAX ", " \
|
||||||
"type:%s, " \
|
"type:%s, " \
|
||||||
"flag:%d, " \
|
"flag:%d, " \
|
||||||
"f_val:%p, " \
|
"f_val:%p, " \
|
||||||
"alloc:%p, " \
|
"alloc:%p, " \
|
||||||
"callbacks: %p}", \
|
"callbacks: %p}", \
|
||||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), h_, \
|
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), h_, h_->buffer, h_->capacity, h_->count, t, \
|
||||||
h_->buffer, h_->capacity, h_->count, t, h_->flag, \
|
h_->flag, h_->f_val, h_->alloc, CMC_CALLBACKS_GET(h_)); \
|
||||||
h_->f_val, h_->alloc, h_->callbacks); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, const char *start, const char *separator, \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, \
|
const char *end) \
|
||||||
const char *start, const char *separator, \
|
{ \
|
||||||
const char *end) \
|
fprintf(fptr, "%s", start); \
|
||||||
{ \
|
\
|
||||||
fprintf(fptr, "%s", start); \
|
for (size_t i = 0; i < _heap_->count; i++) \
|
||||||
\
|
{ \
|
||||||
for (size_t i = 0; i < _heap_->count; i++) \
|
if (!_heap_->f_val->str(fptr, _heap_->buffer[i])) \
|
||||||
{ \
|
return false; \
|
||||||
if (!_heap_->f_val->str(fptr, _heap_->buffer[i])) \
|
\
|
||||||
return false; \
|
if (i + 1 < _heap_->count) \
|
||||||
\
|
fprintf(fptr, "%s", separator); \
|
||||||
if (i + 1 < _heap_->count) \
|
} \
|
||||||
fprintf(fptr, "%s", separator); \
|
\
|
||||||
} \
|
fprintf(fptr, "%s", end); \
|
||||||
\
|
\
|
||||||
fprintf(fptr, "%s", end); \
|
return true; \
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_EXT_CMC_HEAP_H */
|
#endif /* CMC_EXT_CMC_HEAP_H */
|
||||||
+255
-268
@@ -21,300 +21,287 @@
|
|||||||
/**
|
/**
|
||||||
* ITER
|
* ITER
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_ITER(PARAMS) \
|
#define CMC_EXT_CMC_INTERVALHEAP_ITER(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER(PARAMS) \
|
CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE(PARAMS)
|
CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER_( \
|
CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE_( \
|
CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_INTERVALHEAP_ITER_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* IntervalHeap Iterator */ \
|
/* IntervalHeap Iterator */ \
|
||||||
struct CMC_DEF_ITER(SNAME) \
|
struct CMC_DEF_ITER(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Target IntervalHeap */ \
|
/* Target IntervalHeap */ \
|
||||||
struct SNAME *target; \
|
struct SNAME *target; \
|
||||||
\
|
\
|
||||||
/* Cursor's position (index) */ \
|
/* Cursor's position (index) */ \
|
||||||
size_t cursor; \
|
size_t cursor; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the start of the iteration */ \
|
/* If the iterator has reached the start of the iteration */ \
|
||||||
bool start; \
|
bool start; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the end of the iteration */ \
|
/* If the iterator has reached the end of the iteration */ \
|
||||||
bool end; \
|
bool end; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Iterator Initialization */ \
|
/* Iterator Initialization */ \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
||||||
/* Iterator State */ \
|
/* Iterator State */ \
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Movement */ \
|
/* Iterator Movement */ \
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
size_t steps); \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \
|
||||||
size_t steps); \
|
/* Iterator Access */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
size_t index); \
|
|
||||||
/* Iterator Access */ \
|
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_INTERVALHEAP_ITER_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.start = true; \
|
iter.start = true; \
|
||||||
iter.end = CMC_(PFX, _empty)(target); \
|
iter.end = CMC_(PFX, _empty)(target); \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.start = CMC_(PFX, _empty)(target); \
|
iter.start = CMC_(PFX, _empty)(target); \
|
||||||
iter.end = true; \
|
iter.end = true; \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
iter.cursor = target->count - 1; \
|
iter.cursor = target->count - 1; \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = 0; \
|
iter->cursor = 0; \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = iter->target->count - 1; \
|
iter->cursor = iter->target->count - 1; \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->end) \
|
if (iter->end) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->cursor + 1 == iter->target->count) \
|
if (iter->cursor + 1 == iter->target->count) \
|
||||||
{ \
|
{ \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor++; \
|
iter->cursor++; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->start) \
|
if (iter->start) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->cursor == 0) \
|
if (iter->cursor == 0) \
|
||||||
{ \
|
{ \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor--; \
|
iter->cursor--; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* Returns true only if the iterator moved */ \
|
/* Returns true only if the iterator moved */ \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
size_t steps) \
|
{ \
|
||||||
{ \
|
if (iter->end) \
|
||||||
if (iter->end) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->cursor + 1 == iter->target->count) \
|
||||||
if (iter->cursor + 1 == iter->target->count) \
|
{ \
|
||||||
{ \
|
iter->end = true; \
|
||||||
iter->end = true; \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
||||||
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->end) \
|
||||||
if (iter->end) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
\
|
||||||
\
|
iter->cursor += steps; \
|
||||||
iter->cursor += steps; \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
/* Returns true only if the iterator moved */ \
|
||||||
/* Returns true only if the iterator moved */ \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
{ \
|
||||||
size_t steps) \
|
if (iter->start) \
|
||||||
{ \
|
return false; \
|
||||||
if (iter->start) \
|
\
|
||||||
return false; \
|
if (iter->cursor == 0) \
|
||||||
\
|
{ \
|
||||||
if (iter->cursor == 0) \
|
iter->start = true; \
|
||||||
{ \
|
return false; \
|
||||||
iter->start = true; \
|
} \
|
||||||
return false; \
|
\
|
||||||
} \
|
if (steps == 0 || iter->cursor < steps) \
|
||||||
\
|
return false; \
|
||||||
if (steps == 0 || iter->cursor < steps) \
|
\
|
||||||
return false; \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->cursor -= steps; \
|
||||||
\
|
\
|
||||||
iter->cursor -= steps; \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* Returns true only if the iterator was able to be positioned at the */ \
|
/* Returns true only if the iterator was able to be positioned at the */ \
|
||||||
/* given index */ \
|
/* given index */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \
|
||||||
size_t index) \
|
{ \
|
||||||
{ \
|
if (index >= iter->target->count) \
|
||||||
if (index >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->cursor > index) \
|
||||||
if (iter->cursor > index) \
|
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
||||||
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
else if (iter->cursor < index) \
|
||||||
else if (iter->cursor < index) \
|
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
||||||
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return (V){ 0 }; \
|
||||||
return (V){ 0 }; \
|
\
|
||||||
\
|
return iter->target->buffer[iter->cursor / 2][iter->cursor % 2]; \
|
||||||
return iter->target->buffer[iter->cursor / 2][iter->cursor % 2]; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
return iter->cursor; \
|
||||||
return iter->cursor; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STR
|
* STR
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_STR(PARAMS) \
|
#define CMC_EXT_CMC_INTERVALHEAP_STR(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_STR_HEADER(PARAMS) \
|
CMC_EXT_CMC_INTERVALHEAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE(PARAMS)
|
CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_STR_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_INTERVALHEAP_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_STR_HEADER_( \
|
CMC_EXT_CMC_INTERVALHEAP_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE_( \
|
CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_STR_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_INTERVALHEAP_STR_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr); \
|
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr); \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, \
|
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, const char *start, const char *separator, \
|
||||||
const char *start, const char *separator, \
|
|
||||||
const char *end);
|
const char *end);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_INTERVALHEAP_STR_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr) \
|
bool CMC_(PFX, _to_string)(struct SNAME * _heap_, FILE * fptr) \
|
||||||
{ \
|
{ \
|
||||||
struct SNAME *h_ = _heap_; \
|
struct SNAME *h_ = _heap_; \
|
||||||
\
|
\
|
||||||
return 0 <= fprintf(fptr, \
|
return 0 <= fprintf(fptr, \
|
||||||
"struct %s<%s> " \
|
"struct %s<%s> " \
|
||||||
"at %p { " \
|
"at %p { " \
|
||||||
"buffer:%p, " \
|
"buffer:%p, " \
|
||||||
"capacity:%" PRIuMAX ", " \
|
"capacity:%" PRIuMAX ", " \
|
||||||
"size:%" PRIuMAX ", " \
|
"size:%" PRIuMAX ", " \
|
||||||
"count:%" PRIuMAX ", " \
|
"count:%" PRIuMAX ", " \
|
||||||
"flag:%d, " \
|
"flag:%d, " \
|
||||||
"f_val:%p, " \
|
"f_val:%p, " \
|
||||||
"alloc:%p, " \
|
"alloc:%p, " \
|
||||||
"callbacks:%p }", \
|
"callbacks:%p }", \
|
||||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), h_, \
|
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), h_, h_->buffer, h_->capacity, h_->size, h_->count, \
|
||||||
h_->buffer, h_->capacity, h_->size, h_->count, \
|
h_->flag, h_->f_val, h_->alloc, CMC_CALLBACKS_GET(h_)); \
|
||||||
h_->flag, h_->f_val, h_->alloc, h_->callbacks); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, const char *start, const char *separator, \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _heap_, FILE * fptr, \
|
const char *end) \
|
||||||
const char *start, const char *separator, \
|
{ \
|
||||||
const char *end) \
|
fprintf(fptr, "%s", start); \
|
||||||
{ \
|
\
|
||||||
fprintf(fptr, "%s", start); \
|
for (size_t i = 0; i < _heap_->count; i++) \
|
||||||
\
|
{ \
|
||||||
for (size_t i = 0; i < _heap_->count; i++) \
|
if (!_heap_->f_val->str(fptr, _heap_->buffer[i / 2][i % 2])) \
|
||||||
{ \
|
return false; \
|
||||||
if (!_heap_->f_val->str(fptr, _heap_->buffer[i / 2][i % 2])) \
|
\
|
||||||
return false; \
|
if (i + 1 < _heap_->count) \
|
||||||
\
|
fprintf(fptr, "%s", separator); \
|
||||||
if (i + 1 < _heap_->count) \
|
} \
|
||||||
fprintf(fptr, "%s", separator); \
|
\
|
||||||
} \
|
fprintf(fptr, "%s", end); \
|
||||||
\
|
\
|
||||||
fprintf(fptr, "%s", end); \
|
return true; \
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_EXT_CMC_INTERVALHEAP_H */
|
#endif /* CMC_EXT_CMC_INTERVALHEAP_H */
|
||||||
+503
-543
File diff suppressed because it is too large.
Load diff
+434
-465
@@ -21,507 +21,476 @@
|
|||||||
/**
|
/**
|
||||||
* ITER
|
* ITER
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_LIST_ITER(PARAMS) \
|
#define CMC_EXT_CMC_LIST_ITER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_ITER_HEADER(PARAMS) \
|
CMC_EXT_CMC_LIST_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_ITER_SOURCE(PARAMS)
|
CMC_EXT_CMC_LIST_ITER_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_ITER_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_LIST_ITER_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_ITER_HEADER_( \
|
CMC_EXT_CMC_LIST_ITER_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_ITER_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_LIST_ITER_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_ITER_SOURCE_( \
|
CMC_EXT_CMC_LIST_ITER_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_ITER_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_LIST_ITER_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* List Iterator */ \
|
/* List Iterator */ \
|
||||||
struct CMC_DEF_ITER(SNAME) \
|
struct CMC_DEF_ITER(SNAME) \
|
||||||
{ \
|
{ \
|
||||||
/* Target List */ \
|
/* Target List */ \
|
||||||
struct SNAME *target; \
|
struct SNAME *target; \
|
||||||
\
|
\
|
||||||
/* Cursor's position (index) */ \
|
/* Cursor's position (index) */ \
|
||||||
size_t cursor; \
|
size_t cursor; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the start of the iteration */ \
|
/* If the iterator has reached the start of the iteration */ \
|
||||||
bool start; \
|
bool start; \
|
||||||
\
|
\
|
||||||
/* If the iterator has reached the end of the iteration */ \
|
/* If the iterator has reached the end of the iteration */ \
|
||||||
bool end; \
|
bool end; \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
/* Iterator Initialization */ \
|
/* Iterator Initialization */ \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target); \
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target); \
|
||||||
/* Iterator State */ \
|
/* Iterator State */ \
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Movement */ \
|
/* Iterator Movement */ \
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
size_t steps); \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps); \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index); \
|
||||||
size_t steps); \
|
/* Iterator Access */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
size_t index); \
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
||||||
/* Iterator Access */ \
|
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter); \
|
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_ITER_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_LIST_ITER_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_start)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.start = true; \
|
iter.start = true; \
|
||||||
iter.end = CMC_(PFX, _empty)(target); \
|
iter.end = CMC_(PFX, _empty)(target); \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
struct CMC_DEF_ITER(SNAME) CMC_(PFX, _iter_end)(struct SNAME * target) \
|
||||||
{ \
|
{ \
|
||||||
struct CMC_DEF_ITER(SNAME) iter; \
|
struct CMC_DEF_ITER(SNAME) iter; \
|
||||||
\
|
\
|
||||||
iter.target = target; \
|
iter.target = target; \
|
||||||
iter.cursor = 0; \
|
iter.cursor = 0; \
|
||||||
iter.start = CMC_(PFX, _empty)(target); \
|
iter.start = CMC_(PFX, _empty)(target); \
|
||||||
iter.end = true; \
|
iter.end = true; \
|
||||||
\
|
\
|
||||||
if (!CMC_(PFX, _empty)(target)) \
|
if (!CMC_(PFX, _empty)(target)) \
|
||||||
iter.cursor = target->count - 1; \
|
iter.cursor = target->count - 1; \
|
||||||
\
|
\
|
||||||
return iter; \
|
return iter; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
return CMC_(PFX, _empty)(iter->target) || iter->start; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_at_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
return CMC_(PFX, _empty)(iter->target) || iter->end; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_start)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->cursor = 0; \
|
iter->cursor = 0; \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_to_end)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (!CMC_(PFX, _empty)(iter->target)) \
|
if (!CMC_(PFX, _empty)(iter->target)) \
|
||||||
{ \
|
{ \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->cursor = iter->target->count - 1; \
|
iter->cursor = iter->target->count - 1; \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_next)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->end) \
|
if (iter->end) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->cursor + 1 == iter->target->count) \
|
if (iter->cursor + 1 == iter->target->count) \
|
||||||
{ \
|
{ \
|
||||||
iter->end = true; \
|
iter->end = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor++; \
|
iter->cursor++; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
bool CMC_(PFX, _iter_prev)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
{ \
|
{ \
|
||||||
if (iter->start) \
|
if (iter->start) \
|
||||||
return false; \
|
return false; \
|
||||||
\
|
\
|
||||||
if (iter->cursor == 0) \
|
if (iter->cursor == 0) \
|
||||||
{ \
|
{ \
|
||||||
iter->start = true; \
|
iter->start = true; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->cursor--; \
|
iter->cursor--; \
|
||||||
\
|
\
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* Returns true only if the iterator moved */ \
|
/* Returns true only if the iterator moved */ \
|
||||||
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_advance)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
size_t steps) \
|
{ \
|
||||||
{ \
|
if (iter->end) \
|
||||||
if (iter->end) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->cursor + 1 == iter->target->count) \
|
||||||
if (iter->cursor + 1 == iter->target->count) \
|
{ \
|
||||||
{ \
|
iter->end = true; \
|
||||||
iter->end = true; \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
||||||
if (steps == 0 || iter->cursor + steps >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
iter->start = CMC_(PFX, _empty)(iter->target); \
|
||||||
iter->start = CMC_(PFX, _empty)(iter->target); \
|
\
|
||||||
\
|
iter->cursor += steps; \
|
||||||
iter->cursor += steps; \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
/* Returns true only if the iterator moved */ \
|
||||||
/* Returns true only if the iterator moved */ \
|
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, size_t steps) \
|
||||||
bool CMC_(PFX, _iter_rewind)(struct CMC_DEF_ITER(SNAME) * iter, \
|
{ \
|
||||||
size_t steps) \
|
if (iter->start) \
|
||||||
{ \
|
return false; \
|
||||||
if (iter->start) \
|
\
|
||||||
return false; \
|
if (iter->cursor == 0) \
|
||||||
\
|
{ \
|
||||||
if (iter->cursor == 0) \
|
iter->start = true; \
|
||||||
{ \
|
return false; \
|
||||||
iter->start = true; \
|
} \
|
||||||
return false; \
|
\
|
||||||
} \
|
if (steps == 0 || iter->cursor < steps) \
|
||||||
\
|
return false; \
|
||||||
if (steps == 0 || iter->cursor < steps) \
|
\
|
||||||
return false; \
|
iter->end = CMC_(PFX, _empty)(iter->target); \
|
||||||
\
|
\
|
||||||
iter->end = CMC_(PFX, _empty)(iter->target); \
|
iter->cursor -= steps; \
|
||||||
\
|
\
|
||||||
iter->cursor -= steps; \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
|
||||||
\
|
|
||||||
/* Returns true only if the iterator was able to be positioned at the */ \
|
/* Returns true only if the iterator was able to be positioned at the */ \
|
||||||
/* given index */ \
|
/* given index */ \
|
||||||
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, \
|
bool CMC_(PFX, _iter_go_to)(struct CMC_DEF_ITER(SNAME) * iter, size_t index) \
|
||||||
size_t index) \
|
{ \
|
||||||
{ \
|
if (index >= iter->target->count) \
|
||||||
if (index >= iter->target->count) \
|
return false; \
|
||||||
return false; \
|
\
|
||||||
\
|
if (iter->cursor > index) \
|
||||||
if (iter->cursor > index) \
|
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
||||||
return CMC_(PFX, _iter_rewind)(iter, iter->cursor - index); \
|
else if (iter->cursor < index) \
|
||||||
else if (iter->cursor < index) \
|
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
||||||
return CMC_(PFX, _iter_advance)(iter, index - iter->cursor); \
|
\
|
||||||
\
|
return true; \
|
||||||
return true; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V CMC_(PFX, _iter_value)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return (V){ 0 }; \
|
||||||
return (V){ 0 }; \
|
\
|
||||||
\
|
return iter->target->buffer[iter->cursor]; \
|
||||||
return iter->target->buffer[iter->cursor]; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
V *CMC_(PFX, _iter_rvalue)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
if (CMC_(PFX, _empty)(iter->target)) \
|
||||||
if (CMC_(PFX, _empty)(iter->target)) \
|
return NULL; \
|
||||||
return NULL; \
|
\
|
||||||
\
|
return &(iter->target->buffer[iter->cursor]); \
|
||||||
return &(iter->target->buffer[iter->cursor]); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
||||||
size_t CMC_(PFX, _iter_index)(struct CMC_DEF_ITER(SNAME) * iter) \
|
{ \
|
||||||
{ \
|
return iter->cursor; \
|
||||||
return iter->cursor; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SEQ
|
* SEQ
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_LIST_SEQ(PARAMS) \
|
#define CMC_EXT_CMC_LIST_SEQ(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_SEQ_HEADER(PARAMS) \
|
CMC_EXT_CMC_LIST_SEQ_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_SEQ_SOURCE(PARAMS)
|
CMC_EXT_CMC_LIST_SEQ_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_SEQ_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_LIST_SEQ_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_SEQ_HEADER_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_LIST_SEQ_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_SEQ_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_LIST_SEQ_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_SEQ_SOURCE_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_LIST_SEQ_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_SEQ_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_LIST_SEQ_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
/* List Sequence Input and Output */ \
|
/* List Sequence Input and Output */ \
|
||||||
bool CMC_(PFX, _seq_push_front)(struct SNAME * _list_, V * values, \
|
bool CMC_(PFX, _seq_push_front)(struct SNAME * _list_, V * values, size_t size); \
|
||||||
size_t size); \
|
bool CMC_(PFX, _seq_push_at)(struct SNAME * _list_, V * values, size_t size, size_t index); \
|
||||||
bool CMC_(PFX, _seq_push_at)(struct SNAME * _list_, V * values, \
|
bool CMC_(PFX, _seq_push_back)(struct SNAME * _list_, V * values, size_t size); \
|
||||||
size_t size, size_t index); \
|
bool CMC_(PFX, _seq_pop_at)(struct SNAME * _list_, size_t from, size_t to); \
|
||||||
bool CMC_(PFX, _seq_push_back)(struct SNAME * _list_, V * values, \
|
struct SNAME *CMC_(PFX, _seq_sublist)(struct SNAME * _list_, size_t from, size_t to);
|
||||||
size_t size); \
|
|
||||||
bool CMC_(PFX, _seq_pop_at)(struct SNAME * _list_, size_t from, \
|
|
||||||
size_t to); \
|
|
||||||
struct SNAME *CMC_(PFX, _seq_sublist)(struct SNAME * _list_, size_t from, \
|
|
||||||
size_t to);
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_SEQ_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_LIST_SEQ_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _seq_push_front)(struct SNAME * _list_, V * values, \
|
bool CMC_(PFX, _seq_push_front)(struct SNAME * _list_, V * values, size_t size) \
|
||||||
size_t size) \
|
{ \
|
||||||
{ \
|
if (size == 0) \
|
||||||
if (size == 0) \
|
{ \
|
||||||
{ \
|
_list_->flag = CMC_FLAG_INVALID; \
|
||||||
_list_->flag = CMC_FLAG_INVALID; \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
if (!CMC_(PFX, _fits)(_list_, size)) \
|
||||||
if (!CMC_(PFX, _fits)(_list_, size)) \
|
{ \
|
||||||
{ \
|
if (!CMC_(PFX, _resize)(_list_, _list_->count + size)) \
|
||||||
if (!CMC_(PFX, _resize)(_list_, _list_->count + size)) \
|
return false; \
|
||||||
return false; \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
memmove(_list_->buffer + size, _list_->buffer, _list_->count * sizeof(V)); \
|
||||||
memmove(_list_->buffer + size, _list_->buffer, \
|
\
|
||||||
_list_->count * sizeof(V)); \
|
memcpy(_list_->buffer, values, size * sizeof(V)); \
|
||||||
\
|
\
|
||||||
memcpy(_list_->buffer, values, size * sizeof(V)); \
|
_list_->count += size; \
|
||||||
\
|
_list_->flag = CMC_FLAG_OK; \
|
||||||
_list_->count += size; \
|
\
|
||||||
_list_->flag = CMC_FLAG_OK; \
|
if (_list_->callbacks && _list_->callbacks->create) \
|
||||||
\
|
_list_->callbacks->create(); \
|
||||||
if (_list_->callbacks && _list_->callbacks->create) \
|
\
|
||||||
_list_->callbacks->create(); \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
bool CMC_(PFX, _seq_push_at)(struct SNAME * _list_, V * values, size_t size, size_t index) \
|
||||||
\
|
{ \
|
||||||
bool CMC_(PFX, _seq_push_at)(struct SNAME * _list_, V * values, \
|
if (size == 0) \
|
||||||
size_t size, size_t index) \
|
{ \
|
||||||
{ \
|
_list_->flag = CMC_FLAG_INVALID; \
|
||||||
if (size == 0) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
_list_->flag = CMC_FLAG_INVALID; \
|
\
|
||||||
return false; \
|
if (index > _list_->count) \
|
||||||
} \
|
{ \
|
||||||
\
|
_list_->flag = CMC_FLAG_RANGE; \
|
||||||
if (index > _list_->count) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
_list_->flag = CMC_FLAG_RANGE; \
|
\
|
||||||
return false; \
|
if (index == 0) \
|
||||||
} \
|
return CMC_(PFX, _seq_push_front)(_list_, values, size); \
|
||||||
\
|
else if (index == _list_->count) \
|
||||||
if (index == 0) \
|
return CMC_(PFX, _seq_push_back)(_list_, values, size); \
|
||||||
return CMC_(PFX, _seq_push_front)(_list_, values, size); \
|
\
|
||||||
else if (index == _list_->count) \
|
if (!CMC_(PFX, _fits)(_list_, size)) \
|
||||||
return CMC_(PFX, _seq_push_back)(_list_, values, size); \
|
{ \
|
||||||
\
|
if (!CMC_(PFX, _resize)(_list_, _list_->count + size)) \
|
||||||
if (!CMC_(PFX, _fits)(_list_, size)) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
if (!CMC_(PFX, _resize)(_list_, _list_->count + size)) \
|
\
|
||||||
return false; \
|
memmove(_list_->buffer + index + size, _list_->buffer + index, (_list_->count - index) * sizeof(V)); \
|
||||||
} \
|
\
|
||||||
\
|
memcpy(_list_->buffer + index, values, size * sizeof(V)); \
|
||||||
memmove(_list_->buffer + index + size, _list_->buffer + index, \
|
\
|
||||||
(_list_->count - index) * sizeof(V)); \
|
_list_->count += size; \
|
||||||
\
|
_list_->flag = CMC_FLAG_OK; \
|
||||||
memcpy(_list_->buffer + index, values, size * sizeof(V)); \
|
\
|
||||||
\
|
if (_list_->callbacks && _list_->callbacks->create) \
|
||||||
_list_->count += size; \
|
_list_->callbacks->create(); \
|
||||||
_list_->flag = CMC_FLAG_OK; \
|
\
|
||||||
\
|
return true; \
|
||||||
if (_list_->callbacks && _list_->callbacks->create) \
|
} \
|
||||||
_list_->callbacks->create(); \
|
\
|
||||||
\
|
bool CMC_(PFX, _seq_push_back)(struct SNAME * _list_, V * values, size_t size) \
|
||||||
return true; \
|
{ \
|
||||||
} \
|
if (size == 0) \
|
||||||
\
|
{ \
|
||||||
bool CMC_(PFX, _seq_push_back)(struct SNAME * _list_, V * values, \
|
_list_->flag = CMC_FLAG_INVALID; \
|
||||||
size_t size) \
|
return false; \
|
||||||
{ \
|
} \
|
||||||
if (size == 0) \
|
\
|
||||||
{ \
|
if (!CMC_(PFX, _fits)(_list_, size)) \
|
||||||
_list_->flag = CMC_FLAG_INVALID; \
|
{ \
|
||||||
return false; \
|
if (!CMC_(PFX, _resize)(_list_, _list_->count + size)) \
|
||||||
} \
|
return false; \
|
||||||
\
|
} \
|
||||||
if (!CMC_(PFX, _fits)(_list_, size)) \
|
\
|
||||||
{ \
|
memcpy(_list_->buffer + _list_->count, values, size * sizeof(V)); \
|
||||||
if (!CMC_(PFX, _resize)(_list_, _list_->count + size)) \
|
\
|
||||||
return false; \
|
_list_->count += size; \
|
||||||
} \
|
_list_->flag = CMC_FLAG_OK; \
|
||||||
\
|
\
|
||||||
memcpy(_list_->buffer + _list_->count, values, size * sizeof(V)); \
|
if (_list_->callbacks && _list_->callbacks->create) \
|
||||||
\
|
_list_->callbacks->create(); \
|
||||||
_list_->count += size; \
|
\
|
||||||
_list_->flag = CMC_FLAG_OK; \
|
return true; \
|
||||||
\
|
} \
|
||||||
if (_list_->callbacks && _list_->callbacks->create) \
|
\
|
||||||
_list_->callbacks->create(); \
|
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
bool CMC_(PFX, _seq_pop_at)(struct SNAME * _list_, size_t from, size_t to) \
|
bool CMC_(PFX, _seq_pop_at)(struct SNAME * _list_, size_t from, size_t to) \
|
||||||
{ \
|
{ \
|
||||||
if (from > to) \
|
if (from > to) \
|
||||||
{ \
|
{ \
|
||||||
_list_->flag = CMC_FLAG_INVALID; \
|
_list_->flag = CMC_FLAG_INVALID; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if (to >= _list_->count) \
|
if (to >= _list_->count) \
|
||||||
{ \
|
{ \
|
||||||
_list_->flag = CMC_FLAG_RANGE; \
|
_list_->flag = CMC_FLAG_RANGE; \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
size_t length = (to - from + 1); \
|
size_t length = (to - from + 1); \
|
||||||
\
|
\
|
||||||
memmove(_list_->buffer + from, _list_->buffer + to + 1, \
|
memmove(_list_->buffer + from, _list_->buffer + to + 1, (_list_->count - to - 1) * sizeof(V)); \
|
||||||
(_list_->count - to - 1) * sizeof(V)); \
|
\
|
||||||
\
|
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(V)); \
|
||||||
memset(_list_->buffer + _list_->count - length, 0, \
|
\
|
||||||
length * sizeof(V)); \
|
_list_->count -= to - from + 1; \
|
||||||
\
|
_list_->flag = CMC_FLAG_OK; \
|
||||||
_list_->count -= to - from + 1; \
|
\
|
||||||
_list_->flag = CMC_FLAG_OK; \
|
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||||
\
|
_list_->callbacks->delete (); \
|
||||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
\
|
||||||
_list_->callbacks->delete (); \
|
return true; \
|
||||||
\
|
} \
|
||||||
return true; \
|
\
|
||||||
} \
|
struct SNAME *CMC_(PFX, _seq_sublist)(struct SNAME * _list_, size_t from, size_t to) \
|
||||||
\
|
{ \
|
||||||
struct SNAME *CMC_(PFX, _seq_sublist)(struct SNAME * _list_, size_t from, \
|
if (from > to) \
|
||||||
size_t to) \
|
{ \
|
||||||
{ \
|
_list_->flag = CMC_FLAG_INVALID; \
|
||||||
if (from > to) \
|
return NULL; \
|
||||||
{ \
|
} \
|
||||||
_list_->flag = CMC_FLAG_INVALID; \
|
\
|
||||||
return NULL; \
|
if (to >= _list_->count) \
|
||||||
} \
|
{ \
|
||||||
\
|
_list_->flag = CMC_FLAG_RANGE; \
|
||||||
if (to >= _list_->count) \
|
return NULL; \
|
||||||
{ \
|
} \
|
||||||
_list_->flag = CMC_FLAG_RANGE; \
|
\
|
||||||
return NULL; \
|
size_t length = to - from + 1; \
|
||||||
} \
|
\
|
||||||
\
|
struct SNAME *result = CMC_(PFX, _new_custom)(length, _list_->f_val, _list_->alloc, _list_->callbacks); \
|
||||||
size_t length = to - from + 1; \
|
\
|
||||||
\
|
if (!result) \
|
||||||
struct SNAME *result = CMC_(PFX, _new_custom)( \
|
{ \
|
||||||
length, _list_->f_val, _list_->alloc, _list_->callbacks); \
|
_list_->flag = CMC_FLAG_ALLOC; \
|
||||||
\
|
return NULL; \
|
||||||
if (!result) \
|
} \
|
||||||
{ \
|
\
|
||||||
_list_->flag = CMC_FLAG_ALLOC; \
|
memcpy(result->buffer, _list_->buffer, length * sizeof(V)); \
|
||||||
return NULL; \
|
\
|
||||||
} \
|
memmove(_list_->buffer + from, _list_->buffer + to + 1, (_list_->count - to - 1) * sizeof(V)); \
|
||||||
\
|
\
|
||||||
memcpy(result->buffer, _list_->buffer, length * sizeof(V)); \
|
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(V)); \
|
||||||
\
|
\
|
||||||
memmove(_list_->buffer + from, _list_->buffer + to + 1, \
|
_list_->count -= length; \
|
||||||
(_list_->count - to - 1) * sizeof(V)); \
|
result->count = length; \
|
||||||
\
|
\
|
||||||
memset(_list_->buffer + _list_->count - length, 0, \
|
_list_->flag = CMC_FLAG_OK; \
|
||||||
length * sizeof(V)); \
|
\
|
||||||
\
|
if (_list_->callbacks && _list_->callbacks->delete) \
|
||||||
_list_->count -= length; \
|
_list_->callbacks->delete (); \
|
||||||
result->count = length; \
|
\
|
||||||
\
|
return result; \
|
||||||
_list_->flag = CMC_FLAG_OK; \
|
|
||||||
\
|
|
||||||
if (_list_->callbacks && _list_->callbacks->delete) \
|
|
||||||
_list_->callbacks->delete (); \
|
|
||||||
\
|
|
||||||
return result; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STR
|
* STR
|
||||||
*/
|
*/
|
||||||
#define CMC_EXT_CMC_LIST_STR(PARAMS) \
|
#define CMC_EXT_CMC_LIST_STR(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_STR_HEADER(PARAMS) \
|
CMC_EXT_CMC_LIST_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_STR_SOURCE(PARAMS)
|
CMC_EXT_CMC_LIST_STR_SOURCE(PARAMS)
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_STR_HEADER(PARAMS) \
|
#define CMC_EXT_CMC_LIST_STR_HEADER(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_STR_HEADER_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_LIST_STR_HEADER_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_STR_SOURCE(PARAMS) \
|
#define CMC_EXT_CMC_LIST_STR_SOURCE(PARAMS) \
|
||||||
CMC_EXT_CMC_LIST_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), \
|
CMC_EXT_CMC_LIST_STR_SOURCE_(CMC_PARAM_PFX(PARAMS), CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
||||||
CMC_PARAM_SNAME(PARAMS), CMC_PARAM_V(PARAMS))
|
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_STR_HEADER_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_LIST_STR_HEADER_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _list_, FILE * fptr); \
|
bool CMC_(PFX, _to_string)(struct SNAME * _list_, FILE * fptr); \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr, \
|
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr, const char *start, const char *separator, \
|
||||||
const char *start, const char *separator, \
|
|
||||||
const char *end);
|
const char *end);
|
||||||
|
|
||||||
#define CMC_EXT_CMC_LIST_STR_SOURCE_(PFX, SNAME, V) \
|
#define CMC_EXT_CMC_LIST_STR_SOURCE_(PFX, SNAME, V) \
|
||||||
\
|
\
|
||||||
bool CMC_(PFX, _to_string)(struct SNAME * _list_, FILE * fptr) \
|
bool CMC_(PFX, _to_string)(struct SNAME * _list_, FILE * fptr) \
|
||||||
{ \
|
{ \
|
||||||
struct SNAME *l_ = _list_; \
|
struct SNAME *l_ = _list_; \
|
||||||
\
|
\
|
||||||
return 0 <= fprintf(fptr, \
|
return 0 <= fprintf(fptr, \
|
||||||
"struct %s<%s> " \
|
"struct %s<%s> " \
|
||||||
"at %p { " \
|
"at %p { " \
|
||||||
"buffer:%p, " \
|
"buffer:%p, " \
|
||||||
"capacity:%" PRIuMAX ", " \
|
"capacity:%" PRIuMAX ", " \
|
||||||
"count:%" PRIuMAX ", " \
|
"count:%" PRIuMAX ", " \
|
||||||
"flag:%d, " \
|
"flag:%d, " \
|
||||||
"f_val:%p, " \
|
"f_val:%p, " \
|
||||||
"alloc:%p, " \
|
"alloc:%p, " \
|
||||||
"callbacks:%p }", \
|
"callbacks:%p }", \
|
||||||
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), l_, \
|
CMC_TO_STRING(SNAME), CMC_TO_STRING(V), l_, l_->buffer, l_->capacity, l_->count, l_->flag, \
|
||||||
l_->buffer, l_->capacity, l_->count, l_->flag, \
|
l_->f_val, l_->alloc, CMC_CALLBACKS_GET(l_)); \
|
||||||
l_->f_val, l_->alloc, l_->callbacks); \
|
} \
|
||||||
} \
|
\
|
||||||
\
|
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr, const char *start, const char *separator, \
|
||||||
bool CMC_(PFX, _print)(struct SNAME * _list_, FILE * fptr, \
|
const char *end) \
|
||||||
const char *start, const char *separator, \
|
{ \
|
||||||
const char *end) \
|
fprintf(fptr, "%s", start); \
|
||||||
{ \
|
\
|
||||||
fprintf(fptr, "%s", start); \
|
for (size_t i = 0; i < _list_->count; i++) \
|
||||||
\
|
{ \
|
||||||
for (size_t i = 0; i < _list_->count; i++) \
|
if (!_list_->f_val->str(fptr, _list_->buffer[i])) \
|
||||||
{ \
|
return false; \
|
||||||
if (!_list_->f_val->str(fptr, _list_->buffer[i])) \
|
\
|
||||||
return false; \
|
if (i + 1 < _list_->count) \
|
||||||
\
|
fprintf(fptr, "%s", separator); \
|
||||||
if (i + 1 < _list_->count) \
|
} \
|
||||||
fprintf(fptr, "%s", separator); \
|
\
|
||||||
} \
|
fprintf(fptr, "%s", end); \
|
||||||
\
|
\
|
||||||
fprintf(fptr, "%s", end); \
|
return true; \
|
||||||
\
|
|
||||||
return true; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CMC_EXT_CMC_LIST_H */
|
#endif /* CMC_EXT_CMC_LIST_H */
|
||||||
+28
-35
@@ -86,8 +86,7 @@
|
|||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
#define C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
C_MACRO_COLLECTIONS_(LIB, COLLECTION, PART, FILE)(PARAMS)
|
C_MACRO_COLLECTIONS_(LIB, COLLECTION, PART, FILE)(PARAMS)
|
||||||
#define C_MACRO_COLLECTIONS_(LIB, COLLECTION, PART, FILE) \
|
#define C_MACRO_COLLECTIONS_(LIB, COLLECTION, PART, FILE) CMC_##LIB##_##COLLECTION##_##PART##_##FILE
|
||||||
CMC_##LIB##_##COLLECTION##_##PART##_##FILE
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C_MACRO_COLLECTIONS_GEN
|
* C_MACRO_COLLECTIONS_GEN
|
||||||
@@ -100,7 +99,7 @@
|
|||||||
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V)
|
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V)
|
||||||
* \param PARTS A non-empty tuple of all desired EXT parts
|
* \param PARTS A non-empty tuple of all desired EXT parts
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_GEN(LIB, COLLECTION, PARAMS, PARTS) \
|
#define C_MACRO_COLLECTIONS_GEN(LIB, COLLECTION, PARAMS, PARTS) \
|
||||||
C_MACRO_COLLECTIONS_GEN_HEADER(LIB, COLLECTION, PARAMS, PARTS) \
|
C_MACRO_COLLECTIONS_GEN_HEADER(LIB, COLLECTION, PARAMS, PARTS) \
|
||||||
C_MACRO_COLLECTIONS_GEN_SOURCE(LIB, COLLECTION, PARAMS, PARTS)
|
C_MACRO_COLLECTIONS_GEN_SOURCE(LIB, COLLECTION, PARAMS, PARTS)
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@
|
|||||||
* \param PARTS A non-empty tuple of all desired EXT parts
|
* \param PARTS A non-empty tuple of all desired EXT parts
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_GEN_HEADER(LIB, COLLECTION, PARAMS, PARTS) \
|
#define C_MACRO_COLLECTIONS_GEN_HEADER(LIB, COLLECTION, PARAMS, PARTS) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, HEADER, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, HEADER, PARAMS) \
|
||||||
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, HEADER, PARAMS, CMC_EVAL PARTS)
|
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, HEADER, PARAMS, CMC_EVAL PARTS)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,7 +128,7 @@
|
|||||||
* \param PARTS A non-empty tuple of all desired EXT parts
|
* \param PARTS A non-empty tuple of all desired EXT parts
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_GEN_SOURCE(LIB, COLLECTION, PARAMS, PARTS) \
|
#define C_MACRO_COLLECTIONS_GEN_SOURCE(LIB, COLLECTION, PARAMS, PARTS) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, SOURCE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, SOURCE, PARAMS) \
|
||||||
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, SOURCE, PARAMS, CMC_EVAL PARTS)
|
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, SOURCE, PARAMS, CMC_EVAL PARTS)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,7 +141,7 @@
|
|||||||
* \param COLLECTION The name of the collection in all uppercase
|
* \param COLLECTION The name of the collection in all uppercase
|
||||||
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V
|
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_ALL(LIB, COLLECTION, PARAMS) \
|
#define C_MACRO_COLLECTIONS_ALL(LIB, COLLECTION, PARAMS) \
|
||||||
C_MACRO_COLLECTIONS_ALL_HEADER(LIB, COLLECTION, PARAMS) \
|
C_MACRO_COLLECTIONS_ALL_HEADER(LIB, COLLECTION, PARAMS) \
|
||||||
C_MACRO_COLLECTIONS_ALL_SOURCE(LIB, COLLECTION, PARAMS)
|
C_MACRO_COLLECTIONS_ALL_SOURCE(LIB, COLLECTION, PARAMS)
|
||||||
|
|
||||||
@@ -156,9 +155,8 @@
|
|||||||
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V
|
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_ALL_HEADER(LIB, COLLECTION, PARAMS) \
|
#define C_MACRO_COLLECTIONS_ALL_HEADER(LIB, COLLECTION, PARAMS) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, HEADER, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, HEADER, PARAMS) \
|
||||||
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, HEADER, PARAMS, \
|
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, HEADER, PARAMS, C_MACRO_COLLECTIONS_PARTS(LIB, COLLECTION))
|
||||||
C_MACRO_COLLECTIONS_PARTS(LIB, COLLECTION))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C_MACRO_COLLECTIONS_ALL_SOURCE
|
* C_MACRO_COLLECTIONS_ALL_SOURCE
|
||||||
@@ -170,9 +168,8 @@
|
|||||||
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V
|
* \param PARAMS A tuple of form (PFX, SNAME, SIZE, K, V
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_ALL_SOURCE(LIB, COLLECTION, PARAMS) \
|
#define C_MACRO_COLLECTIONS_ALL_SOURCE(LIB, COLLECTION, PARAMS) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, SOURCE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, CORE, SOURCE, PARAMS) \
|
||||||
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, SOURCE, PARAMS, \
|
CMC_MAP(CMC_(EXT_, LIB), COLLECTION, SOURCE, PARAMS, C_MACRO_COLLECTIONS_PARTS(LIB, COLLECTION))
|
||||||
C_MACRO_COLLECTIONS_PARTS(LIB, COLLECTION))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C_MACRO_COLLECTIONS_PARTS
|
* C_MACRO_COLLECTIONS_PARTS
|
||||||
@@ -180,8 +177,7 @@
|
|||||||
* Gets the macro with all EXT parts of a collection. Every collection has this
|
* Gets the macro with all EXT parts of a collection. Every collection has this
|
||||||
* macro defined in the EXT libraries.
|
* macro defined in the EXT libraries.
|
||||||
*/
|
*/
|
||||||
#define C_MACRO_COLLECTIONS_PARTS(LIB, COLLECTION) \
|
#define C_MACRO_COLLECTIONS_PARTS(LIB, COLLECTION) CMC_EXT_##LIB##_##COLLECTION##_PARTS,
|
||||||
CMC_EXT_##LIB##_##COLLECTION##_PARTS,
|
|
||||||
|
|
||||||
/* Evaluates a tuple so that (A, B) -> A, B, */
|
/* Evaluates a tuple so that (A, B) -> A, B, */
|
||||||
#define CMC_EVAL(...) __VA_ARGS__,
|
#define CMC_EVAL(...) __VA_ARGS__,
|
||||||
@@ -195,50 +191,47 @@
|
|||||||
*/
|
*/
|
||||||
#define CMC_NARG(...) CMC_NARG_(__VA_ARGS__, CMC_SEQ_N())
|
#define CMC_NARG(...) CMC_NARG_(__VA_ARGS__, CMC_SEQ_N())
|
||||||
#define CMC_NARG_(...) CMC_ARG_N(__VA_ARGS__)
|
#define CMC_NARG_(...) CMC_ARG_N(__VA_ARGS__)
|
||||||
#define CMC_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, \
|
#define CMC_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, \
|
||||||
_14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, \
|
_22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, \
|
||||||
_26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, \
|
_42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, \
|
||||||
_38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, \
|
_62, _63, N, ...) \
|
||||||
_50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, \
|
|
||||||
_62, _63, N, ...) \
|
|
||||||
N
|
N
|
||||||
#define CMC_SEQ_N() \
|
#define CMC_SEQ_N() \
|
||||||
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, \
|
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, \
|
||||||
45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, \
|
35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, \
|
||||||
28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, \
|
7, 6, 5, 4, 3, 2, 1, 0
|
||||||
11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
|
||||||
|
|
||||||
/* Generates the FILE for each part (__VA_ARGS__) of a collection */
|
/* Generates the FILE for each part (__VA_ARGS__) of a collection */
|
||||||
#define CMC_MAP(LIB, COLLECTION, FILE, PARAMS, ...) \
|
#define CMC_MAP(LIB, COLLECTION, FILE, PARAMS, ...) \
|
||||||
CMC_(CMC_MAP_, CMC_NARG(__VA_ARGS__)) \
|
CMC_(CMC_MAP_, CMC_NARG(__VA_ARGS__)) \
|
||||||
(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
|
|
||||||
#define CMC_MAP_0(LIB, COLLECTION, FILE, PARAMS, PART, ...)
|
#define CMC_MAP_0(LIB, COLLECTION, FILE, PARAMS, PART, ...)
|
||||||
#define CMC_MAP_1(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_1(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_0(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_0(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_2(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_2(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_1(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_1(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_3(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_3(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_2(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_2(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_4(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_4(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_3(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_3(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_5(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_5(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_4(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_4(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_6(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_6(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_5(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_5(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_7(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_7(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_6(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_6(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_8(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_8(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_7(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_7(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_9(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_9(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
C_MACRO_COLLECTIONS(LIB, COLLECTION, PART, FILE, PARAMS) \
|
||||||
CMC_MAP_8(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
CMC_MAP_8(LIB, COLLECTION, FILE, PARAMS, __VA_ARGS__)
|
||||||
#define CMC_MAP_10(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
#define CMC_MAP_10(LIB, COLLECTION, FILE, PARAMS, PART, ...) \
|
||||||
|
|||||||
+2114
-2335
File diff suppressed because it is too large.
Load diff
+4
-6
@@ -22,14 +22,12 @@
|
|||||||
|
|
||||||
#include "../cor/core.h"
|
#include "../cor/core.h"
|
||||||
|
|
||||||
#define CMC_FOREACH(PFX, SNAME, ITERNAME, TARGET) \
|
#define CMC_FOREACH(PFX, SNAME, ITERNAME, TARGET) \
|
||||||
for (struct CMC_DEF_ITER(SNAME) ITERNAME = CMC_(PFX, _iter_start)(TARGET); \
|
for (struct CMC_DEF_ITER(SNAME) ITERNAME = CMC_(PFX, _iter_start)(TARGET); !CMC_(PFX, _iter_at_end)(&ITERNAME); \
|
||||||
!CMC_(PFX, _iter_at_end)(&ITERNAME); \
|
|
||||||
CMC_(PFX, _iter_next)(&ITERNAME))
|
CMC_(PFX, _iter_next)(&ITERNAME))
|
||||||
|
|
||||||
#define CMC_FOREACH_REV(PFX, SNAME, ITERNAME, TARGET) \
|
#define CMC_FOREACH_REV(PFX, SNAME, ITERNAME, TARGET) \
|
||||||
for (struct CMC_DEF_ITER(SNAME) ITERNAME = CMC_(PFX, _iter_end)(TARGET); \
|
for (struct CMC_DEF_ITER(SNAME) ITERNAME = CMC_(PFX, _iter_end)(TARGET); !CMC_(PFX, _iter_at_start)(&ITERNAME); \
|
||||||
!CMC_(PFX, _iter_at_start)(&ITERNAME); \
|
|
||||||
CMC_(PFX, _iter_prev)(&ITERNAME))
|
CMC_(PFX, _iter_prev)(&ITERNAME))
|
||||||
|
|
||||||
#endif /* CMC_UTL_FOREACH_H */
|
#endif /* CMC_UTL_FOREACH_H */
|
||||||
+13
-24
@@ -66,12 +66,10 @@
|
|||||||
|
|
||||||
#include "../cor/core.h"
|
#include "../cor/core.h"
|
||||||
|
|
||||||
static const char *cmc_log_names[] = { "TRACE", "DEBUG", "INFO",
|
static const char *cmc_log_names[] = { "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" };
|
||||||
"WARN", "ERROR", "FATAL" };
|
|
||||||
|
|
||||||
#ifdef CMC_LOG_COLOR
|
#ifdef CMC_LOG_COLOR
|
||||||
static const char *cmc_log_color[] = { "\x1b[94m", "\x1b[36m", "\x1b[32m",
|
static const char *cmc_log_color[] = { "\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m" };
|
||||||
"\x1b[33m", "\x1b[31m", "\x1b[35m" };
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum cmc_log_type
|
enum cmc_log_type
|
||||||
@@ -95,21 +93,14 @@ static struct
|
|||||||
|
|
||||||
} cmc_log_config = { 0, 0, true, true, true, NULL };
|
} cmc_log_config = { 0, 0, true, true, true, NULL };
|
||||||
|
|
||||||
#define cmc_log_trace(fmt, ...) \
|
#define cmc_log_trace(fmt, ...) cmc_log(CMC_LOG_TRACE, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
cmc_log(CMC_LOG_TRACE, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
#define cmc_log_debug(fmt, ...) cmc_log(CMC_LOG_DEBUG, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
#define cmc_log_debug(fmt, ...) \
|
#define cmc_log_info(fmt, ...) cmc_log(CMC_LOG_INFO, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
cmc_log(CMC_LOG_DEBUG, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
#define cmc_log_warn(fmt, ...) cmc_log(CMC_LOG_WARN, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
#define cmc_log_info(fmt, ...) \
|
#define cmc_log_error(fmt, ...) cmc_log(CMC_LOG_ERROR, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
cmc_log(CMC_LOG_INFO, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
#define cmc_log_fatal(fmt, ...) cmc_log(CMC_LOG_FATAL, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
#define cmc_log_warn(fmt, ...) \
|
|
||||||
cmc_log(CMC_LOG_WARN, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
|
||||||
#define cmc_log_error(fmt, ...) \
|
|
||||||
cmc_log(CMC_LOG_ERROR, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
|
||||||
#define cmc_log_fatal(fmt, ...) \
|
|
||||||
cmc_log(CMC_LOG_FATAL, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
CMC_UNUSED static void cmc_log(enum cmc_log_type log, const char *filename,
|
CMC_UNUSED static void cmc_log(enum cmc_log_type log, const char *filename, const char *funcname, unsigned line,
|
||||||
const char *funcname, unsigned line,
|
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (!cmc_log_config.enabled)
|
if (!cmc_log_config.enabled)
|
||||||
@@ -133,11 +124,10 @@ CMC_UNUSED static void cmc_log(enum cmc_log_type log, const char *filename,
|
|||||||
time[strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", lt)] = '\0';
|
time[strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", lt)] = '\0';
|
||||||
|
|
||||||
#ifdef CMC_LOG_COLOR
|
#ifdef CMC_LOG_COLOR
|
||||||
fprintf(stderr, "%s %s%5s\x1b[0m at\x1b[90m %s:%s:%u\x1b[0m | ", time,
|
fprintf(stderr, "%s %s%5s\x1b[0m at\x1b[90m %s:%s:%u\x1b[0m | ", time, cmc_log_color[i], cmc_log_names[i],
|
||||||
cmc_log_color[i], cmc_log_names[i], filename, funcname, line);
|
|
||||||
#else
|
|
||||||
fprintf(stderr, "%s %5s at %s:%s:%u | ", time, cmc_log_names[i],
|
|
||||||
filename, funcname, line);
|
filename, funcname, line);
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "%s %5s at %s:%s:%u | ", time, cmc_log_names[i], filename, funcname, line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -168,8 +158,7 @@ skip:
|
|||||||
char time[32];
|
char time[32];
|
||||||
time[strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", lt)] = '\0';
|
time[strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", lt)] = '\0';
|
||||||
|
|
||||||
fprintf(cmc_log_config.file, "%s %5s at %s:%s:%u | ", time,
|
fprintf(cmc_log_config.file, "%s %5s at %s:%s:%u | ", time, cmc_log_names[i], filename, funcname, line);
|
||||||
cmc_log_names[i], filename, funcname, line);
|
|
||||||
|
|
||||||
va_list file_args;
|
va_list file_args;
|
||||||
va_start(file_args, fmt);
|
va_start(file_args, fmt);
|
||||||
|
|||||||
+122
-133
@@ -66,9 +66,7 @@ static inline const char *cmc_test_color(int i)
|
|||||||
// 3 - Box (gray)
|
// 3 - Box (gray)
|
||||||
// 4 - Name (cyan)
|
// 4 - Name (cyan)
|
||||||
// 5 - Total (yellow)
|
// 5 - Total (yellow)
|
||||||
static const char *cmc_test_colors[] = {
|
static const char *cmc_test_colors[] = { "\x1b[0m", "\x1b[31m", "\x1b[32m", "\x1b[90m", "\x1b[36m", "\x1b[33m" };
|
||||||
"\x1b[0m", "\x1b[31m", "\x1b[32m", "\x1b[90m", "\x1b[36m", "\x1b[33m"
|
|
||||||
};
|
|
||||||
return cmc_test_colors[i];
|
return cmc_test_colors[i];
|
||||||
#else
|
#else
|
||||||
static inline const char *cmc_test_color(int i)
|
static inline const char *cmc_test_color(int i)
|
||||||
@@ -79,9 +77,7 @@ static inline const char *cmc_test_color(int i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Logging function */
|
/* Logging function */
|
||||||
CMC_UNUSED static void cmc_test_log(const char *unit_name,
|
CMC_UNUSED static void cmc_test_log(const char *unit_name, const char *current_test, bool aborted, bool passed)
|
||||||
const char *current_test, bool aborted,
|
|
||||||
bool passed)
|
|
||||||
{
|
{
|
||||||
if (aborted)
|
if (aborted)
|
||||||
{
|
{
|
||||||
@@ -110,139 +106,132 @@ CMC_UNUSED static void cmc_test_log(const char *unit_name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY) \
|
#define CMC_CREATE_UNIT(UNAME, VERBOSE, BODY) \
|
||||||
uintmax_t UNAME(void) \
|
uintmax_t UNAME(void) \
|
||||||
{ \
|
{ \
|
||||||
const char *unit_name = #UNAME; \
|
const char *unit_name = #UNAME; \
|
||||||
const char *current_test = NULL; \
|
const char *current_test = NULL; \
|
||||||
\
|
\
|
||||||
struct cmc_test_info tinfo = { 0 }; \
|
struct cmc_test_info tinfo = { 0 }; \
|
||||||
struct cmc_timer timer = { 0 }; \
|
struct cmc_timer timer = { 0 }; \
|
||||||
\
|
\
|
||||||
tinfo.verbose = VERBOSE; \
|
tinfo.verbose = VERBOSE; \
|
||||||
tinfo.assert_total = cmc_assert_total; \
|
tinfo.assert_total = cmc_assert_total; \
|
||||||
tinfo.assert_failed = cmc_assert_failed; \
|
tinfo.assert_failed = cmc_assert_failed; \
|
||||||
\
|
\
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf( \
|
printf(" +---------------------------------------------------------------+\n"); \
|
||||||
" +---------------------------------------------------------------+\n"); \
|
printf(" | "); \
|
||||||
printf(" | "); \
|
printf("%s", cmc_test_color(0)); \
|
||||||
printf("%s", cmc_test_color(0)); \
|
printf("Unit "); \
|
||||||
printf("Unit "); \
|
printf("%s", cmc_test_color(4)); \
|
||||||
printf("%s", cmc_test_color(4)); \
|
printf("%-56s", unit_name); \
|
||||||
printf("%-56s", unit_name); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf(" |\n +---------------------------------------------------------------+"); \
|
||||||
printf( \
|
printf("%s\n", cmc_test_color(0)); \
|
||||||
" |\n +---------------------------------------------------------------+"); \
|
\
|
||||||
printf("%s\n", cmc_test_color(0)); \
|
/* Tests */ \
|
||||||
\
|
cmc_timer_start(timer); \
|
||||||
/* Tests */ \
|
\
|
||||||
cmc_timer_start(timer); \
|
BODY; \
|
||||||
\
|
\
|
||||||
BODY; \
|
cmc_timer_stop(timer); \
|
||||||
\
|
\
|
||||||
cmc_timer_stop(timer); \
|
unittest_abort: \
|
||||||
\
|
if (tinfo.aborted) \
|
||||||
unittest_abort: \
|
{ \
|
||||||
if (tinfo.aborted) \
|
cmc_test_log(unit_name, current_test, true, false); \
|
||||||
{ \
|
} \
|
||||||
cmc_test_log(unit_name, current_test, true, false); \
|
\
|
||||||
} \
|
tinfo.assert_total = cmc_assert_total - tinfo.assert_total; \
|
||||||
\
|
tinfo.assert_failed = cmc_assert_failed - tinfo.assert_failed; \
|
||||||
tinfo.assert_total = cmc_assert_total - tinfo.assert_total; \
|
\
|
||||||
tinfo.assert_failed = cmc_assert_failed - tinfo.assert_failed; \
|
printf("%s", cmc_test_color(3)); \
|
||||||
\
|
printf(" +---------------------------------------------------------------+\n | "); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(0)); \
|
||||||
printf( \
|
printf("Summary : "); \
|
||||||
" +---------------------------------------------------------------+\n | "); \
|
printf("%s", cmc_test_color(4)); \
|
||||||
printf("%s", cmc_test_color(0)); \
|
printf("%-52s", unit_name); \
|
||||||
printf("Summary : "); \
|
printf("%s|\n", cmc_test_color(3)); \
|
||||||
printf("%s", cmc_test_color(4)); \
|
printf(" +---------++----------------+-----------------+-----------------+\n | "); \
|
||||||
printf("%-52s", unit_name); \
|
printf("%s", cmc_test_color(0)); \
|
||||||
printf("%s|\n", cmc_test_color(3)); \
|
printf("Tests "); \
|
||||||
printf( \
|
printf("%s", cmc_test_color(3)); \
|
||||||
" +---------++----------------+-----------------+-----------------+\n | "); \
|
printf("||"); \
|
||||||
printf("%s", cmc_test_color(0)); \
|
printf("%s", cmc_test_color(5)); \
|
||||||
printf("Tests "); \
|
printf(" Total %8" PRIuMAX "", tinfo.total); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf("||"); \
|
printf(" | "); \
|
||||||
printf("%s", cmc_test_color(5)); \
|
printf("%s", cmc_test_color(2)); \
|
||||||
printf(" Total %8" PRIuMAX "", tinfo.total); \
|
printf("Passed %8" PRIuMAX "", tinfo.passed); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf(" | "); \
|
printf(" | "); \
|
||||||
printf("%s", cmc_test_color(2)); \
|
printf("%s", cmc_test_color(1)); \
|
||||||
printf("Passed %8" PRIuMAX "", tinfo.passed); \
|
printf("Failed %8" PRIuMAX "", tinfo.failed); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf(" | "); \
|
printf(" |\n | "); \
|
||||||
printf("%s", cmc_test_color(1)); \
|
printf("%s", cmc_test_color(0)); \
|
||||||
printf("Failed %8" PRIuMAX "", tinfo.failed); \
|
printf("Asserts "); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf(" |\n | "); \
|
printf("||"); \
|
||||||
printf("%s", cmc_test_color(0)); \
|
printf("%s", cmc_test_color(5)); \
|
||||||
printf("Asserts "); \
|
printf(" Total %8" PRIuMAX "", tinfo.assert_total); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf("||"); \
|
printf(" | "); \
|
||||||
printf("%s", cmc_test_color(5)); \
|
printf("%s", cmc_test_color(2)); \
|
||||||
printf(" Total %8" PRIuMAX "", tinfo.assert_total); \
|
printf("Passed %8" PRIuMAX "", tinfo.assert_total - tinfo.assert_failed); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf(" | "); \
|
printf(" | "); \
|
||||||
printf("%s", cmc_test_color(2)); \
|
printf("%s", cmc_test_color(1)); \
|
||||||
printf("Passed %8" PRIuMAX "", \
|
printf("Failed %8" PRIuMAX "", tinfo.assert_failed); \
|
||||||
tinfo.assert_total - tinfo.assert_failed); \
|
printf("%s", cmc_test_color(3)); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf(" |\n"); \
|
||||||
printf(" | "); \
|
printf(" +---------++----------------+-----------------+-----------------+\n | "); \
|
||||||
printf("%s", cmc_test_color(1)); \
|
printf("%s", cmc_test_color(0)); \
|
||||||
printf("Failed %8" PRIuMAX "", tinfo.assert_failed); \
|
printf("Total Runtime : %32.0f milliseconds", timer.result); \
|
||||||
printf("%s", cmc_test_color(3)); \
|
printf(" %s|\n", cmc_test_color(3)); \
|
||||||
printf(" |\n"); \
|
printf(" +---------------------------------------------------------------+\n"); \
|
||||||
printf( \
|
printf("%s", cmc_test_color(0)); \
|
||||||
" +---------++----------------+-----------------+-----------------+\n | "); \
|
printf("\n"); \
|
||||||
printf("%s", cmc_test_color(0)); \
|
\
|
||||||
printf("Total Runtime : %32.0f milliseconds", timer.result); \
|
return tinfo.failed; \
|
||||||
printf(" %s|\n", cmc_test_color(3)); \
|
|
||||||
printf( \
|
|
||||||
" +---------------------------------------------------------------+\n"); \
|
|
||||||
printf("%s", cmc_test_color(0)); \
|
|
||||||
printf("\n"); \
|
|
||||||
\
|
|
||||||
return tinfo.failed; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CMC_CREATE_TEST(TNAME, BODY) \
|
#define CMC_CREATE_TEST(TNAME, BODY) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
current_test = #TNAME; \
|
current_test = #TNAME; \
|
||||||
\
|
\
|
||||||
tinfo.total += 1; \
|
tinfo.total += 1; \
|
||||||
\
|
\
|
||||||
/* Provided by assert.h */ \
|
/* Provided by assert.h */ \
|
||||||
cmc_assert_state = true; \
|
cmc_assert_state = true; \
|
||||||
\
|
\
|
||||||
BODY; \
|
BODY; \
|
||||||
\
|
\
|
||||||
if (tinfo.verbose) \
|
if (tinfo.verbose) \
|
||||||
{ \
|
{ \
|
||||||
if (!cmc_assert_state) \
|
if (!cmc_assert_state) \
|
||||||
{ \
|
{ \
|
||||||
tinfo.failed += 1; \
|
tinfo.failed += 1; \
|
||||||
cmc_test_log(unit_name, current_test, false, false); \
|
cmc_test_log(unit_name, current_test, false, false); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
tinfo.passed += 1; \
|
tinfo.passed += 1; \
|
||||||
cmc_test_log(unit_name, current_test, false, true); \
|
cmc_test_log(unit_name, current_test, false, true); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CMC_TEST_ABORT() \
|
#define CMC_TEST_ABORT() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
tinfo.aborted = true; \
|
tinfo.aborted = true; \
|
||||||
tinfo.total -= 1; \
|
tinfo.total -= 1; \
|
||||||
goto unittest_abort; \
|
goto unittest_abort; \
|
||||||
\
|
\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif /* CMC_UTL_TEST_H */
|
#endif /* CMC_UTL_TEST_H */
|
||||||
+1
-2
@@ -88,8 +88,7 @@ static void *cmc_thread_wrapper(void *arg)
|
|||||||
* \param args The arguments passed to the proc function.
|
* \param args The arguments passed to the proc function.
|
||||||
* \return True or false if the thread creation was successfull.
|
* \return True or false if the thread creation was successfull.
|
||||||
*/
|
*/
|
||||||
static inline bool cmc_thrd_create(struct cmc_thread *thr, cmc_thread_proc proc,
|
static inline bool cmc_thrd_create(struct cmc_thread *thr, cmc_thread_proc proc, void *args)
|
||||||
void *args)
|
|
||||||
{
|
{
|
||||||
#if defined(CMC_THREAD_WINDOWS)
|
#if defined(CMC_THREAD_WINDOWS)
|
||||||
thr->args = args;
|
thr->args = args;
|
||||||
|
|||||||
+10
-11
@@ -24,20 +24,19 @@ struct cmc_timer
|
|||||||
double result; /* The result is given in milliseconds */
|
double result; /* The result is given in milliseconds */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define cmc_timer_start(timer) \
|
#define cmc_timer_start(timer) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
struct cmc_timer *t__ = &(timer); \
|
struct cmc_timer *t__ = &(timer); \
|
||||||
t__->start = clock(); \
|
t__->start = clock(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define cmc_timer_stop(timer) \
|
#define cmc_timer_stop(timer) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
struct cmc_timer *t__ = &(timer); \
|
struct cmc_timer *t__ = &(timer); \
|
||||||
t__->stop = clock(); \
|
t__->stop = clock(); \
|
||||||
t__->result = \
|
t__->result = (double)(t__->stop - t__->start) * 1000.0 / CLOCKS_PER_SEC; \
|
||||||
(double)(t__->stop - t__->start) * 1000.0 / CLOCKS_PER_SEC; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif /* CMC_UTL_TIMER_H */
|
#endif /* CMC_UTL_TIMER_H */
|
||||||
+11
-19
@@ -20,15 +20,12 @@
|
|||||||
#include "unt/foreach.c"
|
#include "unt/foreach.c"
|
||||||
|
|
||||||
#define cmc_run(unit, unit_fails, test_fails) \
|
#define cmc_run(unit, unit_fails, test_fails) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
uintmax_t f = unit(); \
|
uintmax_t f = unit(); \
|
||||||
\
|
if (f != 0) \
|
||||||
if (f != 0) \
|
unit_fails += 1; \
|
||||||
unit_fails += 1; \
|
test_fails += f; \
|
||||||
\
|
|
||||||
test_fails += f; \
|
|
||||||
\
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -86,19 +83,14 @@ int main(void)
|
|||||||
|
|
||||||
cmc_timer_stop(timer);
|
cmc_timer_stop(timer);
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+\n");
|
||||||
" +---------------------------------------------------------------+\n");
|
printf(" | SUMMARY |\n");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+\n");
|
||||||
" | SUMMARY |\n");
|
|
||||||
printf(
|
|
||||||
" +---------------------------------------------------------------+\n");
|
|
||||||
printf(" | Total Units Failed : %25" PRIuMAX " units |\n", units);
|
printf(" | Total Units Failed : %25" PRIuMAX " units |\n", units);
|
||||||
printf(" | Total Tests Failed : %25" PRIuMAX " tests |\n", tests);
|
printf(" | Total Tests Failed : %25" PRIuMAX " tests |\n", tests);
|
||||||
printf(" | Total Asserts Failed : %25" PRIuMAX " asserts |\n",
|
printf(" | Total Asserts Failed : %25" PRIuMAX " asserts |\n", cmc_assert_failed);
|
||||||
cmc_assert_failed);
|
|
||||||
printf(" | Total Runtime : %25.0lf milliseconds |\n", timer.result);
|
printf(" | Total Runtime : %25.0lf milliseconds |\n", timer.result);
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+\n");
|
||||||
" +---------------------------------------------------------------+\n");
|
|
||||||
|
|
||||||
return tests;
|
return tests;
|
||||||
}
|
}
|
||||||
+10
-21
@@ -19,15 +19,12 @@ struct bitset_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct bitset *bs_new(size_t n_bits);
|
struct bitset *bs_new(size_t n_bits);
|
||||||
struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc,
|
struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
struct bitset bs_init(size_t n_bits);
|
struct bitset bs_init(size_t n_bits);
|
||||||
struct bitset bs_init_custom(size_t n_bits, struct cmc_alloc_node *alloc,
|
struct bitset bs_init_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
void bs_free(struct bitset *_bitset_);
|
void bs_free(struct bitset *_bitset_);
|
||||||
void bs_release(struct bitset _bitset_);
|
void bs_release(struct bitset _bitset_);
|
||||||
void bs_customize(struct bitset *_bitset_, struct cmc_alloc_node *alloc,
|
void bs_customize(struct bitset *_bitset_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool bs_set(struct bitset *_bitset_, size_t bit_index);
|
_Bool bs_set(struct bitset *_bitset_, size_t bit_index);
|
||||||
_Bool bs_set_range(struct bitset *_bitset_, size_t from, size_t to);
|
_Bool bs_set_range(struct bitset *_bitset_, size_t from, size_t to);
|
||||||
_Bool bs_clear(struct bitset *_bitset_, size_t bit_index);
|
_Bool bs_clear(struct bitset *_bitset_, size_t bit_index);
|
||||||
@@ -35,8 +32,7 @@ _Bool bs_clear_range(struct bitset *_bitset_, size_t from, size_t to);
|
|||||||
_Bool bs_flip(struct bitset *_bitset_, size_t bit_index);
|
_Bool bs_flip(struct bitset *_bitset_, size_t bit_index);
|
||||||
_Bool bs_flip_range(struct bitset *_bitset_, size_t from, size_t to);
|
_Bool bs_flip_range(struct bitset *_bitset_, size_t from, size_t to);
|
||||||
_Bool bs_put(struct bitset *_bitset_, size_t bit_index, _Bool state);
|
_Bool bs_put(struct bitset *_bitset_, size_t bit_index, _Bool state);
|
||||||
_Bool bs_put_range(struct bitset *_bitset_, size_t from, size_t to,
|
_Bool bs_put_range(struct bitset *_bitset_, size_t from, size_t to, _Bool state);
|
||||||
_Bool state);
|
|
||||||
_Bool bs_set_all(struct bitset *_bitset_);
|
_Bool bs_set_all(struct bitset *_bitset_);
|
||||||
_Bool bs_clear_all(struct bitset *_bitset_);
|
_Bool bs_clear_all(struct bitset *_bitset_);
|
||||||
_Bool bs_flip_all(struct bitset *_bitset_);
|
_Bool bs_flip_all(struct bitset *_bitset_);
|
||||||
@@ -47,9 +43,7 @@ static inline size_t bs_bit_to_index(size_t idx)
|
|||||||
static const size_t shift =
|
static const size_t shift =
|
||||||
((sizeof(cmc_bitset_word) * 8) >> 6) > 0
|
((sizeof(cmc_bitset_word) * 8) >> 6) > 0
|
||||||
? 6
|
? 6
|
||||||
: ((sizeof(cmc_bitset_word) * 8) >> 5) > 0
|
: ((sizeof(cmc_bitset_word) * 8) >> 5) > 0 ? 5 : ((sizeof(cmc_bitset_word) * 8) >> 4) > 0 ? 4 : 3;
|
||||||
? 5
|
|
||||||
: ((sizeof(cmc_bitset_word) * 8) >> 4) > 0 ? 4 : 3;
|
|
||||||
return idx >> shift;
|
return idx >> shift;
|
||||||
}
|
}
|
||||||
_Bool bs_impl_resize(struct bitset *_bitset_, size_t n_bits, _Bool do_resize);
|
_Bool bs_impl_resize(struct bitset *_bitset_, size_t n_bits, _Bool do_resize);
|
||||||
@@ -57,8 +51,7 @@ struct bitset *bs_new(size_t n_bits)
|
|||||||
{
|
{
|
||||||
return bs_new_custom(n_bits, ((void *)0), ((void *)0));
|
return bs_new_custom(n_bits, ((void *)0), ((void *)0));
|
||||||
}
|
}
|
||||||
struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc,
|
struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (n_bits < 1)
|
if (n_bits < 1)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
@@ -84,8 +77,7 @@ struct bitset bs_init(size_t n_bits)
|
|||||||
{
|
{
|
||||||
return bs_init_custom(n_bits, ((void *)0), ((void *)0));
|
return bs_init_custom(n_bits, ((void *)0), ((void *)0));
|
||||||
}
|
}
|
||||||
struct bitset bs_init_custom(size_t n_bits, struct cmc_alloc_node *alloc,
|
struct bitset bs_init_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
struct bitset _bitset_ = { 0 };
|
struct bitset _bitset_ = { 0 };
|
||||||
if (n_bits < 1)
|
if (n_bits < 1)
|
||||||
@@ -111,8 +103,7 @@ void bs_release(struct bitset _bitset_)
|
|||||||
{
|
{
|
||||||
free(_bitset_.buffer);
|
free(_bitset_.buffer);
|
||||||
}
|
}
|
||||||
void bs_customize(struct bitset *_bitset_, struct cmc_alloc_node *alloc,
|
void bs_customize(struct bitset *_bitset_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_bitset_->alloc = &cmc_alloc_node_default;
|
_bitset_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -317,8 +308,7 @@ _Bool bs_impl_resize(struct bitset *_bitset_, size_t n_bits, _Bool do_resize)
|
|||||||
size_t words = bs_bit_to_index(n_bits - 1) + 1;
|
size_t words = bs_bit_to_index(n_bits - 1) + 1;
|
||||||
if (!do_resize && words <= _bitset_->capacity)
|
if (!do_resize && words <= _bitset_->capacity)
|
||||||
return 1;
|
return 1;
|
||||||
cmc_bitset_word *new_buffer =
|
cmc_bitset_word *new_buffer = realloc(_bitset_->buffer, words * sizeof(cmc_bitset_word));
|
||||||
realloc(_bitset_->buffer, words * sizeof(cmc_bitset_word));
|
|
||||||
if (!new_buffer)
|
if (!new_buffer)
|
||||||
{
|
{
|
||||||
_bitset_->flag = CMC_FLAG_ALLOC;
|
_bitset_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -326,8 +316,7 @@ _Bool bs_impl_resize(struct bitset *_bitset_, size_t n_bits, _Bool do_resize)
|
|||||||
}
|
}
|
||||||
_bitset_->buffer = new_buffer;
|
_bitset_->buffer = new_buffer;
|
||||||
if (_bitset_->capacity < words)
|
if (_bitset_->capacity < words)
|
||||||
memset(_bitset_->buffer + _bitset_->capacity, 0,
|
memset(_bitset_->buffer + _bitset_->capacity, 0, (words - _bitset_->capacity) * sizeof(cmc_bitset_word));
|
||||||
(words - _bitset_->capacity) * sizeof(cmc_bitset_word));
|
|
||||||
_bitset_->capacity = words;
|
_bitset_->capacity = words;
|
||||||
if (_bitset_->callbacks && _bitset_->callbacks->resize)
|
if (_bitset_->callbacks && _bitset_->callbacks->resize)
|
||||||
_bitset_->callbacks->resize();
|
_bitset_->callbacks->resize();
|
||||||
|
|||||||
+12
-24
@@ -33,14 +33,12 @@ struct deque_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct deque *d_new(size_t capacity, struct deque_fval *f_val);
|
struct deque *d_new(size_t capacity, struct deque_fval *f_val);
|
||||||
struct deque *d_new_custom(size_t capacity, struct deque_fval *f_val,
|
struct deque *d_new_custom(size_t capacity, struct deque_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void d_clear(struct deque *_deque_);
|
void d_clear(struct deque *_deque_);
|
||||||
void d_free(struct deque *_deque_);
|
void d_free(struct deque *_deque_);
|
||||||
void d_release(struct deque _deque_);
|
void d_release(struct deque _deque_);
|
||||||
void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc,
|
void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool d_push_front(struct deque *_deque_, size_t value);
|
_Bool d_push_front(struct deque *_deque_, size_t value);
|
||||||
_Bool d_push_back(struct deque *_deque_, size_t value);
|
_Bool d_push_back(struct deque *_deque_, size_t value);
|
||||||
_Bool d_pop_front(struct deque *_deque_);
|
_Bool d_pop_front(struct deque *_deque_);
|
||||||
@@ -76,8 +74,7 @@ struct deque *d_new(size_t capacity, struct deque_fval *f_val)
|
|||||||
{
|
{
|
||||||
return d_new_custom(capacity, f_val, ((void *)0), ((void *)0));
|
return d_new_custom(capacity, f_val, ((void *)0), ((void *)0));
|
||||||
}
|
}
|
||||||
struct deque *d_new_custom(size_t capacity, struct deque_fval *f_val,
|
struct deque *d_new_custom(size_t capacity, struct deque_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
@@ -146,8 +143,7 @@ void d_release(struct deque _deque_)
|
|||||||
}
|
}
|
||||||
_deque_.alloc->free(_deque_.buffer);
|
_deque_.alloc->free(_deque_.buffer);
|
||||||
}
|
}
|
||||||
void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc,
|
void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_deque_->alloc = &cmc_alloc_node_default;
|
_deque_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -163,8 +159,7 @@ _Bool d_push_front(struct deque *_deque_, size_t value)
|
|||||||
if (!d_resize(_deque_, _deque_->capacity * 2))
|
if (!d_resize(_deque_, _deque_->capacity * 2))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_deque_->front =
|
_deque_->front = (_deque_->front == 0) ? _deque_->capacity - 1 : _deque_->front - 1;
|
||||||
(_deque_->front == 0) ? _deque_->capacity - 1 : _deque_->front - 1;
|
|
||||||
_deque_->buffer[_deque_->front] = value;
|
_deque_->buffer[_deque_->front] = value;
|
||||||
_deque_->count++;
|
_deque_->count++;
|
||||||
_deque_->flag = CMC_FLAG_OK;
|
_deque_->flag = CMC_FLAG_OK;
|
||||||
@@ -180,8 +175,7 @@ _Bool d_push_back(struct deque *_deque_, size_t value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_deque_->buffer[_deque_->back] = value;
|
_deque_->buffer[_deque_->back] = value;
|
||||||
_deque_->back =
|
_deque_->back = (_deque_->back == _deque_->capacity - 1) ? 0 : _deque_->back + 1;
|
||||||
(_deque_->back == _deque_->capacity - 1) ? 0 : _deque_->back + 1;
|
|
||||||
_deque_->count++;
|
_deque_->count++;
|
||||||
_deque_->flag = CMC_FLAG_OK;
|
_deque_->flag = CMC_FLAG_OK;
|
||||||
if (_deque_->callbacks && _deque_->callbacks->create)
|
if (_deque_->callbacks && _deque_->callbacks->create)
|
||||||
@@ -196,8 +190,7 @@ _Bool d_pop_front(struct deque *_deque_)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_deque_->buffer[_deque_->front] = (size_t){ 0 };
|
_deque_->buffer[_deque_->front] = (size_t){ 0 };
|
||||||
_deque_->front =
|
_deque_->front = (_deque_->front == _deque_->capacity - 1) ? 0 : _deque_->front + 1;
|
||||||
(_deque_->front == _deque_->capacity - 1) ? 0 : _deque_->front + 1;
|
|
||||||
_deque_->count--;
|
_deque_->count--;
|
||||||
_deque_->flag = CMC_FLAG_OK;
|
_deque_->flag = CMC_FLAG_OK;
|
||||||
if (_deque_->callbacks && _deque_->callbacks->delete)
|
if (_deque_->callbacks && _deque_->callbacks->delete)
|
||||||
@@ -211,8 +204,7 @@ _Bool d_pop_back(struct deque *_deque_)
|
|||||||
_deque_->flag = CMC_FLAG_EMPTY;
|
_deque_->flag = CMC_FLAG_EMPTY;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_deque_->back =
|
_deque_->back = (_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1;
|
||||||
(_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1;
|
|
||||||
_deque_->buffer[_deque_->back] = (size_t){ 0 };
|
_deque_->buffer[_deque_->back] = (size_t){ 0 };
|
||||||
_deque_->count--;
|
_deque_->count--;
|
||||||
_deque_->flag = CMC_FLAG_OK;
|
_deque_->flag = CMC_FLAG_OK;
|
||||||
@@ -242,8 +234,7 @@ size_t d_back(struct deque *_deque_)
|
|||||||
_deque_->flag = CMC_FLAG_OK;
|
_deque_->flag = CMC_FLAG_OK;
|
||||||
if (_deque_->callbacks && _deque_->callbacks->read)
|
if (_deque_->callbacks && _deque_->callbacks->read)
|
||||||
_deque_->callbacks->read();
|
_deque_->callbacks->read();
|
||||||
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1
|
return _deque_->buffer[(_deque_->back == 0) ? _deque_->capacity - 1 : _deque_->back - 1];
|
||||||
: _deque_->back - 1];
|
|
||||||
}
|
}
|
||||||
_Bool d_contains(struct deque *_deque_, size_t value)
|
_Bool d_contains(struct deque *_deque_, size_t value)
|
||||||
{
|
{
|
||||||
@@ -315,8 +306,7 @@ success:
|
|||||||
}
|
}
|
||||||
struct deque *d_copy_of(struct deque *_deque_)
|
struct deque *d_copy_of(struct deque *_deque_)
|
||||||
{
|
{
|
||||||
struct deque *result = d_new_custom(_deque_->capacity, _deque_->f_val,
|
struct deque *result = d_new_custom(_deque_->capacity, _deque_->f_val, _deque_->alloc, _deque_->callbacks);
|
||||||
_deque_->alloc, _deque_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_deque_->flag = CMC_FLAG_ERROR;
|
_deque_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -351,8 +341,7 @@ _Bool d_equals(struct deque *_deque1_, struct deque *_deque2_)
|
|||||||
if (_deque1_->count != _deque2_->count)
|
if (_deque1_->count != _deque2_->count)
|
||||||
return 0;
|
return 0;
|
||||||
size_t i, j, k;
|
size_t i, j, k;
|
||||||
for (i = _deque1_->front, j = _deque2_->front, k = 0; k < _deque1_->count;
|
for (i = _deque1_->front, j = _deque2_->front, k = 0; k < _deque1_->count; k++)
|
||||||
k++)
|
|
||||||
{
|
{
|
||||||
if (_deque1_->f_val->cmp(_deque1_->buffer[i], _deque2_->buffer[j]) != 0)
|
if (_deque1_->f_val->cmp(_deque1_->buffer[i], _deque2_->buffer[j]) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -451,8 +440,7 @@ _Bool d_iter_prev(struct deque_iter *iter)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
iter->end = d_empty(iter->target);
|
iter->end = d_empty(iter->target);
|
||||||
iter->cursor =
|
iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1;
|
||||||
(iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1;
|
|
||||||
iter->index--;
|
iter->index--;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-107
@@ -52,25 +52,19 @@ struct hashbidimap_iter
|
|||||||
_Bool start;
|
_Bool start;
|
||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct hashbidimap *hbm_new(size_t capacity, double load,
|
struct hashbidimap *hbm_new(size_t capacity, double load, struct hashbidimap_fkey *f_key,
|
||||||
struct hashbidimap_fkey *f_key,
|
|
||||||
struct hashbidimap_fval *f_val);
|
struct hashbidimap_fval *f_val);
|
||||||
struct hashbidimap *hbm_new_custom(size_t capacity, double load,
|
struct hashbidimap *hbm_new_custom(size_t capacity, double load, struct hashbidimap_fkey *f_key,
|
||||||
struct hashbidimap_fkey *f_key,
|
struct hashbidimap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct hashbidimap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void hbm_clear(struct hashbidimap *_map_);
|
void hbm_clear(struct hashbidimap *_map_);
|
||||||
void hbm_free(struct hashbidimap *_map_);
|
void hbm_free(struct hashbidimap *_map_);
|
||||||
void hbm_customize(struct hashbidimap *_map_, struct cmc_alloc_node *alloc,
|
void hbm_customize(struct hashbidimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool hbm_insert(struct hashbidimap *_map_, size_t key, size_t value);
|
_Bool hbm_insert(struct hashbidimap *_map_, size_t key, size_t value);
|
||||||
_Bool hbm_update_key(struct hashbidimap *_map_, size_t val, size_t new_key);
|
_Bool hbm_update_key(struct hashbidimap *_map_, size_t val, size_t new_key);
|
||||||
_Bool hbm_update_val(struct hashbidimap *_map_, size_t key, size_t new_val);
|
_Bool hbm_update_val(struct hashbidimap *_map_, size_t key, size_t new_val);
|
||||||
_Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key,
|
_Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key, size_t *out_val);
|
||||||
size_t *out_val);
|
_Bool hbm_remove_by_val(struct hashbidimap *_map_, size_t val, size_t *out_key, size_t *out_val);
|
||||||
_Bool hbm_remove_by_val(struct hashbidimap *_map_, size_t val, size_t *out_key,
|
|
||||||
size_t *out_val);
|
|
||||||
size_t hbm_get_key(struct hashbidimap *_map_, size_t val);
|
size_t hbm_get_key(struct hashbidimap *_map_, size_t val);
|
||||||
size_t hbm_get_val(struct hashbidimap *_map_, size_t key);
|
size_t hbm_get_val(struct hashbidimap *_map_, size_t key);
|
||||||
_Bool hbm_contains_key(struct hashbidimap *_map_, size_t key);
|
_Bool hbm_contains_key(struct hashbidimap *_map_, size_t key);
|
||||||
@@ -101,23 +95,15 @@ _Bool hbm_iter_go_to(struct hashbidimap_iter *iter, size_t index);
|
|||||||
size_t hbm_iter_key(struct hashbidimap_iter *iter);
|
size_t hbm_iter_key(struct hashbidimap_iter *iter);
|
||||||
size_t hbm_iter_value(struct hashbidimap_iter *iter);
|
size_t hbm_iter_value(struct hashbidimap_iter *iter);
|
||||||
size_t hbm_iter_index(struct hashbidimap_iter *iter);
|
size_t hbm_iter_index(struct hashbidimap_iter *iter);
|
||||||
static struct hashbidimap_entry *hbm_impl_new_entry(struct hashbidimap *_map_,
|
static struct hashbidimap_entry *hbm_impl_new_entry(struct hashbidimap *_map_, size_t key, size_t value);
|
||||||
size_t key, size_t value);
|
static struct hashbidimap_entry **hbm_impl_get_entry_by_key(struct hashbidimap *_map_, size_t key);
|
||||||
static struct hashbidimap_entry **
|
static struct hashbidimap_entry **hbm_impl_get_entry_by_val(struct hashbidimap *_map_, size_t val);
|
||||||
hbm_impl_get_entry_by_key(struct hashbidimap *_map_, size_t key);
|
static struct hashbidimap_entry **hbm_impl_add_entry_to_key(struct hashbidimap *_map_, struct hashbidimap_entry *entry);
|
||||||
static struct hashbidimap_entry **
|
static struct hashbidimap_entry **hbm_impl_add_entry_to_val(struct hashbidimap *_map_, struct hashbidimap_entry *entry);
|
||||||
hbm_impl_get_entry_by_val(struct hashbidimap *_map_, size_t val);
|
|
||||||
static struct hashbidimap_entry **
|
|
||||||
hbm_impl_add_entry_to_key(struct hashbidimap *_map_,
|
|
||||||
struct hashbidimap_entry *entry);
|
|
||||||
static struct hashbidimap_entry **
|
|
||||||
hbm_impl_add_entry_to_val(struct hashbidimap *_map_,
|
|
||||||
struct hashbidimap_entry *entry);
|
|
||||||
static size_t hbm_impl_calculate_size(size_t required);
|
static size_t hbm_impl_calculate_size(size_t required);
|
||||||
static struct hashbidimap_iter hbm_impl_it_start(struct hashbidimap *_map_);
|
static struct hashbidimap_iter hbm_impl_it_start(struct hashbidimap *_map_);
|
||||||
static struct hashbidimap_iter hbm_impl_it_end(struct hashbidimap *_map_);
|
static struct hashbidimap_iter hbm_impl_it_end(struct hashbidimap *_map_);
|
||||||
struct hashbidimap *hbm_new(size_t capacity, double load,
|
struct hashbidimap *hbm_new(size_t capacity, double load, struct hashbidimap_fkey *f_key,
|
||||||
struct hashbidimap_fkey *f_key,
|
|
||||||
struct hashbidimap_fval *f_val)
|
struct hashbidimap_fval *f_val)
|
||||||
{
|
{
|
||||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
||||||
@@ -131,8 +117,7 @@ struct hashbidimap *hbm_new(size_t capacity, double load,
|
|||||||
struct hashbidimap *_map_ = alloc->malloc(sizeof(struct hashbidimap));
|
struct hashbidimap *_map_ = alloc->malloc(sizeof(struct hashbidimap));
|
||||||
if (!_map_)
|
if (!_map_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
_map_->buffer =
|
_map_->buffer = alloc->calloc(real_capacity, sizeof(struct hashbidimap_entry *[2]));
|
||||||
alloc->calloc(real_capacity, sizeof(struct hashbidimap_entry *[2]));
|
|
||||||
if (!_map_->buffer)
|
if (!_map_->buffer)
|
||||||
{
|
{
|
||||||
alloc->free(_map_->buffer);
|
alloc->free(_map_->buffer);
|
||||||
@@ -151,10 +136,8 @@ struct hashbidimap *hbm_new(size_t capacity, double load,
|
|||||||
_map_->it_end = hbm_impl_it_end;
|
_map_->it_end = hbm_impl_it_end;
|
||||||
return _map_;
|
return _map_;
|
||||||
}
|
}
|
||||||
struct hashbidimap *hbm_new_custom(size_t capacity, double load,
|
struct hashbidimap *hbm_new_custom(size_t capacity, double load, struct hashbidimap_fkey *f_key,
|
||||||
struct hashbidimap_fkey *f_key,
|
struct hashbidimap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct hashbidimap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity == 0 || load <= 0 || load >= 1)
|
if (capacity == 0 || load <= 0 || load >= 1)
|
||||||
@@ -169,8 +152,7 @@ struct hashbidimap *hbm_new_custom(size_t capacity, double load,
|
|||||||
struct hashbidimap *_map_ = alloc->malloc(sizeof(struct hashbidimap));
|
struct hashbidimap *_map_ = alloc->malloc(sizeof(struct hashbidimap));
|
||||||
if (!_map_)
|
if (!_map_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
_map_->buffer =
|
_map_->buffer = alloc->calloc(real_capacity, sizeof(struct hashbidimap_entry *[2]));
|
||||||
alloc->calloc(real_capacity, sizeof(struct hashbidimap_entry *[2]));
|
|
||||||
if (!_map_->buffer)
|
if (!_map_->buffer)
|
||||||
{
|
{
|
||||||
alloc->free(_map_->buffer);
|
alloc->free(_map_->buffer);
|
||||||
@@ -215,8 +197,7 @@ void hbm_free(struct hashbidimap *_map_)
|
|||||||
_map_->alloc->free(_map_->buffer);
|
_map_->alloc->free(_map_->buffer);
|
||||||
_map_->alloc->free(_map_);
|
_map_->alloc->free(_map_);
|
||||||
}
|
}
|
||||||
void hbm_customize(struct hashbidimap *_map_, struct cmc_alloc_node *alloc,
|
void hbm_customize(struct hashbidimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_map_->alloc = &cmc_alloc_node_default;
|
_map_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -232,17 +213,14 @@ _Bool hbm_insert(struct hashbidimap *_map_, size_t key, size_t value)
|
|||||||
if (!hbm_resize(_map_, _map_->capacity + 1))
|
if (!hbm_resize(_map_, _map_->capacity + 1))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (hbm_impl_get_entry_by_key(_map_, key) != ((void *)0) ||
|
if (hbm_impl_get_entry_by_key(_map_, key) != ((void *)0) || hbm_impl_get_entry_by_val(_map_, value) != ((void *)0))
|
||||||
hbm_impl_get_entry_by_val(_map_, value) != ((void *)0))
|
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_DUPLICATE;
|
_map_->flag = CMC_FLAG_DUPLICATE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct hashbidimap_entry *entry = hbm_impl_new_entry(_map_, key, value);
|
struct hashbidimap_entry *entry = hbm_impl_new_entry(_map_, key, value);
|
||||||
struct hashbidimap_entry **key_entry =
|
struct hashbidimap_entry **key_entry = hbm_impl_add_entry_to_key(_map_, entry);
|
||||||
hbm_impl_add_entry_to_key(_map_, entry);
|
struct hashbidimap_entry **val_entry = hbm_impl_add_entry_to_val(_map_, entry);
|
||||||
struct hashbidimap_entry **val_entry =
|
|
||||||
hbm_impl_add_entry_to_val(_map_, entry);
|
|
||||||
if (!key_entry || !val_entry)
|
if (!key_entry || !val_entry)
|
||||||
{
|
{
|
||||||
if (key_entry)
|
if (key_entry)
|
||||||
@@ -347,8 +325,7 @@ success:
|
|||||||
_map_->callbacks->update();
|
_map_->callbacks->update();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key,
|
_Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key, size_t *out_val)
|
||||||
size_t *out_val)
|
|
||||||
{
|
{
|
||||||
if (hbm_empty(_map_))
|
if (hbm_empty(_map_))
|
||||||
{
|
{
|
||||||
@@ -381,8 +358,7 @@ _Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key,
|
|||||||
_map_->callbacks->delete ();
|
_map_->callbacks->delete ();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool hbm_remove_by_val(struct hashbidimap *_map_, size_t val, size_t *out_key,
|
_Bool hbm_remove_by_val(struct hashbidimap *_map_, size_t val, size_t *out_key, size_t *out_val)
|
||||||
size_t *out_val)
|
|
||||||
{
|
{
|
||||||
if (hbm_empty(_map_))
|
if (hbm_empty(_map_))
|
||||||
{
|
{
|
||||||
@@ -500,8 +476,7 @@ _Bool hbm_resize(struct hashbidimap *_map_, size_t capacity)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct hashbidimap *_new_map_ =
|
struct hashbidimap *_new_map_ =
|
||||||
hbm_new_custom(capacity, _map_->load, _map_->f_key, _map_->f_val,
|
hbm_new_custom(capacity, _map_->load, _map_->f_key, _map_->f_val, _map_->alloc, ((void *)0));
|
||||||
_map_->alloc, ((void *)0));
|
|
||||||
if (!_new_map_)
|
if (!_new_map_)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ALLOC;
|
_map_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -512,10 +487,8 @@ _Bool hbm_resize(struct hashbidimap *_map_, size_t capacity)
|
|||||||
struct hashbidimap_entry *scan = _map_->buffer[i][0];
|
struct hashbidimap_entry *scan = _map_->buffer[i][0];
|
||||||
if (scan && scan != ((void *)1))
|
if (scan && scan != ((void *)1))
|
||||||
{
|
{
|
||||||
struct hashbidimap_entry **e1 =
|
struct hashbidimap_entry **e1 = hbm_impl_add_entry_to_key(_new_map_, scan);
|
||||||
hbm_impl_add_entry_to_key(_new_map_, scan);
|
struct hashbidimap_entry **e2 = hbm_impl_add_entry_to_val(_new_map_, scan);
|
||||||
struct hashbidimap_entry **e2 =
|
|
||||||
hbm_impl_add_entry_to_val(_new_map_, scan);
|
|
||||||
if (!e1 || !e2)
|
if (!e1 || !e2)
|
||||||
{
|
{
|
||||||
_new_map_->f_key = &(struct hashbidimap_fkey){ ((void *)0) };
|
_new_map_->f_key = &(struct hashbidimap_fkey){ ((void *)0) };
|
||||||
@@ -549,9 +522,8 @@ success:
|
|||||||
}
|
}
|
||||||
struct hashbidimap *hbm_copy_of(struct hashbidimap *_map_)
|
struct hashbidimap *hbm_copy_of(struct hashbidimap *_map_)
|
||||||
{
|
{
|
||||||
struct hashbidimap *result =
|
struct hashbidimap *result = hbm_new_custom(_map_->capacity * _map_->load, _map_->load, _map_->f_key, _map_->f_val,
|
||||||
hbm_new_custom(_map_->capacity * _map_->load, _map_->load, _map_->f_key,
|
_map_->alloc, _map_->callbacks);
|
||||||
_map_->f_val, _map_->alloc, _map_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ERROR;
|
_map_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -572,8 +544,7 @@ struct hashbidimap *hbm_copy_of(struct hashbidimap *_map_)
|
|||||||
tmp_val = _map_->f_val->cpy(scan->value);
|
tmp_val = _map_->f_val->cpy(scan->value);
|
||||||
else
|
else
|
||||||
tmp_val = scan->value;
|
tmp_val = scan->value;
|
||||||
struct hashbidimap_entry *entry =
|
struct hashbidimap_entry *entry = hbm_impl_new_entry(result, tmp_key, tmp_val);
|
||||||
hbm_impl_new_entry(result, tmp_key, tmp_val);
|
|
||||||
hbm_impl_add_entry_to_key(result, entry);
|
hbm_impl_add_entry_to_key(result, entry);
|
||||||
hbm_impl_add_entry_to_val(result, entry);
|
hbm_impl_add_entry_to_val(result, entry);
|
||||||
result->count++;
|
result->count++;
|
||||||
@@ -605,8 +576,7 @@ _Bool hbm_equals(struct hashbidimap *_map1_, struct hashbidimap *_map2_)
|
|||||||
struct hashbidimap_entry *scan = _mapA_->buffer[i][0];
|
struct hashbidimap_entry *scan = _mapA_->buffer[i][0];
|
||||||
if (scan && scan != ((void *)1))
|
if (scan && scan != ((void *)1))
|
||||||
{
|
{
|
||||||
struct hashbidimap_entry **entry_B =
|
struct hashbidimap_entry **entry_B = hbm_impl_get_entry_by_key(_mapB_, scan->key);
|
||||||
hbm_impl_get_entry_by_key(_mapB_, scan->key);
|
|
||||||
if (!entry_B)
|
if (!entry_B)
|
||||||
return 0;
|
return 0;
|
||||||
if (_mapA_->f_val->cmp((*entry_B)->value, scan->value) != 0)
|
if (_mapA_->f_val->cmp((*entry_B)->value, scan->value) != 0)
|
||||||
@@ -615,36 +585,9 @@ _Bool hbm_equals(struct hashbidimap *_map1_, struct hashbidimap *_map2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string hbm_to_string(struct hashbidimap *_map_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct hashbidimap *m_ = _map_;
|
|
||||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_hashbidimap,
|
|
||||||
"CMC_PARAM_SNAME((hbm, hashbidimap, , size_t, size_t))",
|
|
||||||
"CMC_PARAM_K((hbm, hashbidimap, , size_t, size_t))",
|
|
||||||
"CMC_PARAM_V((hbm, hashbidimap, , size_t, size_t))", m_,
|
|
||||||
m_->buffer, m_->capacity, m_->count, m_->load, m_->flag,
|
|
||||||
m_->f_key, m_->f_val, m_->alloc, m_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool hbm_print(struct hashbidimap *_map_, FILE *fptr)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < _map_->capacity; i++)
|
|
||||||
{
|
|
||||||
struct hashbidimap_entry *target = _map_->buffer[i][0];
|
|
||||||
if (target && target != ((void *)1))
|
|
||||||
{
|
|
||||||
if (!_map_->f_key->str(fptr, target->key) ||
|
|
||||||
!_map_->f_val->str(fptr, target->value))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct hashbidimap_iter *hbm_iter_new(struct hashbidimap *target)
|
struct hashbidimap_iter *hbm_iter_new(struct hashbidimap *target)
|
||||||
{
|
{
|
||||||
struct hashbidimap_iter *iter =
|
struct hashbidimap_iter *iter = target->alloc->malloc(sizeof(struct hashbidimap_iter));
|
||||||
target->alloc->malloc(sizeof(struct hashbidimap_iter));
|
|
||||||
if (!iter)
|
if (!iter)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
hbm_iter_init(iter, target);
|
hbm_iter_init(iter, target);
|
||||||
@@ -815,11 +758,9 @@ size_t hbm_iter_index(struct hashbidimap_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->index;
|
return iter->index;
|
||||||
}
|
}
|
||||||
static struct hashbidimap_entry *hbm_impl_new_entry(struct hashbidimap *_map_,
|
static struct hashbidimap_entry *hbm_impl_new_entry(struct hashbidimap *_map_, size_t key, size_t value)
|
||||||
size_t key, size_t value)
|
|
||||||
{
|
{
|
||||||
struct hashbidimap_entry *entry =
|
struct hashbidimap_entry *entry = _map_->alloc->malloc(sizeof(struct hashbidimap_entry));
|
||||||
_map_->alloc->malloc(sizeof(struct hashbidimap_entry));
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
entry->key = key;
|
entry->key = key;
|
||||||
@@ -830,8 +771,7 @@ static struct hashbidimap_entry *hbm_impl_new_entry(struct hashbidimap *_map_,
|
|||||||
entry->ref[1] = ((void *)0);
|
entry->ref[1] = ((void *)0);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
static struct hashbidimap_entry **
|
static struct hashbidimap_entry **hbm_impl_get_entry_by_key(struct hashbidimap *_map_, size_t key)
|
||||||
hbm_impl_get_entry_by_key(struct hashbidimap *_map_, size_t key)
|
|
||||||
{
|
{
|
||||||
size_t hash = _map_->f_key->hash(key);
|
size_t hash = _map_->f_key->hash(key);
|
||||||
size_t pos = hash % _map_->capacity;
|
size_t pos = hash % _map_->capacity;
|
||||||
@@ -845,8 +785,7 @@ hbm_impl_get_entry_by_key(struct hashbidimap *_map_, size_t key)
|
|||||||
}
|
}
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
static struct hashbidimap_entry **
|
static struct hashbidimap_entry **hbm_impl_get_entry_by_val(struct hashbidimap *_map_, size_t val)
|
||||||
hbm_impl_get_entry_by_val(struct hashbidimap *_map_, size_t val)
|
|
||||||
{
|
{
|
||||||
size_t hash = _map_->f_val->hash(val);
|
size_t hash = _map_->f_val->hash(val);
|
||||||
size_t pos = hash % _map_->capacity;
|
size_t pos = hash % _map_->capacity;
|
||||||
@@ -860,16 +799,13 @@ hbm_impl_get_entry_by_val(struct hashbidimap *_map_, size_t val)
|
|||||||
}
|
}
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
static struct hashbidimap_entry **
|
static struct hashbidimap_entry **hbm_impl_add_entry_to_key(struct hashbidimap *_map_, struct hashbidimap_entry *entry)
|
||||||
hbm_impl_add_entry_to_key(struct hashbidimap *_map_,
|
|
||||||
struct hashbidimap_entry *entry)
|
|
||||||
{
|
{
|
||||||
struct hashbidimap_entry **to_return = ((void *)0);
|
struct hashbidimap_entry **to_return = ((void *)0);
|
||||||
size_t hash = _map_->f_key->hash(entry->key);
|
size_t hash = _map_->f_key->hash(entry->key);
|
||||||
size_t original_pos = hash % _map_->capacity;
|
size_t original_pos = hash % _map_->capacity;
|
||||||
size_t pos = original_pos;
|
size_t pos = original_pos;
|
||||||
struct hashbidimap_entry **scan =
|
struct hashbidimap_entry **scan = &(_map_->buffer[hash % _map_->capacity][0]);
|
||||||
&(_map_->buffer[hash % _map_->capacity][0]);
|
|
||||||
if (*scan == ((void *)0))
|
if (*scan == ((void *)0))
|
||||||
{
|
{
|
||||||
*scan = entry;
|
*scan = entry;
|
||||||
@@ -907,16 +843,13 @@ hbm_impl_add_entry_to_key(struct hashbidimap *_map_,
|
|||||||
}
|
}
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
static struct hashbidimap_entry **
|
static struct hashbidimap_entry **hbm_impl_add_entry_to_val(struct hashbidimap *_map_, struct hashbidimap_entry *entry)
|
||||||
hbm_impl_add_entry_to_val(struct hashbidimap *_map_,
|
|
||||||
struct hashbidimap_entry *entry)
|
|
||||||
{
|
{
|
||||||
struct hashbidimap_entry **to_return = ((void *)0);
|
struct hashbidimap_entry **to_return = ((void *)0);
|
||||||
size_t hash = _map_->f_val->hash(entry->value);
|
size_t hash = _map_->f_val->hash(entry->value);
|
||||||
size_t original_pos = hash % _map_->capacity;
|
size_t original_pos = hash % _map_->capacity;
|
||||||
size_t pos = original_pos;
|
size_t pos = original_pos;
|
||||||
struct hashbidimap_entry **scan =
|
struct hashbidimap_entry **scan = &(_map_->buffer[hash % _map_->capacity][1]);
|
||||||
&(_map_->buffer[hash % _map_->capacity][1]);
|
|
||||||
if (*scan == ((void *)0))
|
if (*scan == ((void *)0))
|
||||||
{
|
{
|
||||||
*scan = entry;
|
*scan = entry;
|
||||||
@@ -956,8 +889,7 @@ hbm_impl_add_entry_to_val(struct hashbidimap *_map_,
|
|||||||
}
|
}
|
||||||
static size_t hbm_impl_calculate_size(size_t required)
|
static size_t hbm_impl_calculate_size(size_t required)
|
||||||
{
|
{
|
||||||
const size_t count =
|
const size_t count = sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
||||||
sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
|
||||||
if (cmc_hashtable_primes[count - 1] < required)
|
if (cmc_hashtable_primes[count - 1] < required)
|
||||||
return required;
|
return required;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|||||||
+20
-41
@@ -50,21 +50,15 @@ struct hashmap_iter
|
|||||||
_Bool start;
|
_Bool start;
|
||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key,
|
struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val);
|
||||||
struct hashmap_fval *f_val);
|
struct hashmap *hm_new_custom(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val,
|
||||||
struct hashmap *hm_new_custom(size_t capacity, double load,
|
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct hashmap_fkey *f_key,
|
|
||||||
struct hashmap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
void hm_clear(struct hashmap *_map_);
|
void hm_clear(struct hashmap *_map_);
|
||||||
void hm_free(struct hashmap *_map_);
|
void hm_free(struct hashmap *_map_);
|
||||||
void hm_release(struct hashmap _map_);
|
void hm_release(struct hashmap _map_);
|
||||||
void hm_customize(struct hashmap *_map_, struct cmc_alloc_node *alloc,
|
void hm_customize(struct hashmap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool hm_insert(struct hashmap *_map_, size_t key, size_t value);
|
_Bool hm_insert(struct hashmap *_map_, size_t key, size_t value);
|
||||||
_Bool hm_update(struct hashmap *_map_, size_t key, size_t new_value,
|
_Bool hm_update(struct hashmap *_map_, size_t key, size_t new_value, size_t *old_value);
|
||||||
size_t *old_value);
|
|
||||||
_Bool hm_remove(struct hashmap *_map_, size_t key, size_t *out_value);
|
_Bool hm_remove(struct hashmap *_map_, size_t key, size_t *out_value);
|
||||||
_Bool hm_max(struct hashmap *_map_, size_t *key, size_t *value);
|
_Bool hm_max(struct hashmap *_map_, size_t *key, size_t *value);
|
||||||
_Bool hm_min(struct hashmap *_map_, size_t *key, size_t *value);
|
_Bool hm_min(struct hashmap *_map_, size_t *key, size_t *value);
|
||||||
@@ -97,20 +91,14 @@ size_t hm_iter_key(struct hashmap_iter *iter);
|
|||||||
size_t hm_iter_value(struct hashmap_iter *iter);
|
size_t hm_iter_value(struct hashmap_iter *iter);
|
||||||
size_t *hm_iter_rvalue(struct hashmap_iter *iter);
|
size_t *hm_iter_rvalue(struct hashmap_iter *iter);
|
||||||
size_t hm_iter_index(struct hashmap_iter *iter);
|
size_t hm_iter_index(struct hashmap_iter *iter);
|
||||||
static struct hashmap_entry *hm_impl_get_entry(struct hashmap *_map_,
|
static struct hashmap_entry *hm_impl_get_entry(struct hashmap *_map_, size_t key);
|
||||||
size_t key);
|
|
||||||
static size_t hm_impl_calculate_size(size_t required);
|
static size_t hm_impl_calculate_size(size_t required);
|
||||||
struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key,
|
struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val)
|
||||||
struct hashmap_fval *f_val)
|
|
||||||
{
|
{
|
||||||
return hm_new_custom(capacity, load, f_key, f_val, ((void *)0),
|
return hm_new_custom(capacity, load, f_key, f_val, ((void *)0), ((void *)0));
|
||||||
((void *)0));
|
|
||||||
}
|
}
|
||||||
struct hashmap *hm_new_custom(size_t capacity, double load,
|
struct hashmap *hm_new_custom(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val,
|
||||||
struct hashmap_fkey *f_key,
|
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct hashmap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (capacity == 0 || load <= 0 || load >= 1)
|
if (capacity == 0 || load <= 0 || load >= 1)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
@@ -197,8 +185,7 @@ void hm_release(struct hashmap _map_)
|
|||||||
}
|
}
|
||||||
_map_.alloc->free(_map_.buffer);
|
_map_.alloc->free(_map_.buffer);
|
||||||
}
|
}
|
||||||
void hm_customize(struct hashmap *_map_, struct cmc_alloc_node *alloc,
|
void hm_customize(struct hashmap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_map_->alloc = &cmc_alloc_node_default;
|
_map_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -236,8 +223,7 @@ _Bool hm_insert(struct hashmap *_map_, size_t key, size_t value)
|
|||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
target = &(_map_->buffer[pos % _map_->capacity]);
|
target = &(_map_->buffer[pos % _map_->capacity]);
|
||||||
if (target->state == CMC_ES_EMPTY ||
|
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED)
|
||||||
target->state == CMC_ES_DELETED)
|
|
||||||
{
|
{
|
||||||
target->key = key;
|
target->key = key;
|
||||||
target->value = value;
|
target->value = value;
|
||||||
@@ -265,8 +251,7 @@ _Bool hm_insert(struct hashmap *_map_, size_t key, size_t value)
|
|||||||
_map_->callbacks->create();
|
_map_->callbacks->create();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool hm_update(struct hashmap *_map_, size_t key, size_t new_value,
|
_Bool hm_update(struct hashmap *_map_, size_t key, size_t new_value, size_t *old_value)
|
||||||
size_t *old_value)
|
|
||||||
{
|
{
|
||||||
if (hm_empty(_map_))
|
if (hm_empty(_map_))
|
||||||
{
|
{
|
||||||
@@ -457,8 +442,7 @@ _Bool hm_resize(struct hashmap *_map_, size_t capacity)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct hashmap *_new_map_ =
|
struct hashmap *_new_map_ =
|
||||||
hm_new_custom(capacity, _map_->load, _map_->f_key, _map_->f_val,
|
hm_new_custom(capacity, _map_->load, _map_->f_key, _map_->f_val, _map_->alloc, ((void *)0));
|
||||||
_map_->alloc, ((void *)0));
|
|
||||||
if (!_new_map_)
|
if (!_new_map_)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ALLOC;
|
_map_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -493,9 +477,8 @@ success:
|
|||||||
}
|
}
|
||||||
struct hashmap *hm_copy_of(struct hashmap *_map_)
|
struct hashmap *hm_copy_of(struct hashmap *_map_)
|
||||||
{
|
{
|
||||||
struct hashmap *result =
|
struct hashmap *result = hm_new_custom(_map_->capacity * _map_->load, _map_->load, _map_->f_key, _map_->f_val,
|
||||||
hm_new_custom(_map_->capacity * _map_->load, _map_->load, _map_->f_key,
|
_map_->alloc, _map_->callbacks);
|
||||||
_map_->f_val, _map_->alloc, _map_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ERROR;
|
_map_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -528,8 +511,7 @@ struct hashmap *hm_copy_of(struct hashmap *_map_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(result->buffer, _map_->buffer,
|
memcpy(result->buffer, _map_->buffer, sizeof(struct hashmap_entry) * _map_->capacity);
|
||||||
sizeof(struct hashmap_entry) * _map_->capacity);
|
|
||||||
result->count = _map_->count;
|
result->count = _map_->count;
|
||||||
_map_->flag = CMC_FLAG_OK;
|
_map_->flag = CMC_FLAG_OK;
|
||||||
return result;
|
return result;
|
||||||
@@ -543,8 +525,7 @@ _Bool hm_equals(struct hashmap *_map1_, struct hashmap *_map2_)
|
|||||||
struct hashmap_iter iter = hm_iter_start(_map1_);
|
struct hashmap_iter iter = hm_iter_start(_map1_);
|
||||||
for (; !hm_iter_at_end(&iter); hm_iter_next(&iter))
|
for (; !hm_iter_at_end(&iter); hm_iter_next(&iter))
|
||||||
{
|
{
|
||||||
struct hashmap_entry *entry =
|
struct hashmap_entry *entry = hm_impl_get_entry(_map2_, hm_iter_key(&iter));
|
||||||
hm_impl_get_entry(_map2_, hm_iter_key(&iter));
|
|
||||||
if (entry == ((void *)0))
|
if (entry == ((void *)0))
|
||||||
return 0;
|
return 0;
|
||||||
if (_map1_->f_val->cmp(entry->value, hm_iter_value(&iter)) != 0)
|
if (_map1_->f_val->cmp(entry->value, hm_iter_value(&iter)) != 0)
|
||||||
@@ -753,8 +734,7 @@ size_t hm_iter_index(struct hashmap_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->index;
|
return iter->index;
|
||||||
}
|
}
|
||||||
static struct hashmap_entry *hm_impl_get_entry(struct hashmap *_map_,
|
static struct hashmap_entry *hm_impl_get_entry(struct hashmap *_map_, size_t key)
|
||||||
size_t key)
|
|
||||||
{
|
{
|
||||||
size_t hash = _map_->f_key->hash(key);
|
size_t hash = _map_->f_key->hash(key);
|
||||||
size_t pos = hash % _map_->capacity;
|
size_t pos = hash % _map_->capacity;
|
||||||
@@ -770,8 +750,7 @@ static struct hashmap_entry *hm_impl_get_entry(struct hashmap *_map_,
|
|||||||
}
|
}
|
||||||
static size_t hm_impl_calculate_size(size_t required)
|
static size_t hm_impl_calculate_size(size_t required)
|
||||||
{
|
{
|
||||||
const size_t count =
|
const size_t count = sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
||||||
sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
|
||||||
if (cmc_hashtable_primes[count - 1] < required)
|
if (cmc_hashtable_primes[count - 1] < required)
|
||||||
return required;
|
return required;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|||||||
@@ -51,26 +51,19 @@ struct hashmultimap_iter
|
|||||||
_Bool start;
|
_Bool start;
|
||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct hashmultimap *hmm_new(size_t capacity, double load,
|
struct hashmultimap *hmm_new(size_t capacity, double load, struct hashmultimap_fkey *f_key,
|
||||||
struct hashmultimap_fkey *f_key,
|
|
||||||
struct hashmultimap_fval *f_val);
|
struct hashmultimap_fval *f_val);
|
||||||
struct hashmultimap *hmm_new_custom(size_t capacity, double load,
|
struct hashmultimap *hmm_new_custom(size_t capacity, double load, struct hashmultimap_fkey *f_key,
|
||||||
struct hashmultimap_fkey *f_key,
|
struct hashmultimap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct hashmultimap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void hmm_clear(struct hashmultimap *_map_);
|
void hmm_clear(struct hashmultimap *_map_);
|
||||||
void hmm_free(struct hashmultimap *_map_);
|
void hmm_free(struct hashmultimap *_map_);
|
||||||
void hmm_customize(struct hashmultimap *_map_, struct cmc_alloc_node *alloc,
|
void hmm_customize(struct hashmultimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool hmm_insert(struct hashmultimap *_map_, size_t key, size_t value);
|
_Bool hmm_insert(struct hashmultimap *_map_, size_t key, size_t value);
|
||||||
_Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value,
|
_Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value, size_t *old_value);
|
||||||
size_t *old_value);
|
size_t hmm_update_all(struct hashmultimap *_map_, size_t key, size_t new_value, size_t **old_values);
|
||||||
size_t hmm_update_all(struct hashmultimap *_map_, size_t key, size_t new_value,
|
|
||||||
size_t **old_values);
|
|
||||||
_Bool hmm_remove(struct hashmultimap *_map_, size_t key, size_t *out_value);
|
_Bool hmm_remove(struct hashmultimap *_map_, size_t key, size_t *out_value);
|
||||||
size_t hmm_remove_all(struct hashmultimap *_map_, size_t key,
|
size_t hmm_remove_all(struct hashmultimap *_map_, size_t key, size_t **out_values);
|
||||||
size_t **out_values);
|
|
||||||
_Bool hmm_max(struct hashmultimap *_map_, size_t *key, size_t *value);
|
_Bool hmm_max(struct hashmultimap *_map_, size_t *key, size_t *value);
|
||||||
_Bool hmm_min(struct hashmultimap *_map_, size_t *key, size_t *value);
|
_Bool hmm_min(struct hashmultimap *_map_, size_t *key, size_t *value);
|
||||||
size_t hmm_get(struct hashmultimap *_map_, size_t key);
|
size_t hmm_get(struct hashmultimap *_map_, size_t key);
|
||||||
@@ -103,14 +96,11 @@ size_t hmm_iter_key(struct hashmultimap_iter *iter);
|
|||||||
size_t hmm_iter_value(struct hashmultimap_iter *iter);
|
size_t hmm_iter_value(struct hashmultimap_iter *iter);
|
||||||
size_t *hmm_iter_rvalue(struct hashmultimap_iter *iter);
|
size_t *hmm_iter_rvalue(struct hashmultimap_iter *iter);
|
||||||
size_t hmm_iter_index(struct hashmultimap_iter *iter);
|
size_t hmm_iter_index(struct hashmultimap_iter *iter);
|
||||||
struct hashmultimap_entry *hmm_impl_new_entry(struct hashmultimap *_map_,
|
struct hashmultimap_entry *hmm_impl_new_entry(struct hashmultimap *_map_, size_t key, size_t value);
|
||||||
size_t key, size_t value);
|
struct hashmultimap_entry *hmm_impl_get_entry(struct hashmultimap *_map_, size_t key);
|
||||||
struct hashmultimap_entry *hmm_impl_get_entry(struct hashmultimap *_map_,
|
|
||||||
size_t key);
|
|
||||||
size_t hmm_impl_key_count(struct hashmultimap *_map_, size_t key);
|
size_t hmm_impl_key_count(struct hashmultimap *_map_, size_t key);
|
||||||
size_t hmm_impl_calculate_size(size_t required);
|
size_t hmm_impl_calculate_size(size_t required);
|
||||||
struct hashmultimap *hmm_new(size_t capacity, double load,
|
struct hashmultimap *hmm_new(size_t capacity, double load, struct hashmultimap_fkey *f_key,
|
||||||
struct hashmultimap_fkey *f_key,
|
|
||||||
struct hashmultimap_fval *f_val)
|
struct hashmultimap_fval *f_val)
|
||||||
{
|
{
|
||||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
||||||
@@ -124,8 +114,7 @@ struct hashmultimap *hmm_new(size_t capacity, double load,
|
|||||||
struct hashmultimap *_map_ = alloc->malloc(sizeof(struct hashmultimap));
|
struct hashmultimap *_map_ = alloc->malloc(sizeof(struct hashmultimap));
|
||||||
if (!_map_)
|
if (!_map_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
_map_->buffer =
|
_map_->buffer = alloc->calloc(real_capacity, sizeof(struct hashmultimap_entry *[2]));
|
||||||
alloc->calloc(real_capacity, sizeof(struct hashmultimap_entry *[2]));
|
|
||||||
if (!_map_->buffer)
|
if (!_map_->buffer)
|
||||||
{
|
{
|
||||||
alloc->free(_map_);
|
alloc->free(_map_);
|
||||||
@@ -141,10 +130,8 @@ struct hashmultimap *hmm_new(size_t capacity, double load,
|
|||||||
_map_->callbacks = ((void *)0);
|
_map_->callbacks = ((void *)0);
|
||||||
return _map_;
|
return _map_;
|
||||||
}
|
}
|
||||||
struct hashmultimap *hmm_new_custom(size_t capacity, double load,
|
struct hashmultimap *hmm_new_custom(size_t capacity, double load, struct hashmultimap_fkey *f_key,
|
||||||
struct hashmultimap_fkey *f_key,
|
struct hashmultimap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct hashmultimap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity == 0 || load <= 0)
|
if (capacity == 0 || load <= 0)
|
||||||
@@ -159,8 +146,7 @@ struct hashmultimap *hmm_new_custom(size_t capacity, double load,
|
|||||||
struct hashmultimap *_map_ = alloc->malloc(sizeof(struct hashmultimap));
|
struct hashmultimap *_map_ = alloc->malloc(sizeof(struct hashmultimap));
|
||||||
if (!_map_)
|
if (!_map_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
_map_->buffer =
|
_map_->buffer = alloc->calloc(real_capacity, sizeof(struct hashmultimap_entry *[2]));
|
||||||
alloc->calloc(real_capacity, sizeof(struct hashmultimap_entry *[2]));
|
|
||||||
if (!_map_->buffer)
|
if (!_map_->buffer)
|
||||||
{
|
{
|
||||||
alloc->free(_map_);
|
alloc->free(_map_);
|
||||||
@@ -192,8 +178,7 @@ void hmm_clear(struct hashmultimap *_map_)
|
|||||||
scan = next;
|
scan = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memset(_map_->buffer, 0,
|
memset(_map_->buffer, 0, sizeof(struct hashmultimap_entry *[2]) * _map_->capacity);
|
||||||
sizeof(struct hashmultimap_entry *[2]) * _map_->capacity);
|
|
||||||
_map_->count = 0;
|
_map_->count = 0;
|
||||||
_map_->flag = CMC_FLAG_OK;
|
_map_->flag = CMC_FLAG_OK;
|
||||||
}
|
}
|
||||||
@@ -232,8 +217,7 @@ void hmm_free(struct hashmultimap *_map_)
|
|||||||
_map_->alloc->free(_map_->buffer);
|
_map_->alloc->free(_map_->buffer);
|
||||||
_map_->alloc->free(_map_);
|
_map_->alloc->free(_map_);
|
||||||
}
|
}
|
||||||
void hmm_customize(struct hashmultimap *_map_, struct cmc_alloc_node *alloc,
|
void hmm_customize(struct hashmultimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_map_->alloc = &cmc_alloc_node_default;
|
_map_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -269,8 +253,7 @@ _Bool hmm_insert(struct hashmultimap *_map_, size_t key, size_t value)
|
|||||||
_map_->callbacks->create();
|
_map_->callbacks->create();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value,
|
_Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value, size_t *old_value)
|
||||||
size_t *old_value)
|
|
||||||
{
|
{
|
||||||
if (hmm_empty(_map_))
|
if (hmm_empty(_map_))
|
||||||
{
|
{
|
||||||
@@ -291,8 +274,7 @@ _Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value,
|
|||||||
_map_->callbacks->update();
|
_map_->callbacks->update();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
size_t hmm_update_all(struct hashmultimap *_map_, size_t key, size_t new_value,
|
size_t hmm_update_all(struct hashmultimap *_map_, size_t key, size_t new_value, size_t **old_values)
|
||||||
size_t **old_values)
|
|
||||||
{
|
{
|
||||||
if (hmm_empty(_map_))
|
if (hmm_empty(_map_))
|
||||||
{
|
{
|
||||||
@@ -346,10 +328,8 @@ _Bool hmm_remove(struct hashmultimap *_map_, size_t key, size_t *out_value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t hash = _map_->f_key->hash(key);
|
size_t hash = _map_->f_key->hash(key);
|
||||||
struct hashmultimap_entry **head =
|
struct hashmultimap_entry **head = &(_map_->buffer[hash % _map_->capacity][0]);
|
||||||
&(_map_->buffer[hash % _map_->capacity][0]);
|
struct hashmultimap_entry **tail = &(_map_->buffer[hash % _map_->capacity][1]);
|
||||||
struct hashmultimap_entry **tail =
|
|
||||||
&(_map_->buffer[hash % _map_->capacity][1]);
|
|
||||||
if (*head == ((void *)0))
|
if (*head == ((void *)0))
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_NOT_FOUND;
|
_map_->flag = CMC_FLAG_NOT_FOUND;
|
||||||
@@ -407,8 +387,7 @@ _Bool hmm_remove(struct hashmultimap *_map_, size_t key, size_t *out_value)
|
|||||||
_map_->callbacks->delete ();
|
_map_->callbacks->delete ();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
size_t hmm_remove_all(struct hashmultimap *_map_, size_t key,
|
size_t hmm_remove_all(struct hashmultimap *_map_, size_t key, size_t **out_values)
|
||||||
size_t **out_values)
|
|
||||||
{
|
{
|
||||||
if (hmm_empty(_map_))
|
if (hmm_empty(_map_))
|
||||||
{
|
{
|
||||||
@@ -416,10 +395,8 @@ size_t hmm_remove_all(struct hashmultimap *_map_, size_t key,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t hash = _map_->f_key->hash(key);
|
size_t hash = _map_->f_key->hash(key);
|
||||||
struct hashmultimap_entry **head =
|
struct hashmultimap_entry **head = &(_map_->buffer[hash % _map_->capacity][0]);
|
||||||
&(_map_->buffer[hash % _map_->capacity][0]);
|
struct hashmultimap_entry **tail = &(_map_->buffer[hash % _map_->capacity][1]);
|
||||||
struct hashmultimap_entry **tail =
|
|
||||||
&(_map_->buffer[hash % _map_->capacity][1]);
|
|
||||||
if (*head == ((void *)0))
|
if (*head == ((void *)0))
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_NOT_FOUND;
|
_map_->flag = CMC_FLAG_NOT_FOUND;
|
||||||
@@ -643,8 +620,7 @@ _Bool hmm_resize(struct hashmultimap *_map_, size_t capacity)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct hashmultimap *_new_map_ =
|
struct hashmultimap *_new_map_ =
|
||||||
hmm_new_custom(capacity, _map_->load, _map_->f_key, _map_->f_val,
|
hmm_new_custom(capacity, _map_->load, _map_->f_key, _map_->f_val, _map_->alloc, ((void *)0));
|
||||||
_map_->alloc, ((void *)0));
|
|
||||||
if (!_new_map_)
|
if (!_new_map_)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ALLOC;
|
_map_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -679,9 +655,8 @@ success:
|
|||||||
}
|
}
|
||||||
struct hashmultimap *hmm_copy_of(struct hashmultimap *_map_)
|
struct hashmultimap *hmm_copy_of(struct hashmultimap *_map_)
|
||||||
{
|
{
|
||||||
struct hashmultimap *result =
|
struct hashmultimap *result = hmm_new_custom(_map_->capacity * _map_->load, _map_->load, _map_->f_key, _map_->f_val,
|
||||||
hmm_new_custom(_map_->capacity * _map_->load, _map_->load, _map_->f_key,
|
_map_->alloc, ((void *)0));
|
||||||
_map_->f_val, _map_->alloc, ((void *)0));
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ERROR;
|
_map_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -935,11 +910,9 @@ size_t hmm_iter_index(struct hashmultimap_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->index;
|
return iter->index;
|
||||||
}
|
}
|
||||||
struct hashmultimap_entry *hmm_impl_new_entry(struct hashmultimap *_map_,
|
struct hashmultimap_entry *hmm_impl_new_entry(struct hashmultimap *_map_, size_t key, size_t value)
|
||||||
size_t key, size_t value)
|
|
||||||
{
|
{
|
||||||
struct hashmultimap_entry *entry =
|
struct hashmultimap_entry *entry = _map_->alloc->malloc(sizeof(struct hashmultimap_entry));
|
||||||
_map_->alloc->malloc(sizeof(struct hashmultimap_entry));
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
entry->key = key;
|
entry->key = key;
|
||||||
@@ -948,8 +921,7 @@ struct hashmultimap_entry *hmm_impl_new_entry(struct hashmultimap *_map_,
|
|||||||
entry->prev = ((void *)0);
|
entry->prev = ((void *)0);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
struct hashmultimap_entry *hmm_impl_get_entry(struct hashmultimap *_map_,
|
struct hashmultimap_entry *hmm_impl_get_entry(struct hashmultimap *_map_, size_t key)
|
||||||
size_t key)
|
|
||||||
{
|
{
|
||||||
size_t hash = _map_->f_key->hash(key);
|
size_t hash = _map_->f_key->hash(key);
|
||||||
struct hashmultimap_entry *entry = _map_->buffer[hash % _map_->capacity][0];
|
struct hashmultimap_entry *entry = _map_->buffer[hash % _map_->capacity][0];
|
||||||
@@ -978,8 +950,7 @@ size_t hmm_impl_key_count(struct hashmultimap *_map_, size_t key)
|
|||||||
}
|
}
|
||||||
size_t hmm_impl_calculate_size(size_t required)
|
size_t hmm_impl_calculate_size(size_t required)
|
||||||
{
|
{
|
||||||
const size_t count =
|
const size_t count = sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
||||||
sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
|
||||||
if (cmc_hashtable_primes[count - 1] < required)
|
if (cmc_hashtable_primes[count - 1] < required)
|
||||||
return required;
|
return required;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|||||||
+51
-104
@@ -41,16 +41,12 @@ struct hashmultiset_iter
|
|||||||
_Bool start;
|
_Bool start;
|
||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct hashmultiset *hms_new(size_t capacity, double load,
|
struct hashmultiset *hms_new(size_t capacity, double load, struct hashmultiset_fval *f_val);
|
||||||
struct hashmultiset_fval *f_val);
|
struct hashmultiset *hms_new_custom(size_t capacity, double load, struct hashmultiset_fval *f_val,
|
||||||
struct hashmultiset *hms_new_custom(size_t capacity, double load,
|
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct hashmultiset_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
void hms_clear(struct hashmultiset *_set_);
|
void hms_clear(struct hashmultiset *_set_);
|
||||||
void hms_free(struct hashmultiset *_set_);
|
void hms_free(struct hashmultiset *_set_);
|
||||||
void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc,
|
void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool hms_insert(struct hashmultiset *_set_, size_t value);
|
_Bool hms_insert(struct hashmultiset *_set_, size_t value);
|
||||||
_Bool hms_insert_many(struct hashmultiset *_set_, size_t value, size_t count);
|
_Bool hms_insert_many(struct hashmultiset *_set_, size_t value, size_t count);
|
||||||
_Bool hms_update(struct hashmultiset *_set_, size_t value, size_t multiplicity);
|
_Bool hms_update(struct hashmultiset *_set_, size_t value, size_t multiplicity);
|
||||||
@@ -72,24 +68,16 @@ struct hashmultiset *hms_copy_of(struct hashmultiset *_set_);
|
|||||||
_Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
_Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct cmc_string hms_to_string(struct hashmultiset *_set_);
|
struct cmc_string hms_to_string(struct hashmultiset *_set_);
|
||||||
_Bool hms_print(struct hashmultiset *_set_, FILE *fptr);
|
_Bool hms_print(struct hashmultiset *_set_, FILE *fptr);
|
||||||
struct hashmultiset *hms_union(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_union(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *_set2_);
|
struct hashmultiset *hms_intersection(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *hms_intersection(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *_set2_);
|
struct hashmultiset *hms_summation(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *hms_difference(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_symmetric_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *_set2_);
|
|
||||||
struct hashmultiset *hms_summation(struct hashmultiset *_set1_,
|
|
||||||
struct hashmultiset *_set2_);
|
|
||||||
struct hashmultiset *hms_symmetric_difference(struct hashmultiset *_set1_,
|
|
||||||
struct hashmultiset *_set2_);
|
|
||||||
_Bool hms_is_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
_Bool hms_is_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
_Bool hms_is_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
_Bool hms_is_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
_Bool hms_is_proper_subset(struct hashmultiset *_set1_,
|
_Bool hms_is_proper_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *_set2_);
|
_Bool hms_is_proper_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
_Bool hms_is_proper_superset(struct hashmultiset *_set1_,
|
_Bool hms_is_disjointset(struct hashmultiset *_set1_, struct hashmultiset *_set2_);
|
||||||
struct hashmultiset *_set2_);
|
|
||||||
_Bool hms_is_disjointset(struct hashmultiset *_set1_,
|
|
||||||
struct hashmultiset *_set2_);
|
|
||||||
struct hashmultiset_iter hms_iter_start(struct hashmultiset *target);
|
struct hashmultiset_iter hms_iter_start(struct hashmultiset *target);
|
||||||
struct hashmultiset_iter hms_iter_end(struct hashmultiset *target);
|
struct hashmultiset_iter hms_iter_end(struct hashmultiset *target);
|
||||||
_Bool hms_iter_at_start(struct hashmultiset_iter *iter);
|
_Bool hms_iter_at_start(struct hashmultiset_iter *iter);
|
||||||
@@ -104,16 +92,11 @@ _Bool hms_iter_go_to(struct hashmultiset_iter *iter, size_t index);
|
|||||||
size_t hms_iter_value(struct hashmultiset_iter *iter);
|
size_t hms_iter_value(struct hashmultiset_iter *iter);
|
||||||
size_t hms_iter_multiplicity(struct hashmultiset_iter *iter);
|
size_t hms_iter_multiplicity(struct hashmultiset_iter *iter);
|
||||||
size_t hms_iter_index(struct hashmultiset_iter *iter);
|
size_t hms_iter_index(struct hashmultiset_iter *iter);
|
||||||
static size_t hms_impl_multiplicity_of(struct hashmultiset *_set_,
|
static size_t hms_impl_multiplicity_of(struct hashmultiset *_set_, size_t value);
|
||||||
size_t value);
|
static struct hashmultiset_entry *hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value, _Bool *new_node);
|
||||||
static struct hashmultiset_entry *
|
static struct hashmultiset_entry *hms_impl_get_entry(struct hashmultiset *_set_, size_t value);
|
||||||
hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value,
|
|
||||||
_Bool *new_node);
|
|
||||||
static struct hashmultiset_entry *hms_impl_get_entry(struct hashmultiset *_set_,
|
|
||||||
size_t value);
|
|
||||||
static size_t hms_impl_calculate_size(size_t required);
|
static size_t hms_impl_calculate_size(size_t required);
|
||||||
struct hashmultiset *hms_new(size_t capacity, double load,
|
struct hashmultiset *hms_new(size_t capacity, double load, struct hashmultiset_fval *f_val)
|
||||||
struct hashmultiset_fval *f_val)
|
|
||||||
{
|
{
|
||||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
||||||
if (capacity == 0 || load <= 0 || load >= 1)
|
if (capacity == 0 || load <= 0 || load >= 1)
|
||||||
@@ -126,8 +109,7 @@ struct hashmultiset *hms_new(size_t capacity, double load,
|
|||||||
struct hashmultiset *_set_ = alloc->malloc(sizeof(struct hashmultiset));
|
struct hashmultiset *_set_ = alloc->malloc(sizeof(struct hashmultiset));
|
||||||
if (!_set_)
|
if (!_set_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
_set_->buffer =
|
_set_->buffer = alloc->calloc(real_capacity, sizeof(struct hashmultiset_entry));
|
||||||
alloc->calloc(real_capacity, sizeof(struct hashmultiset_entry));
|
|
||||||
if (!_set_->buffer)
|
if (!_set_->buffer)
|
||||||
{
|
{
|
||||||
alloc->free(_set_);
|
alloc->free(_set_);
|
||||||
@@ -143,10 +125,8 @@ struct hashmultiset *hms_new(size_t capacity, double load,
|
|||||||
_set_->callbacks = ((void *)0);
|
_set_->callbacks = ((void *)0);
|
||||||
return _set_;
|
return _set_;
|
||||||
}
|
}
|
||||||
struct hashmultiset *hms_new_custom(size_t capacity, double load,
|
struct hashmultiset *hms_new_custom(size_t capacity, double load, struct hashmultiset_fval *f_val,
|
||||||
struct hashmultiset_fval *f_val,
|
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (capacity == 0 || load <= 0 || load >= 1)
|
if (capacity == 0 || load <= 0 || load >= 1)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
@@ -160,8 +140,7 @@ struct hashmultiset *hms_new_custom(size_t capacity, double load,
|
|||||||
struct hashmultiset *_set_ = alloc->malloc(sizeof(struct hashmultiset));
|
struct hashmultiset *_set_ = alloc->malloc(sizeof(struct hashmultiset));
|
||||||
if (!_set_)
|
if (!_set_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
_set_->buffer =
|
_set_->buffer = alloc->calloc(real_capacity, sizeof(struct hashmultiset_entry));
|
||||||
alloc->calloc(real_capacity, sizeof(struct hashmultiset_entry));
|
|
||||||
if (!_set_->buffer)
|
if (!_set_->buffer)
|
||||||
{
|
{
|
||||||
alloc->free(_set_);
|
alloc->free(_set_);
|
||||||
@@ -190,8 +169,7 @@ void hms_clear(struct hashmultiset *_set_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memset(_set_->buffer, 0,
|
memset(_set_->buffer, 0, sizeof(struct hashmultiset_entry) * _set_->capacity);
|
||||||
sizeof(struct hashmultiset_entry) * _set_->capacity);
|
|
||||||
_set_->count = 0;
|
_set_->count = 0;
|
||||||
_set_->flag = CMC_FLAG_OK;
|
_set_->flag = CMC_FLAG_OK;
|
||||||
}
|
}
|
||||||
@@ -211,8 +189,7 @@ void hms_free(struct hashmultiset *_set_)
|
|||||||
_set_->alloc->free(_set_->buffer);
|
_set_->alloc->free(_set_->buffer);
|
||||||
_set_->alloc->free(_set_);
|
_set_->alloc->free(_set_);
|
||||||
}
|
}
|
||||||
void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc,
|
void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_set_->alloc = &cmc_alloc_node_default;
|
_set_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -224,8 +201,7 @@ void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc,
|
|||||||
_Bool hms_insert(struct hashmultiset *_set_, size_t value)
|
_Bool hms_insert(struct hashmultiset *_set_, size_t value)
|
||||||
{
|
{
|
||||||
_Bool new_node;
|
_Bool new_node;
|
||||||
struct hashmultiset_entry *entry =
|
struct hashmultiset_entry *entry = hms_impl_insert_and_return(_set_, value, &new_node);
|
||||||
hms_impl_insert_and_return(_set_, value, &new_node);
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ERROR;
|
_set_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -244,8 +220,7 @@ _Bool hms_insert_many(struct hashmultiset *_set_, size_t value, size_t count)
|
|||||||
if (count == 0)
|
if (count == 0)
|
||||||
goto success;
|
goto success;
|
||||||
_Bool new_node;
|
_Bool new_node;
|
||||||
struct hashmultiset_entry *entry =
|
struct hashmultiset_entry *entry = hms_impl_insert_and_return(_set_, value, &new_node);
|
||||||
hms_impl_insert_and_return(_set_, value, &new_node);
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ERROR;
|
_set_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -278,14 +253,12 @@ _Bool hms_update(struct hashmultiset *_set_, size_t value, size_t multiplicity)
|
|||||||
goto success;
|
goto success;
|
||||||
}
|
}
|
||||||
_Bool new_node;
|
_Bool new_node;
|
||||||
struct hashmultiset_entry *entry =
|
struct hashmultiset_entry *entry = hms_impl_insert_and_return(_set_, value, &new_node);
|
||||||
hms_impl_insert_and_return(_set_, value, &new_node);
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return 0;
|
return 0;
|
||||||
if (new_node)
|
if (new_node)
|
||||||
_set_->cardinality++;
|
_set_->cardinality++;
|
||||||
_set_->cardinality =
|
_set_->cardinality = (_set_->cardinality - entry->multiplicity) + multiplicity;
|
||||||
(_set_->cardinality - entry->multiplicity) + multiplicity;
|
|
||||||
entry->multiplicity = multiplicity;
|
entry->multiplicity = multiplicity;
|
||||||
success:
|
success:
|
||||||
_set_->flag = CMC_FLAG_OK;
|
_set_->flag = CMC_FLAG_OK;
|
||||||
@@ -461,8 +434,7 @@ _Bool hms_resize(struct hashmultiset *_set_, size_t capacity)
|
|||||||
_set_->flag = CMC_FLAG_INVALID;
|
_set_->flag = CMC_FLAG_INVALID;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct hashmultiset *_new_set_ = hms_new_custom(
|
struct hashmultiset *_new_set_ = hms_new_custom(capacity, _set_->load, _set_->f_val, _set_->alloc, ((void *)0));
|
||||||
capacity, _set_->load, _set_->f_val, _set_->alloc, ((void *)0));
|
|
||||||
if (!_new_set_)
|
if (!_new_set_)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ERROR;
|
_set_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -471,8 +443,7 @@ _Bool hms_resize(struct hashmultiset *_set_, size_t capacity)
|
|||||||
struct hashmultiset_iter iter = hms_iter_start(_set_);
|
struct hashmultiset_iter iter = hms_iter_start(_set_);
|
||||||
for (; !hms_iter_at_end(&iter); hms_iter_next(&iter))
|
for (; !hms_iter_at_end(&iter); hms_iter_next(&iter))
|
||||||
{
|
{
|
||||||
hms_insert_many(_new_set_, hms_iter_value(&iter),
|
hms_insert_many(_new_set_, hms_iter_value(&iter), hms_iter_multiplicity(&iter));
|
||||||
hms_iter_multiplicity(&iter));
|
|
||||||
}
|
}
|
||||||
if (_set_->count != _new_set_->count)
|
if (_set_->count != _new_set_->count)
|
||||||
{
|
{
|
||||||
@@ -496,8 +467,7 @@ success:
|
|||||||
struct hashmultiset *hms_copy_of(struct hashmultiset *_set_)
|
struct hashmultiset *hms_copy_of(struct hashmultiset *_set_)
|
||||||
{
|
{
|
||||||
struct hashmultiset *result =
|
struct hashmultiset *result =
|
||||||
hms_new_custom(_set_->capacity * _set_->load, _set_->load, _set_->f_val,
|
hms_new_custom(_set_->capacity * _set_->load, _set_->load, _set_->f_val, _set_->alloc, _set_->callbacks);
|
||||||
_set_->alloc, _set_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ERROR;
|
_set_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -524,8 +494,7 @@ struct hashmultiset *hms_copy_of(struct hashmultiset *_set_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(result->buffer, _set_->buffer,
|
memcpy(result->buffer, _set_->buffer, sizeof(struct hashmultiset_entry) * _set_->capacity);
|
||||||
sizeof(struct hashmultiset_entry) * _set_->capacity);
|
|
||||||
result->count = _set_->count;
|
result->count = _set_->count;
|
||||||
result->cardinality = _set_->cardinality;
|
result->cardinality = _set_->cardinality;
|
||||||
_set_->flag = CMC_FLAG_OK;
|
_set_->flag = CMC_FLAG_OK;
|
||||||
@@ -544,8 +513,7 @@ _Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
|||||||
struct hashmultiset_iter iter = hms_iter_start(_set1_);
|
struct hashmultiset_iter iter = hms_iter_start(_set1_);
|
||||||
for (; !hms_iter_at_end(&iter); hms_iter_next(&iter))
|
for (; !hms_iter_at_end(&iter); hms_iter_next(&iter))
|
||||||
{
|
{
|
||||||
struct hashmultiset_entry *entry =
|
struct hashmultiset_entry *entry = hms_impl_get_entry(_set2_, hms_iter_value(&iter));
|
||||||
hms_impl_get_entry(_set2_, hms_iter_value(&iter));
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return 0;
|
return 0;
|
||||||
if (entry->multiplicity != hms_iter_multiplicity(&iter))
|
if (entry->multiplicity != hms_iter_multiplicity(&iter))
|
||||||
@@ -553,12 +521,10 @@ _Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct hashmultiset *hms_union(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_union(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct hashmultiset *_set_r_ =
|
struct hashmultiset *_set_r_ =
|
||||||
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct hashmultiset_iter iter1 = hms_iter_start(_set1_);
|
struct hashmultiset_iter iter1 = hms_iter_start(_set1_);
|
||||||
@@ -582,16 +548,13 @@ struct hashmultiset *hms_union(struct hashmultiset *_set1_,
|
|||||||
_set_r_->callbacks = _set1_->callbacks;
|
_set_r_->callbacks = _set1_->callbacks;
|
||||||
return _set_r_;
|
return _set_r_;
|
||||||
}
|
}
|
||||||
struct hashmultiset *hms_intersection(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_intersection(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct hashmultiset *_set_r_ =
|
struct hashmultiset *_set_r_ =
|
||||||
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct hashmultiset *_set_A_ =
|
struct hashmultiset *_set_A_ = _set1_->count < _set2_->count ? _set1_ : _set2_;
|
||||||
_set1_->count < _set2_->count ? _set1_ : _set2_;
|
|
||||||
struct hashmultiset *_set_B_ = _set_A_ == _set1_ ? _set2_ : _set1_;
|
struct hashmultiset *_set_B_ = _set_A_ == _set1_ ? _set2_ : _set1_;
|
||||||
struct hashmultiset_iter iter = hms_iter_start(_set_A_);
|
struct hashmultiset_iter iter = hms_iter_start(_set_A_);
|
||||||
for (; !hms_iter_at_end(&iter); hms_iter_next(&iter))
|
for (; !hms_iter_at_end(&iter); hms_iter_next(&iter))
|
||||||
@@ -605,12 +568,10 @@ struct hashmultiset *hms_intersection(struct hashmultiset *_set1_,
|
|||||||
_set_r_->callbacks = _set1_->callbacks;
|
_set_r_->callbacks = _set1_->callbacks;
|
||||||
return _set_r_;
|
return _set_r_;
|
||||||
}
|
}
|
||||||
struct hashmultiset *hms_difference(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct hashmultiset *_set_r_ =
|
struct hashmultiset *_set_r_ =
|
||||||
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct hashmultiset_iter iter = hms_iter_start(_set1_);
|
struct hashmultiset_iter iter = hms_iter_start(_set1_);
|
||||||
@@ -625,35 +586,29 @@ struct hashmultiset *hms_difference(struct hashmultiset *_set1_,
|
|||||||
_set_r_->callbacks = _set1_->callbacks;
|
_set_r_->callbacks = _set1_->callbacks;
|
||||||
return _set_r_;
|
return _set_r_;
|
||||||
}
|
}
|
||||||
struct hashmultiset *hms_summation(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_summation(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct hashmultiset *_set_r_ =
|
struct hashmultiset *_set_r_ =
|
||||||
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct hashmultiset_iter iter1 = hms_iter_start(_set1_);
|
struct hashmultiset_iter iter1 = hms_iter_start(_set1_);
|
||||||
struct hashmultiset_iter iter2 = hms_iter_start(_set2_);
|
struct hashmultiset_iter iter2 = hms_iter_start(_set2_);
|
||||||
for (; !hms_iter_at_end(&iter1); hms_iter_next(&iter1))
|
for (; !hms_iter_at_end(&iter1); hms_iter_next(&iter1))
|
||||||
{
|
{
|
||||||
hms_insert_many(_set_r_, hms_iter_value(&iter1),
|
hms_insert_many(_set_r_, hms_iter_value(&iter1), hms_iter_multiplicity(&iter1));
|
||||||
hms_iter_multiplicity(&iter1));
|
|
||||||
}
|
}
|
||||||
for (; !hms_iter_at_end(&iter2); hms_iter_next(&iter2))
|
for (; !hms_iter_at_end(&iter2); hms_iter_next(&iter2))
|
||||||
{
|
{
|
||||||
hms_insert_many(_set_r_, hms_iter_value(&iter2),
|
hms_insert_many(_set_r_, hms_iter_value(&iter2), hms_iter_multiplicity(&iter2));
|
||||||
hms_iter_multiplicity(&iter2));
|
|
||||||
}
|
}
|
||||||
_set_r_->callbacks = _set1_->callbacks;
|
_set_r_->callbacks = _set1_->callbacks;
|
||||||
return _set_r_;
|
return _set_r_;
|
||||||
}
|
}
|
||||||
struct hashmultiset *hms_symmetric_difference(struct hashmultiset *_set1_,
|
struct hashmultiset *hms_symmetric_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct hashmultiset *_set_r_ =
|
struct hashmultiset *_set_r_ =
|
||||||
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
hms_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct hashmultiset_iter iter1 = hms_iter_start(_set1_);
|
struct hashmultiset_iter iter1 = hms_iter_start(_set1_);
|
||||||
@@ -708,8 +663,7 @@ _Bool hms_is_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
|||||||
{
|
{
|
||||||
return hms_is_subset(_set2_, _set1_);
|
return hms_is_subset(_set2_, _set1_);
|
||||||
}
|
}
|
||||||
_Bool hms_is_proper_subset(struct hashmultiset *_set1_,
|
_Bool hms_is_proper_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
if (_set1_->count >= _set2_->count)
|
if (_set1_->count >= _set2_->count)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -731,13 +685,11 @@ _Bool hms_is_proper_subset(struct hashmultiset *_set1_,
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool hms_is_proper_superset(struct hashmultiset *_set1_,
|
_Bool hms_is_proper_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
return hms_is_proper_subset(_set2_, _set1_);
|
return hms_is_proper_subset(_set2_, _set1_);
|
||||||
}
|
}
|
||||||
_Bool hms_is_disjointset(struct hashmultiset *_set1_,
|
_Bool hms_is_disjointset(struct hashmultiset *_set1_, struct hashmultiset *_set2_)
|
||||||
struct hashmultiset *_set2_)
|
|
||||||
{
|
{
|
||||||
if (hms_empty(_set1_))
|
if (hms_empty(_set1_))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -952,9 +904,7 @@ static size_t hms_impl_multiplicity_of(struct hashmultiset *_set_, size_t value)
|
|||||||
return 0;
|
return 0;
|
||||||
return entry->multiplicity;
|
return entry->multiplicity;
|
||||||
}
|
}
|
||||||
static struct hashmultiset_entry *
|
static struct hashmultiset_entry *hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value, _Bool *new_node)
|
||||||
hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value,
|
|
||||||
_Bool *new_node)
|
|
||||||
{
|
{
|
||||||
*new_node = 0;
|
*new_node = 0;
|
||||||
struct hashmultiset_entry *entry = hms_impl_get_entry(_set_, value);
|
struct hashmultiset_entry *entry = hms_impl_get_entry(_set_, value);
|
||||||
@@ -986,8 +936,7 @@ hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value,
|
|||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
target = &(_set_->buffer[pos % _set_->capacity]);
|
target = &(_set_->buffer[pos % _set_->capacity]);
|
||||||
if (target->state == CMC_ES_EMPTY ||
|
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED)
|
||||||
target->state == CMC_ES_DELETED)
|
|
||||||
{
|
{
|
||||||
target->value = value;
|
target->value = value;
|
||||||
target->multiplicity = curr_mul;
|
target->multiplicity = curr_mul;
|
||||||
@@ -1016,8 +965,7 @@ hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value,
|
|||||||
_set_->count++;
|
_set_->count++;
|
||||||
return to_return;
|
return to_return;
|
||||||
}
|
}
|
||||||
static struct hashmultiset_entry *hms_impl_get_entry(struct hashmultiset *_set_,
|
static struct hashmultiset_entry *hms_impl_get_entry(struct hashmultiset *_set_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
size_t hash = _set_->f_val->hash(value);
|
size_t hash = _set_->f_val->hash(value);
|
||||||
size_t pos = hash % _set_->capacity;
|
size_t pos = hash % _set_->capacity;
|
||||||
@@ -1033,8 +981,7 @@ static struct hashmultiset_entry *hms_impl_get_entry(struct hashmultiset *_set_,
|
|||||||
}
|
}
|
||||||
static size_t hms_impl_calculate_size(size_t required)
|
static size_t hms_impl_calculate_size(size_t required)
|
||||||
{
|
{
|
||||||
const size_t count =
|
const size_t count = sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
||||||
sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
|
||||||
if (cmc_hashtable_primes[count - 1] < required)
|
if (cmc_hashtable_primes[count - 1] < required)
|
||||||
return required;
|
return required;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|||||||
+18
-42
@@ -39,16 +39,12 @@ struct hashset_iter
|
|||||||
_Bool start;
|
_Bool start;
|
||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct hashset *hs_new(size_t capacity, double load,
|
struct hashset *hs_new(size_t capacity, double load, struct hashset_fval *f_val);
|
||||||
struct hashset_fval *f_val);
|
struct hashset *hs_new_custom(size_t capacity, double load, struct hashset_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct hashset *hs_new_custom(size_t capacity, double load,
|
|
||||||
struct hashset_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void hs_clear(struct hashset *_set_);
|
void hs_clear(struct hashset *_set_);
|
||||||
void hs_free(struct hashset *_set_);
|
void hs_free(struct hashset *_set_);
|
||||||
void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc,
|
void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool hs_insert(struct hashset *_set_, size_t value);
|
_Bool hs_insert(struct hashset *_set_, size_t value);
|
||||||
_Bool hs_remove(struct hashset *_set_, size_t value);
|
_Bool hs_remove(struct hashset *_set_, size_t value);
|
||||||
_Bool hs_max(struct hashset *_set_, size_t *value);
|
_Bool hs_max(struct hashset *_set_, size_t *value);
|
||||||
@@ -68,8 +64,7 @@ _Bool hs_print(struct hashset *_set_, FILE *fptr);
|
|||||||
struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_);
|
struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_);
|
struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_);
|
struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
struct hashset *hs_symmetric_difference(struct hashset *_set1_,
|
struct hashset *hs_symmetric_difference(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
struct hashset *_set2_);
|
|
||||||
_Bool hs_is_subset(struct hashset *_set1_, struct hashset *_set2_);
|
_Bool hs_is_subset(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
_Bool hs_is_superset(struct hashset *_set1_, struct hashset *_set2_);
|
_Bool hs_is_superset(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
_Bool hs_is_proper_subset(struct hashset *_set1_, struct hashset *_set2_);
|
_Bool hs_is_proper_subset(struct hashset *_set1_, struct hashset *_set2_);
|
||||||
@@ -88,8 +83,7 @@ _Bool hs_iter_rewind(struct hashset_iter *iter, size_t steps);
|
|||||||
_Bool hs_iter_go_to(struct hashset_iter *iter, size_t index);
|
_Bool hs_iter_go_to(struct hashset_iter *iter, size_t index);
|
||||||
size_t hs_iter_value(struct hashset_iter *iter);
|
size_t hs_iter_value(struct hashset_iter *iter);
|
||||||
size_t hs_iter_index(struct hashset_iter *iter);
|
size_t hs_iter_index(struct hashset_iter *iter);
|
||||||
static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_,
|
static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_, size_t value);
|
||||||
size_t value);
|
|
||||||
static size_t hs_impl_calculate_size(size_t required);
|
static size_t hs_impl_calculate_size(size_t required);
|
||||||
static struct hashset_iter hs_impl_it_start(struct hashset *_set_);
|
static struct hashset_iter hs_impl_it_start(struct hashset *_set_);
|
||||||
static struct hashset_iter hs_impl_it_end(struct hashset *_set_);
|
static struct hashset_iter hs_impl_it_end(struct hashset *_set_);
|
||||||
@@ -121,9 +115,7 @@ struct hashset *hs_new(size_t capacity, double load, struct hashset_fval *f_val)
|
|||||||
_set_->callbacks = ((void *)0);
|
_set_->callbacks = ((void *)0);
|
||||||
return _set_;
|
return _set_;
|
||||||
}
|
}
|
||||||
struct hashset *hs_new_custom(size_t capacity, double load,
|
struct hashset *hs_new_custom(size_t capacity, double load, struct hashset_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct hashset_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity == 0 || load <= 0 || load >= 1)
|
if (capacity == 0 || load <= 0 || load >= 1)
|
||||||
@@ -186,8 +178,7 @@ void hs_free(struct hashset *_set_)
|
|||||||
_set_->alloc->free(_set_->buffer);
|
_set_->alloc->free(_set_->buffer);
|
||||||
_set_->alloc->free(_set_);
|
_set_->alloc->free(_set_);
|
||||||
}
|
}
|
||||||
void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc,
|
void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_set_->alloc = &cmc_alloc_node_default;
|
_set_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -224,8 +215,7 @@ _Bool hs_insert(struct hashset *_set_, size_t value)
|
|||||||
{
|
{
|
||||||
pos++;
|
pos++;
|
||||||
target = &(_set_->buffer[pos % _set_->capacity]);
|
target = &(_set_->buffer[pos % _set_->capacity]);
|
||||||
if (target->state == CMC_ES_EMPTY ||
|
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED)
|
||||||
target->state == CMC_ES_DELETED)
|
|
||||||
{
|
{
|
||||||
target->value = value;
|
target->value = value;
|
||||||
target->dist = pos - original_pos;
|
target->dist = pos - original_pos;
|
||||||
@@ -371,8 +361,7 @@ _Bool hs_resize(struct hashset *_set_, size_t capacity)
|
|||||||
_set_->flag = CMC_FLAG_INVALID;
|
_set_->flag = CMC_FLAG_INVALID;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct hashset *_new_set_ = hs_new_custom(
|
struct hashset *_new_set_ = hs_new_custom(capacity, _set_->load, _set_->f_val, _set_->alloc, ((void *)0));
|
||||||
capacity, _set_->load, _set_->f_val, _set_->alloc, ((void *)0));
|
|
||||||
if (!_new_set_)
|
if (!_new_set_)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ALLOC;
|
_set_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -406,8 +395,7 @@ success:
|
|||||||
struct hashset *hs_copy_of(struct hashset *_set_)
|
struct hashset *hs_copy_of(struct hashset *_set_)
|
||||||
{
|
{
|
||||||
struct hashset *result =
|
struct hashset *result =
|
||||||
hs_new_custom(_set_->capacity * _set_->load, _set_->load, _set_->f_val,
|
hs_new_custom(_set_->capacity * _set_->load, _set_->load, _set_->f_val, _set_->alloc, _set_->callbacks);
|
||||||
_set_->alloc, _set_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ERROR;
|
_set_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -433,8 +421,7 @@ struct hashset *hs_copy_of(struct hashset *_set_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(result->buffer, _set_->buffer,
|
memcpy(result->buffer, _set_->buffer, sizeof(struct hashset_entry) * _set_->capacity);
|
||||||
sizeof(struct hashset_entry) * _set_->capacity);
|
|
||||||
result->count = _set_->count;
|
result->count = _set_->count;
|
||||||
_set_->flag = CMC_FLAG_OK;
|
_set_->flag = CMC_FLAG_OK;
|
||||||
return result;
|
return result;
|
||||||
@@ -457,9 +444,7 @@ _Bool hs_equals(struct hashset *_set1_, struct hashset *_set2_)
|
|||||||
}
|
}
|
||||||
struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_)
|
struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_)
|
||||||
{
|
{
|
||||||
struct hashset *_set_r_ =
|
struct hashset *_set_r_ = hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
{
|
{
|
||||||
_set1_->flag = CMC_FLAG_ALLOC;
|
_set1_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -481,9 +466,7 @@ struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_)
|
|||||||
}
|
}
|
||||||
struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_)
|
struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_)
|
||||||
{
|
{
|
||||||
struct hashset *_set_r_ =
|
struct hashset *_set_r_ = hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
{
|
{
|
||||||
_set1_->flag = CMC_FLAG_ALLOC;
|
_set1_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -504,9 +487,7 @@ struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_)
|
|||||||
}
|
}
|
||||||
struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_)
|
struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_)
|
||||||
{
|
{
|
||||||
struct hashset *_set_r_ =
|
struct hashset *_set_r_ = hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
{
|
{
|
||||||
_set1_->flag = CMC_FLAG_ALLOC;
|
_set1_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -523,12 +504,9 @@ struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_)
|
|||||||
_set_r_->callbacks = _set1_->callbacks;
|
_set_r_->callbacks = _set1_->callbacks;
|
||||||
return _set_r_;
|
return _set_r_;
|
||||||
}
|
}
|
||||||
struct hashset *hs_symmetric_difference(struct hashset *_set1_,
|
struct hashset *hs_symmetric_difference(struct hashset *_set1_, struct hashset *_set2_)
|
||||||
struct hashset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct hashset *_set_r_ =
|
struct hashset *_set_r_ = hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val, _set1_->alloc, ((void *)0));
|
||||||
hs_new_custom(_set1_->capacity, _set1_->load, _set1_->f_val,
|
|
||||||
_set1_->alloc, ((void *)0));
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
{
|
{
|
||||||
_set1_->flag = CMC_FLAG_ALLOC;
|
_set1_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -803,8 +781,7 @@ size_t hs_iter_index(struct hashset_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->index;
|
return iter->index;
|
||||||
}
|
}
|
||||||
static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_,
|
static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
size_t hash = _set_->f_val->hash(value);
|
size_t hash = _set_->f_val->hash(value);
|
||||||
size_t pos = hash % _set_->capacity;
|
size_t pos = hash % _set_->capacity;
|
||||||
@@ -820,8 +797,7 @@ static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_,
|
|||||||
}
|
}
|
||||||
static size_t hs_impl_calculate_size(size_t required)
|
static size_t hs_impl_calculate_size(size_t required)
|
||||||
{
|
{
|
||||||
const size_t count =
|
const size_t count = sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
||||||
sizeof(cmc_hashtable_primes) / sizeof(cmc_hashtable_primes[0]);
|
|
||||||
if (cmc_hashtable_primes[count - 1] < required)
|
if (cmc_hashtable_primes[count - 1] < required)
|
||||||
return required;
|
return required;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|||||||
+12
-23
@@ -30,15 +30,12 @@ struct heap_iter
|
|||||||
_Bool start;
|
_Bool start;
|
||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct heap *h_new(size_t capacity, enum cmc_heap_order HO,
|
struct heap *h_new(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val);
|
||||||
struct heap_fval *f_val);
|
struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val,
|
||||||
struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO,
|
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct heap_fval *f_val, struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
void h_clear(struct heap *_heap_);
|
void h_clear(struct heap *_heap_);
|
||||||
void h_free(struct heap *_heap_);
|
void h_free(struct heap *_heap_);
|
||||||
void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc,
|
void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool h_insert(struct heap *_heap_, size_t value);
|
_Bool h_insert(struct heap *_heap_, size_t value);
|
||||||
_Bool h_remove(struct heap *_heap_);
|
_Bool h_remove(struct heap *_heap_);
|
||||||
size_t h_peek(struct heap *_heap_);
|
size_t h_peek(struct heap *_heap_);
|
||||||
@@ -68,8 +65,7 @@ size_t h_iter_value(struct heap_iter *iter);
|
|||||||
size_t h_iter_index(struct heap_iter *iter);
|
size_t h_iter_index(struct heap_iter *iter);
|
||||||
static void h_impl_float_up(struct heap *_heap_, size_t index);
|
static void h_impl_float_up(struct heap *_heap_, size_t index);
|
||||||
static void h_impl_float_down(struct heap *_heap_, size_t index);
|
static void h_impl_float_down(struct heap *_heap_, size_t index);
|
||||||
struct heap *h_new(size_t capacity, enum cmc_heap_order HO,
|
struct heap *h_new(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val)
|
||||||
struct heap_fval *f_val)
|
|
||||||
{
|
{
|
||||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
@@ -96,9 +92,8 @@ struct heap *h_new(size_t capacity, enum cmc_heap_order HO,
|
|||||||
_heap_->callbacks = ((void *)0);
|
_heap_->callbacks = ((void *)0);
|
||||||
return _heap_;
|
return _heap_;
|
||||||
}
|
}
|
||||||
struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO,
|
struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val,
|
||||||
struct heap_fval *f_val, struct cmc_alloc_node *alloc,
|
struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
@@ -151,8 +146,7 @@ void h_free(struct heap *_heap_)
|
|||||||
_heap_->alloc->free(_heap_->buffer);
|
_heap_->alloc->free(_heap_->buffer);
|
||||||
_heap_->alloc->free(_heap_);
|
_heap_->alloc->free(_heap_);
|
||||||
}
|
}
|
||||||
void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc,
|
void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_heap_->alloc = &cmc_alloc_node_default;
|
_heap_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -252,8 +246,7 @@ _Bool h_resize(struct heap *_heap_, size_t capacity)
|
|||||||
_heap_->flag = CMC_FLAG_INVALID;
|
_heap_->flag = CMC_FLAG_INVALID;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t *new_buffer =
|
size_t *new_buffer = _heap_->alloc->realloc(_heap_->buffer, sizeof(size_t) * capacity);
|
||||||
_heap_->alloc->realloc(_heap_->buffer, sizeof(size_t) * capacity);
|
|
||||||
if (!new_buffer)
|
if (!new_buffer)
|
||||||
{
|
{
|
||||||
_heap_->flag = CMC_FLAG_ALLOC;
|
_heap_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -268,9 +261,7 @@ success:
|
|||||||
}
|
}
|
||||||
struct heap *h_copy_of(struct heap *_heap_)
|
struct heap *h_copy_of(struct heap *_heap_)
|
||||||
{
|
{
|
||||||
struct heap *result =
|
struct heap *result = h_new_custom(_heap_->capacity, _heap_->HO, _heap_->f_val, _heap_->alloc, _heap_->callbacks);
|
||||||
h_new_custom(_heap_->capacity, _heap_->HO, _heap_->f_val, _heap_->alloc,
|
|
||||||
_heap_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_heap_->flag = CMC_FLAG_ERROR;
|
_heap_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -454,13 +445,11 @@ static void h_impl_float_down(struct heap *_heap_, size_t index)
|
|||||||
size_t L = 2 * index + 1;
|
size_t L = 2 * index + 1;
|
||||||
size_t R = 2 * index + 2;
|
size_t R = 2 * index + 2;
|
||||||
size_t C = index;
|
size_t C = index;
|
||||||
if (L < _heap_->count &&
|
if (L < _heap_->count && _heap_->f_val->cmp(_heap_->buffer[L], _heap_->buffer[C]) * mod > 0)
|
||||||
_heap_->f_val->cmp(_heap_->buffer[L], _heap_->buffer[C]) * mod > 0)
|
|
||||||
{
|
{
|
||||||
C = L;
|
C = L;
|
||||||
}
|
}
|
||||||
if (R < _heap_->count &&
|
if (R < _heap_->count && _heap_->f_val->cmp(_heap_->buffer[R], _heap_->buffer[C]) * mod > 0)
|
||||||
_heap_->f_val->cmp(_heap_->buffer[R], _heap_->buffer[C]) * mod > 0)
|
|
||||||
{
|
{
|
||||||
C = R;
|
C = R;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,11 @@ struct intervalheap_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct intervalheap *ih_new(size_t capacity, struct intervalheap_fval *f_val);
|
struct intervalheap *ih_new(size_t capacity, struct intervalheap_fval *f_val);
|
||||||
struct intervalheap *ih_new_custom(size_t capacity,
|
struct intervalheap *ih_new_custom(size_t capacity, struct intervalheap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct intervalheap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void ih_clear(struct intervalheap *_heap_);
|
void ih_clear(struct intervalheap *_heap_);
|
||||||
void ih_free(struct intervalheap *_heap_);
|
void ih_free(struct intervalheap *_heap_);
|
||||||
void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc,
|
void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool ih_insert(struct intervalheap *_heap_, size_t value);
|
_Bool ih_insert(struct intervalheap *_heap_, size_t value);
|
||||||
_Bool ih_remove_max(struct intervalheap *_heap_);
|
_Bool ih_remove_max(struct intervalheap *_heap_);
|
||||||
_Bool ih_remove_min(struct intervalheap *_heap_);
|
_Bool ih_remove_min(struct intervalheap *_heap_);
|
||||||
@@ -100,9 +97,7 @@ struct intervalheap *ih_new(size_t capacity, struct intervalheap_fval *f_val)
|
|||||||
_heap_->callbacks = ((void *)0);
|
_heap_->callbacks = ((void *)0);
|
||||||
return _heap_;
|
return _heap_;
|
||||||
}
|
}
|
||||||
struct intervalheap *ih_new_custom(size_t capacity,
|
struct intervalheap *ih_new_custom(size_t capacity, struct intervalheap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct intervalheap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity == 0 || capacity == 0xffffffffffffffffULL)
|
if (capacity == 0 || capacity == 0xffffffffffffffffULL)
|
||||||
@@ -156,8 +151,7 @@ void ih_free(struct intervalheap *_heap_)
|
|||||||
_heap_->alloc->free(_heap_->buffer);
|
_heap_->alloc->free(_heap_->buffer);
|
||||||
_heap_->alloc->free(_heap_);
|
_heap_->alloc->free(_heap_);
|
||||||
}
|
}
|
||||||
void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc,
|
void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_heap_->alloc = &cmc_alloc_node_default;
|
_heap_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -405,8 +399,7 @@ _Bool ih_resize(struct intervalheap *_heap_, size_t capacity)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
capacity += capacity % 2;
|
capacity += capacity % 2;
|
||||||
size_t(*new_buffer)[2] =
|
size_t(*new_buffer)[2] = _heap_->alloc->realloc(_heap_->buffer, sizeof(size_t[2]) * capacity);
|
||||||
_heap_->alloc->realloc(_heap_->buffer, sizeof(size_t[2]) * capacity);
|
|
||||||
if (!new_buffer)
|
if (!new_buffer)
|
||||||
{
|
{
|
||||||
_heap_->flag = CMC_FLAG_ALLOC;
|
_heap_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -414,8 +407,7 @@ _Bool ih_resize(struct intervalheap *_heap_, size_t capacity)
|
|||||||
}
|
}
|
||||||
if (capacity > _heap_->capacity)
|
if (capacity > _heap_->capacity)
|
||||||
{
|
{
|
||||||
memset(new_buffer + _heap_->capacity, 0,
|
memset(new_buffer + _heap_->capacity, 0, sizeof(size_t[2]) * (capacity - _heap_->capacity));
|
||||||
sizeof(size_t[2]) * (capacity - _heap_->capacity));
|
|
||||||
}
|
}
|
||||||
_heap_->buffer = new_buffer;
|
_heap_->buffer = new_buffer;
|
||||||
_heap_->capacity = capacity;
|
_heap_->capacity = capacity;
|
||||||
@@ -427,16 +419,14 @@ success:
|
|||||||
}
|
}
|
||||||
struct intervalheap *ih_copy_of(struct intervalheap *_heap_)
|
struct intervalheap *ih_copy_of(struct intervalheap *_heap_)
|
||||||
{
|
{
|
||||||
struct intervalheap *result =
|
struct intervalheap *result = _heap_->alloc->malloc(sizeof(struct intervalheap));
|
||||||
_heap_->alloc->malloc(sizeof(struct intervalheap));
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_heap_->flag = CMC_FLAG_ALLOC;
|
_heap_->flag = CMC_FLAG_ALLOC;
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
memcpy(result, _heap_, sizeof(struct intervalheap));
|
memcpy(result, _heap_, sizeof(struct intervalheap));
|
||||||
result->buffer =
|
result->buffer = _heap_->alloc->malloc(sizeof(size_t[2]) * _heap_->capacity);
|
||||||
_heap_->alloc->malloc(sizeof(size_t[2]) * _heap_->capacity);
|
|
||||||
if (!result->buffer)
|
if (!result->buffer)
|
||||||
{
|
{
|
||||||
_heap_->alloc->free(result);
|
_heap_->alloc->free(result);
|
||||||
@@ -446,12 +436,10 @@ struct intervalheap *ih_copy_of(struct intervalheap *_heap_)
|
|||||||
if (_heap_->f_val->cpy)
|
if (_heap_->f_val->cpy)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < _heap_->count; i++)
|
for (size_t i = 0; i < _heap_->count; i++)
|
||||||
result->buffer[i / 2][i % 2] =
|
result->buffer[i / 2][i % 2] = _heap_->f_val->cpy(_heap_->buffer[i / 2][i % 2]);
|
||||||
_heap_->f_val->cpy(_heap_->buffer[i / 2][i % 2]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(result->buffer, _heap_->buffer,
|
memcpy(result->buffer, _heap_->buffer, sizeof(size_t[2]) * _heap_->capacity);
|
||||||
sizeof(size_t[2]) * _heap_->capacity);
|
|
||||||
result->capacity = _heap_->capacity;
|
result->capacity = _heap_->capacity;
|
||||||
result->size = _heap_->size;
|
result->size = _heap_->size;
|
||||||
result->count = _heap_->count;
|
result->count = _heap_->count;
|
||||||
@@ -666,11 +654,9 @@ static void ih_impl_float_down_max(struct intervalheap *_heap_)
|
|||||||
size_t(*L)[2] = &(_heap_->buffer[L_index]);
|
size_t(*L)[2] = &(_heap_->buffer[L_index]);
|
||||||
size_t(*R)[2] = &(_heap_->buffer[R_index]);
|
size_t(*R)[2] = &(_heap_->buffer[R_index]);
|
||||||
if (R_index == _heap_->size - 1 && _heap_->count % 2 != 0)
|
if (R_index == _heap_->size - 1 && _heap_->count % 2 != 0)
|
||||||
child = _heap_->f_val->cmp((*L)[1], (*R)[0]) > 0 ? L_index
|
child = _heap_->f_val->cmp((*L)[1], (*R)[0]) > 0 ? L_index : R_index;
|
||||||
: R_index;
|
|
||||||
else
|
else
|
||||||
child = _heap_->f_val->cmp((*L)[1], (*R)[1]) > 0 ? L_index
|
child = _heap_->f_val->cmp((*L)[1], (*R)[1]) > 0 ? L_index : R_index;
|
||||||
: R_index;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
child = L_index;
|
child = L_index;
|
||||||
@@ -716,8 +702,7 @@ static void ih_impl_float_down_min(struct intervalheap *_heap_)
|
|||||||
{
|
{
|
||||||
size_t(*L)[2] = &(_heap_->buffer[L_index]);
|
size_t(*L)[2] = &(_heap_->buffer[L_index]);
|
||||||
size_t(*R)[2] = &(_heap_->buffer[R_index]);
|
size_t(*R)[2] = &(_heap_->buffer[R_index]);
|
||||||
child =
|
child = _heap_->f_val->cmp((*L)[0], (*R)[0]) < 0 ? L_index : R_index;
|
||||||
_heap_->f_val->cmp((*L)[0], (*R)[0]) < 0 ? L_index : R_index;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
child = L_index;
|
child = L_index;
|
||||||
|
|||||||
+10
-20
@@ -37,13 +37,11 @@ struct linkedlist_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct linkedlist *ll_new(struct linkedlist_fval *f_val);
|
struct linkedlist *ll_new(struct linkedlist_fval *f_val);
|
||||||
struct linkedlist *ll_new_custom(struct linkedlist_fval *f_val,
|
struct linkedlist *ll_new_custom(struct linkedlist_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void ll_clear(struct linkedlist *_list_);
|
void ll_clear(struct linkedlist *_list_);
|
||||||
void ll_free(struct linkedlist *_list_);
|
void ll_free(struct linkedlist *_list_);
|
||||||
void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc,
|
void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool ll_push_front(struct linkedlist *_list_, size_t value);
|
_Bool ll_push_front(struct linkedlist *_list_, size_t value);
|
||||||
_Bool ll_push_at(struct linkedlist *_list_, size_t value, size_t index);
|
_Bool ll_push_at(struct linkedlist *_list_, size_t value, size_t index);
|
||||||
_Bool ll_push_back(struct linkedlist *_list_, size_t value);
|
_Bool ll_push_back(struct linkedlist *_list_, size_t value);
|
||||||
@@ -67,10 +65,8 @@ void ll_free_node(struct linkedlist *_list_, struct linkedlist_node *_node_);
|
|||||||
struct linkedlist_node *ll_head(struct linkedlist *_list_);
|
struct linkedlist_node *ll_head(struct linkedlist *_list_);
|
||||||
struct linkedlist_node *ll_get_node(struct linkedlist *_list_, size_t index);
|
struct linkedlist_node *ll_get_node(struct linkedlist *_list_, size_t index);
|
||||||
struct linkedlist_node *ll_tail(struct linkedlist *_list_);
|
struct linkedlist_node *ll_tail(struct linkedlist *_list_);
|
||||||
_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_,
|
_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value);
|
||||||
size_t value);
|
_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value);
|
||||||
_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_,
|
|
||||||
size_t value);
|
|
||||||
_Bool ll_del_next(struct linkedlist *_owner_, struct linkedlist_node *_node_);
|
_Bool ll_del_next(struct linkedlist *_owner_, struct linkedlist_node *_node_);
|
||||||
_Bool ll_del_curr(struct linkedlist *_owner_, struct linkedlist_node *_node_);
|
_Bool ll_del_curr(struct linkedlist *_owner_, struct linkedlist_node *_node_);
|
||||||
_Bool ll_del_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_);
|
_Bool ll_del_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_);
|
||||||
@@ -108,8 +104,7 @@ struct linkedlist *ll_new(struct linkedlist_fval *f_val)
|
|||||||
_list_->callbacks = ((void *)0);
|
_list_->callbacks = ((void *)0);
|
||||||
return _list_;
|
return _list_;
|
||||||
}
|
}
|
||||||
struct linkedlist *ll_new_custom(struct linkedlist_fval *f_val,
|
struct linkedlist *ll_new_custom(struct linkedlist_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (!f_val)
|
if (!f_val)
|
||||||
@@ -151,8 +146,7 @@ void ll_free(struct linkedlist *_list_)
|
|||||||
ll_clear(_list_);
|
ll_clear(_list_);
|
||||||
_list_->alloc->free(_list_);
|
_list_->alloc->free(_list_);
|
||||||
}
|
}
|
||||||
void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc,
|
void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_list_->alloc = &cmc_alloc_node_default;
|
_list_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -400,8 +394,7 @@ int ll_flag(struct linkedlist *_list_)
|
|||||||
}
|
}
|
||||||
struct linkedlist *ll_copy_of(struct linkedlist *_list_)
|
struct linkedlist *ll_copy_of(struct linkedlist *_list_)
|
||||||
{
|
{
|
||||||
struct linkedlist *result =
|
struct linkedlist *result = ll_new_custom(_list_->f_val, _list_->alloc, _list_->callbacks);
|
||||||
ll_new_custom(_list_->f_val, _list_->alloc, _list_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct linkedlist_node *scan = _list_->head;
|
struct linkedlist_node *scan = _list_->head;
|
||||||
@@ -448,8 +441,7 @@ _Bool ll_equals(struct linkedlist *_list1_, struct linkedlist *_list2_)
|
|||||||
}
|
}
|
||||||
struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t value)
|
struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t value)
|
||||||
{
|
{
|
||||||
struct linkedlist_node *_node_ =
|
struct linkedlist_node *_node_ = _list_->alloc->malloc(sizeof(struct linkedlist_node));
|
||||||
_list_->alloc->malloc(sizeof(struct linkedlist_node));
|
|
||||||
if (!_node_)
|
if (!_node_)
|
||||||
{
|
{
|
||||||
_list_->flag = CMC_FLAG_ALLOC;
|
_list_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -504,8 +496,7 @@ struct linkedlist_node *ll_tail(struct linkedlist *_list_)
|
|||||||
{
|
{
|
||||||
return _list_->tail;
|
return _list_->tail;
|
||||||
}
|
}
|
||||||
_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_,
|
_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
struct linkedlist_node *new_node = ll_new_node(_owner_, value);
|
struct linkedlist_node *new_node = ll_new_node(_owner_, value);
|
||||||
if (!new_node)
|
if (!new_node)
|
||||||
@@ -521,8 +512,7 @@ _Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_,
|
|||||||
_owner_->flag = CMC_FLAG_OK;
|
_owner_->flag = CMC_FLAG_OK;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_,
|
_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
struct linkedlist_node *new_node = ll_new_node(_owner_, value);
|
struct linkedlist_node *new_node = ll_new_node(_owner_, value);
|
||||||
if (!new_node)
|
if (!new_node)
|
||||||
|
|||||||
+17
-54
@@ -30,13 +30,11 @@ struct list_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct list *l_new(size_t capacity, struct list_fval *f_val);
|
struct list *l_new(size_t capacity, struct list_fval *f_val);
|
||||||
struct list *l_new_custom(size_t capacity, struct list_fval *f_val,
|
struct list *l_new_custom(size_t capacity, struct list_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void l_clear(struct list *_list_);
|
void l_clear(struct list *_list_);
|
||||||
void l_free(struct list *_list_);
|
void l_free(struct list *_list_);
|
||||||
void l_customize(struct list *_list_, struct cmc_alloc_node *alloc,
|
void l_customize(struct list *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool l_push_front(struct list *_list_, size_t value);
|
_Bool l_push_front(struct list *_list_, size_t value);
|
||||||
_Bool l_push_at(struct list *_list_, size_t value, size_t index);
|
_Bool l_push_at(struct list *_list_, size_t value, size_t index);
|
||||||
_Bool l_push_back(struct list *_list_, size_t value);
|
_Bool l_push_back(struct list *_list_, size_t value);
|
||||||
@@ -44,8 +42,7 @@ _Bool l_pop_front(struct list *_list_);
|
|||||||
_Bool l_pop_at(struct list *_list_, size_t index);
|
_Bool l_pop_at(struct list *_list_, size_t index);
|
||||||
_Bool l_pop_back(struct list *_list_);
|
_Bool l_pop_back(struct list *_list_);
|
||||||
_Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size);
|
_Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size);
|
||||||
_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size,
|
_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size, size_t index);
|
||||||
size_t index);
|
|
||||||
_Bool l_seq_push_back(struct list *_list_, size_t *values, size_t size);
|
_Bool l_seq_push_back(struct list *_list_, size_t *values, size_t size);
|
||||||
_Bool l_seq_pop_at(struct list *_list_, size_t from, size_t to);
|
_Bool l_seq_pop_at(struct list *_list_, size_t from, size_t to);
|
||||||
struct list *l_seq_sublist(struct list *_list_, size_t from, size_t to);
|
struct list *l_seq_sublist(struct list *_list_, size_t from, size_t to);
|
||||||
@@ -102,8 +99,7 @@ struct list *l_new(size_t capacity, struct list_fval *f_val)
|
|||||||
_list_->callbacks = ((void *)0);
|
_list_->callbacks = ((void *)0);
|
||||||
return _list_;
|
return _list_;
|
||||||
}
|
}
|
||||||
struct list *l_new_custom(size_t capacity, struct list_fval *f_val,
|
struct list *l_new_custom(size_t capacity, struct list_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
@@ -150,8 +146,7 @@ void l_free(struct list *_list_)
|
|||||||
_list_->alloc->free(_list_->buffer);
|
_list_->alloc->free(_list_->buffer);
|
||||||
_list_->alloc->free(_list_);
|
_list_->alloc->free(_list_);
|
||||||
}
|
}
|
||||||
void l_customize(struct list *_list_, struct cmc_alloc_node *alloc,
|
void l_customize(struct list *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_list_->alloc = &cmc_alloc_node_default;
|
_list_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -169,8 +164,7 @@ _Bool l_push_front(struct list *_list_, size_t value)
|
|||||||
}
|
}
|
||||||
if (!l_empty(_list_))
|
if (!l_empty(_list_))
|
||||||
{
|
{
|
||||||
memmove(_list_->buffer + 1, _list_->buffer,
|
memmove(_list_->buffer + 1, _list_->buffer, _list_->count * sizeof(size_t));
|
||||||
_list_->count * sizeof(size_t));
|
|
||||||
}
|
}
|
||||||
_list_->buffer[0] = value;
|
_list_->buffer[0] = value;
|
||||||
_list_->count++;
|
_list_->count++;
|
||||||
@@ -191,8 +185,7 @@ _Bool l_push_at(struct list *_list_, size_t value, size_t index)
|
|||||||
if (!l_resize(_list_, _list_->count * 2))
|
if (!l_resize(_list_, _list_->count * 2))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memmove(_list_->buffer + index + 1, _list_->buffer + index,
|
memmove(_list_->buffer + index + 1, _list_->buffer + index, (_list_->count - index) * sizeof(size_t));
|
||||||
(_list_->count - index) * sizeof(size_t));
|
|
||||||
_list_->buffer[index] = value;
|
_list_->buffer[index] = value;
|
||||||
_list_->count++;
|
_list_->count++;
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
@@ -220,8 +213,7 @@ _Bool l_pop_front(struct list *_list_)
|
|||||||
_list_->flag = CMC_FLAG_EMPTY;
|
_list_->flag = CMC_FLAG_EMPTY;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memmove(_list_->buffer, _list_->buffer + 1,
|
memmove(_list_->buffer, _list_->buffer + 1, (_list_->count - 1) * sizeof(size_t));
|
||||||
(_list_->count - 1) * sizeof(size_t));
|
|
||||||
_list_->buffer[--_list_->count] = (size_t){ 0 };
|
_list_->buffer[--_list_->count] = (size_t){ 0 };
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
if (_list_->callbacks && _list_->callbacks->delete)
|
if (_list_->callbacks && _list_->callbacks->delete)
|
||||||
@@ -240,8 +232,7 @@ _Bool l_pop_at(struct list *_list_, size_t index)
|
|||||||
_list_->flag = CMC_FLAG_RANGE;
|
_list_->flag = CMC_FLAG_RANGE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memmove(_list_->buffer + index, _list_->buffer + index + 1,
|
memmove(_list_->buffer + index, _list_->buffer + index + 1, (_list_->count - index - 1) * sizeof(size_t));
|
||||||
(_list_->count - index - 1) * sizeof(size_t));
|
|
||||||
_list_->buffer[--_list_->count] = (size_t){ 0 };
|
_list_->buffer[--_list_->count] = (size_t){ 0 };
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
if (_list_->callbacks && _list_->callbacks->delete)
|
if (_list_->callbacks && _list_->callbacks->delete)
|
||||||
@@ -270,8 +261,7 @@ _Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size)
|
|||||||
if (!l_resize(_list_, _list_->count + size))
|
if (!l_resize(_list_, _list_->count + size))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memmove(_list_->buffer + size, _list_->buffer,
|
memmove(_list_->buffer + size, _list_->buffer, _list_->count * sizeof(size_t));
|
||||||
_list_->count * sizeof(size_t));
|
|
||||||
memcpy(_list_->buffer, values, size * sizeof(size_t));
|
memcpy(_list_->buffer, values, size * sizeof(size_t));
|
||||||
_list_->count += size;
|
_list_->count += size;
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
@@ -279,8 +269,7 @@ _Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size)
|
|||||||
_list_->callbacks->create();
|
_list_->callbacks->create();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size,
|
_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size, size_t index)
|
||||||
size_t index)
|
|
||||||
{
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
@@ -301,8 +290,7 @@ _Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size,
|
|||||||
if (!l_resize(_list_, _list_->count + size))
|
if (!l_resize(_list_, _list_->count + size))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memmove(_list_->buffer + index + size, _list_->buffer + index,
|
memmove(_list_->buffer + index + size, _list_->buffer + index, (_list_->count - index) * sizeof(size_t));
|
||||||
(_list_->count - index) * sizeof(size_t));
|
|
||||||
memcpy(_list_->buffer + index, values, size * sizeof(size_t));
|
memcpy(_list_->buffer + index, values, size * sizeof(size_t));
|
||||||
_list_->count += size;
|
_list_->count += size;
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
@@ -342,8 +330,7 @@ _Bool l_seq_pop_at(struct list *_list_, size_t from, size_t to)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t length = (to - from + 1);
|
size_t length = (to - from + 1);
|
||||||
memmove(_list_->buffer + from, _list_->buffer + to + 1,
|
memmove(_list_->buffer + from, _list_->buffer + to + 1, (_list_->count - to - 1) * sizeof(size_t));
|
||||||
(_list_->count - to - 1) * sizeof(size_t));
|
|
||||||
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(size_t));
|
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(size_t));
|
||||||
_list_->count -= to - from + 1;
|
_list_->count -= to - from + 1;
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
@@ -364,16 +351,14 @@ struct list *l_seq_sublist(struct list *_list_, size_t from, size_t to)
|
|||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
size_t length = to - from + 1;
|
size_t length = to - from + 1;
|
||||||
struct list *result =
|
struct list *result = l_new_custom(length, _list_->f_val, _list_->alloc, _list_->callbacks);
|
||||||
l_new_custom(length, _list_->f_val, _list_->alloc, _list_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_list_->flag = CMC_FLAG_ALLOC;
|
_list_->flag = CMC_FLAG_ALLOC;
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
memcpy(result->buffer, _list_->buffer, length * sizeof(size_t));
|
memcpy(result->buffer, _list_->buffer, length * sizeof(size_t));
|
||||||
memmove(_list_->buffer + from, _list_->buffer + to + 1,
|
memmove(_list_->buffer + from, _list_->buffer + to + 1, (_list_->count - to - 1) * sizeof(size_t));
|
||||||
(_list_->count - to - 1) * sizeof(size_t));
|
|
||||||
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(size_t));
|
memset(_list_->buffer + _list_->count - length, 0, length * sizeof(size_t));
|
||||||
_list_->count -= length;
|
_list_->count -= length;
|
||||||
result->count = length;
|
result->count = length;
|
||||||
@@ -520,8 +505,7 @@ _Bool l_resize(struct list *_list_, size_t capacity)
|
|||||||
_list_->flag = CMC_FLAG_INVALID;
|
_list_->flag = CMC_FLAG_INVALID;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t *new_buffer =
|
size_t *new_buffer = _list_->alloc->realloc(_list_->buffer, sizeof(size_t) * capacity);
|
||||||
_list_->alloc->realloc(_list_->buffer, sizeof(size_t) * capacity);
|
|
||||||
if (!new_buffer)
|
if (!new_buffer)
|
||||||
{
|
{
|
||||||
_list_->flag = CMC_FLAG_ALLOC;
|
_list_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -535,8 +519,7 @@ _Bool l_resize(struct list *_list_, size_t capacity)
|
|||||||
}
|
}
|
||||||
struct list *l_copy_of(struct list *_list_)
|
struct list *l_copy_of(struct list *_list_)
|
||||||
{
|
{
|
||||||
struct list *result = l_new_custom(_list_->capacity, _list_->f_val,
|
struct list *result = l_new_custom(_list_->capacity, _list_->f_val, _list_->alloc, _list_->callbacks);
|
||||||
_list_->alloc, _list_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_list_->flag = CMC_FLAG_ALLOC;
|
_list_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -566,26 +549,6 @@ _Bool l_equals(struct list *_list1_, struct list *_list2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string l_to_string(struct list *_list_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct list *l_ = _list_;
|
|
||||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_list,
|
|
||||||
"CMC_PARAM_SNAME((l, list, , , size_t))",
|
|
||||||
"CMC_PARAM_V((l, list, , , size_t))", l_, l_->buffer,
|
|
||||||
l_->capacity, l_->count, l_->flag, l_->f_val, l_->alloc,
|
|
||||||
l_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool l_print(struct list *_list_, FILE *fptr)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < _list_->count; i++)
|
|
||||||
{
|
|
||||||
if (!_list_->f_val->str(fptr, _list_->buffer[i]))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct list_iter l_iter_start(struct list *target)
|
struct list_iter l_iter_start(struct list *target)
|
||||||
{
|
{
|
||||||
struct list_iter iter;
|
struct list_iter iter;
|
||||||
|
|||||||
+9
-39
@@ -33,13 +33,11 @@ struct queue_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct queue *q_new(size_t capacity, struct queue_fval *f_val);
|
struct queue *q_new(size_t capacity, struct queue_fval *f_val);
|
||||||
struct queue *q_new_custom(size_t capacity, struct queue_fval *f_val,
|
struct queue *q_new_custom(size_t capacity, struct queue_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void q_clear(struct queue *_queue_);
|
void q_clear(struct queue *_queue_);
|
||||||
void q_free(struct queue *_queue_);
|
void q_free(struct queue *_queue_);
|
||||||
void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc,
|
void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool q_enqueue(struct queue *_queue_, size_t value);
|
_Bool q_enqueue(struct queue *_queue_, size_t value);
|
||||||
_Bool q_dequeue(struct queue *_queue_);
|
_Bool q_dequeue(struct queue *_queue_);
|
||||||
size_t q_peek(struct queue *_queue_);
|
size_t q_peek(struct queue *_queue_);
|
||||||
@@ -94,8 +92,7 @@ struct queue *q_new(size_t capacity, struct queue_fval *f_val)
|
|||||||
_queue_->callbacks = ((void *)0);
|
_queue_->callbacks = ((void *)0);
|
||||||
return _queue_;
|
return _queue_;
|
||||||
}
|
}
|
||||||
struct queue *q_new_custom(size_t capacity, struct queue_fval *f_val,
|
struct queue *q_new_custom(size_t capacity, struct queue_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
@@ -152,8 +149,7 @@ void q_free(struct queue *_queue_)
|
|||||||
_queue_->alloc->free(_queue_->buffer);
|
_queue_->alloc->free(_queue_->buffer);
|
||||||
_queue_->alloc->free(_queue_);
|
_queue_->alloc->free(_queue_);
|
||||||
}
|
}
|
||||||
void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc,
|
void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_queue_->alloc = &cmc_alloc_node_default;
|
_queue_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -170,8 +166,7 @@ _Bool q_enqueue(struct queue *_queue_, size_t value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_queue_->buffer[_queue_->back] = value;
|
_queue_->buffer[_queue_->back] = value;
|
||||||
_queue_->back =
|
_queue_->back = (_queue_->back == _queue_->capacity - 1) ? 0 : _queue_->back + 1;
|
||||||
(_queue_->back == _queue_->capacity - 1) ? 0 : _queue_->back + 1;
|
|
||||||
_queue_->count++;
|
_queue_->count++;
|
||||||
_queue_->flag = CMC_FLAG_OK;
|
_queue_->flag = CMC_FLAG_OK;
|
||||||
if (_queue_->callbacks && _queue_->callbacks->create)
|
if (_queue_->callbacks && _queue_->callbacks->create)
|
||||||
@@ -186,8 +181,7 @@ _Bool q_dequeue(struct queue *_queue_)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_queue_->buffer[_queue_->front] = (size_t){ 0 };
|
_queue_->buffer[_queue_->front] = (size_t){ 0 };
|
||||||
_queue_->front =
|
_queue_->front = (_queue_->front == _queue_->capacity - 1) ? 0 : _queue_->front + 1;
|
||||||
(_queue_->front == _queue_->capacity - 1) ? 0 : _queue_->front + 1;
|
|
||||||
_queue_->count--;
|
_queue_->count--;
|
||||||
_queue_->flag = CMC_FLAG_OK;
|
_queue_->flag = CMC_FLAG_OK;
|
||||||
if (_queue_->callbacks && _queue_->callbacks->delete)
|
if (_queue_->callbacks && _queue_->callbacks->delete)
|
||||||
@@ -276,8 +270,7 @@ success:
|
|||||||
}
|
}
|
||||||
struct queue *q_copy_of(struct queue *_queue_)
|
struct queue *q_copy_of(struct queue *_queue_)
|
||||||
{
|
{
|
||||||
struct queue *result = q_new_custom(_queue_->capacity, _queue_->f_val,
|
struct queue *result = q_new_custom(_queue_->capacity, _queue_->f_val, _queue_->alloc, _queue_->callbacks);
|
||||||
_queue_->alloc, _queue_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_queue_->flag = CMC_FLAG_ERROR;
|
_queue_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -312,8 +305,7 @@ _Bool q_equals(struct queue *_queue1_, struct queue *_queue2_)
|
|||||||
if (_queue1_->count != _queue2_->count)
|
if (_queue1_->count != _queue2_->count)
|
||||||
return 0;
|
return 0;
|
||||||
size_t i, j, k;
|
size_t i, j, k;
|
||||||
for (i = _queue1_->front, j = _queue2_->front, k = 0; k < _queue1_->count;
|
for (i = _queue1_->front, j = _queue2_->front, k = 0; k < _queue1_->count; k++)
|
||||||
k++)
|
|
||||||
{
|
{
|
||||||
if (_queue1_->f_val->cmp(_queue1_->buffer[i], _queue2_->buffer[j]) != 0)
|
if (_queue1_->f_val->cmp(_queue1_->buffer[i], _queue2_->buffer[j]) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -322,27 +314,6 @@ _Bool q_equals(struct queue *_queue1_, struct queue *_queue2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string q_to_string(struct queue *_queue_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct queue *q_ = _queue_;
|
|
||||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_queue,
|
|
||||||
"CMC_PARAM_SNAME((q, queue, , , size_t))",
|
|
||||||
"CMC_PARAM_V((q, queue, , , size_t))", q_, q_->buffer,
|
|
||||||
q_->capacity, q_->count, q_->front, q_->back, q_->flag,
|
|
||||||
q_->f_val, q_->alloc, q_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool q_print(struct queue *_queue_, FILE *fptr)
|
|
||||||
{
|
|
||||||
for (size_t i = _queue_->front, j = 0; j < _queue_->count; j++)
|
|
||||||
{
|
|
||||||
if (!_queue_->f_val->str(fptr, _queue_->buffer[i]))
|
|
||||||
return 0;
|
|
||||||
i = (i + 1) % _queue_->capacity;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct queue_iter q_iter_start(struct queue *target)
|
struct queue_iter q_iter_start(struct queue *target)
|
||||||
{
|
{
|
||||||
struct queue_iter iter;
|
struct queue_iter iter;
|
||||||
@@ -433,8 +404,7 @@ _Bool q_iter_prev(struct queue_iter *iter)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
iter->end = q_empty(iter->target);
|
iter->end = q_empty(iter->target);
|
||||||
iter->cursor =
|
iter->cursor = (iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1;
|
||||||
(iter->cursor == 0) ? iter->target->capacity - 1 : iter->cursor - 1;
|
|
||||||
iter->index--;
|
iter->index--;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-54
@@ -31,13 +31,11 @@ struct sortedlist_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val);
|
struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val);
|
||||||
struct sortedlist *sl_new_custom(size_t capacity, struct sortedlist_fval *f_val,
|
struct sortedlist *sl_new_custom(size_t capacity, struct sortedlist_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void sl_clear(struct sortedlist *_list_);
|
void sl_clear(struct sortedlist *_list_);
|
||||||
void sl_free(struct sortedlist *_list_);
|
void sl_free(struct sortedlist *_list_);
|
||||||
void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc,
|
void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool sl_insert(struct sortedlist *_list_, size_t value);
|
_Bool sl_insert(struct sortedlist *_list_, size_t value);
|
||||||
_Bool sl_remove(struct sortedlist *_list_, size_t index);
|
_Bool sl_remove(struct sortedlist *_list_, size_t index);
|
||||||
size_t sl_max(struct sortedlist *_list_);
|
size_t sl_max(struct sortedlist *_list_);
|
||||||
@@ -69,14 +67,10 @@ _Bool sl_iter_rewind(struct sortedlist_iter *iter, size_t steps);
|
|||||||
_Bool sl_iter_go_to(struct sortedlist_iter *iter, size_t index);
|
_Bool sl_iter_go_to(struct sortedlist_iter *iter, size_t index);
|
||||||
size_t sl_iter_value(struct sortedlist_iter *iter);
|
size_t sl_iter_value(struct sortedlist_iter *iter);
|
||||||
size_t sl_iter_index(struct sortedlist_iter *iter);
|
size_t sl_iter_index(struct sortedlist_iter *iter);
|
||||||
static size_t sl_impl_binary_search_first(struct sortedlist *_list_,
|
static size_t sl_impl_binary_search_first(struct sortedlist *_list_, size_t value);
|
||||||
size_t value);
|
static size_t sl_impl_binary_search_last(struct sortedlist *_list_, size_t value);
|
||||||
static size_t sl_impl_binary_search_last(struct sortedlist *_list_,
|
void sl_impl_sort_quicksort(size_t *array, int (*cmp)(size_t, size_t), size_t low, size_t high);
|
||||||
size_t value);
|
void sl_impl_sort_insertion(size_t *array, int (*cmp)(size_t, size_t), size_t low, size_t high);
|
||||||
void sl_impl_sort_quicksort(size_t *array, int (*cmp)(size_t, size_t),
|
|
||||||
size_t low, size_t high);
|
|
||||||
void sl_impl_sort_insertion(size_t *array, int (*cmp)(size_t, size_t),
|
|
||||||
size_t low, size_t high);
|
|
||||||
struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val)
|
struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val)
|
||||||
{
|
{
|
||||||
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
struct cmc_alloc_node *alloc = &cmc_alloc_node_default;
|
||||||
@@ -102,8 +96,7 @@ struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val)
|
|||||||
_list_->callbacks = ((void *)0);
|
_list_->callbacks = ((void *)0);
|
||||||
return _list_;
|
return _list_;
|
||||||
}
|
}
|
||||||
struct sortedlist *sl_new_custom(size_t capacity, struct sortedlist_fval *f_val,
|
struct sortedlist *sl_new_custom(size_t capacity, struct sortedlist_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
@@ -149,8 +142,7 @@ void sl_free(struct sortedlist *_list_)
|
|||||||
_list_->alloc->free(_list_->buffer);
|
_list_->alloc->free(_list_->buffer);
|
||||||
_list_->alloc->free(_list_);
|
_list_->alloc->free(_list_);
|
||||||
}
|
}
|
||||||
void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc,
|
void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_list_->alloc = &cmc_alloc_node_default;
|
_list_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -185,8 +177,7 @@ _Bool sl_remove(struct sortedlist *_list_, size_t index)
|
|||||||
_list_->flag = CMC_FLAG_RANGE;
|
_list_->flag = CMC_FLAG_RANGE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memmove(_list_->buffer + index, _list_->buffer + index + 1,
|
memmove(_list_->buffer + index, _list_->buffer + index + 1, (_list_->count - index) * sizeof(size_t));
|
||||||
(_list_->count - index) * sizeof(size_t));
|
|
||||||
_list_->buffer[--_list_->count] = (size_t){ 0 };
|
_list_->buffer[--_list_->count] = (size_t){ 0 };
|
||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
if (_list_->callbacks && _list_->callbacks->delete)
|
if (_list_->callbacks && _list_->callbacks->delete)
|
||||||
@@ -288,8 +279,7 @@ _Bool sl_resize(struct sortedlist *_list_, size_t capacity)
|
|||||||
_list_->flag = CMC_FLAG_INVALID;
|
_list_->flag = CMC_FLAG_INVALID;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t *new_buffer =
|
size_t *new_buffer = _list_->alloc->realloc(_list_->buffer, sizeof(size_t) * capacity);
|
||||||
_list_->alloc->realloc(_list_->buffer, sizeof(size_t) * capacity);
|
|
||||||
if (!new_buffer)
|
if (!new_buffer)
|
||||||
{
|
{
|
||||||
_list_->flag = CMC_FLAG_ALLOC;
|
_list_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -308,15 +298,13 @@ void sl_sort(struct sortedlist *_list_)
|
|||||||
_list_->flag = CMC_FLAG_OK;
|
_list_->flag = CMC_FLAG_OK;
|
||||||
if (!_list_->is_sorted && _list_->count > 1)
|
if (!_list_->is_sorted && _list_->count > 1)
|
||||||
{
|
{
|
||||||
sl_impl_sort_quicksort(_list_->buffer, _list_->f_val->cmp, 0,
|
sl_impl_sort_quicksort(_list_->buffer, _list_->f_val->cmp, 0, _list_->count - 1);
|
||||||
_list_->count - 1);
|
|
||||||
_list_->is_sorted = 1;
|
_list_->is_sorted = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct sortedlist *sl_copy_of(struct sortedlist *_list_)
|
struct sortedlist *sl_copy_of(struct sortedlist *_list_)
|
||||||
{
|
{
|
||||||
struct sortedlist *result = sl_new_custom(_list_->capacity, _list_->f_val,
|
struct sortedlist *result = sl_new_custom(_list_->capacity, _list_->f_val, _list_->alloc, _list_->callbacks);
|
||||||
_list_->alloc, _list_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_list_->flag = CMC_FLAG_ERROR;
|
_list_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -346,28 +334,6 @@ _Bool sl_equals(struct sortedlist *_list1_, struct sortedlist *_list2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string sl_to_string(struct sortedlist *_list_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct sortedlist *l_ = _list_;
|
|
||||||
int n =
|
|
||||||
snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_sortedlist,
|
|
||||||
"CMC_PARAM_SNAME((sl, sortedlist, , , size_t))",
|
|
||||||
"CMC_PARAM_V((sl, sortedlist, , , size_t))", l_, l_->buffer,
|
|
||||||
l_->capacity, l_->count, l_->is_sorted ? "true" : "false",
|
|
||||||
l_->flag, l_->f_val, l_->alloc, l_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool sl_print(struct sortedlist *_list_, FILE *fptr)
|
|
||||||
{
|
|
||||||
sl_sort(_list_);
|
|
||||||
for (size_t i = 0; i < _list_->count; i++)
|
|
||||||
{
|
|
||||||
if (!_list_->f_val->str(fptr, _list_->buffer[i]))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct sortedlist_iter sl_iter_start(struct sortedlist *target)
|
struct sortedlist_iter sl_iter_start(struct sortedlist *target)
|
||||||
{
|
{
|
||||||
sl_sort(target);
|
sl_sort(target);
|
||||||
@@ -496,8 +462,7 @@ size_t sl_iter_index(struct sortedlist_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->cursor;
|
return iter->cursor;
|
||||||
}
|
}
|
||||||
static size_t sl_impl_binary_search_first(struct sortedlist *_list_,
|
static size_t sl_impl_binary_search_first(struct sortedlist *_list_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
if (sl_empty(_list_))
|
if (sl_empty(_list_))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -515,8 +480,7 @@ static size_t sl_impl_binary_search_first(struct sortedlist *_list_,
|
|||||||
return L;
|
return L;
|
||||||
return _list_->count;
|
return _list_->count;
|
||||||
}
|
}
|
||||||
static size_t sl_impl_binary_search_last(struct sortedlist *_list_,
|
static size_t sl_impl_binary_search_last(struct sortedlist *_list_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
if (sl_empty(_list_))
|
if (sl_empty(_list_))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -534,8 +498,7 @@ static size_t sl_impl_binary_search_last(struct sortedlist *_list_,
|
|||||||
return L - 1;
|
return L - 1;
|
||||||
return _list_->count;
|
return _list_->count;
|
||||||
}
|
}
|
||||||
void sl_impl_sort_quicksort(size_t *array, int (*cmp)(size_t, size_t),
|
void sl_impl_sort_quicksort(size_t *array, int (*cmp)(size_t, size_t), size_t low, size_t high)
|
||||||
size_t low, size_t high)
|
|
||||||
{
|
{
|
||||||
while (low < high)
|
while (low < high)
|
||||||
{
|
{
|
||||||
@@ -574,8 +537,7 @@ void sl_impl_sort_quicksort(size_t *array, int (*cmp)(size_t, size_t),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void sl_impl_sort_insertion(size_t *array, int (*cmp)(size_t, size_t),
|
void sl_impl_sort_insertion(size_t *array, int (*cmp)(size_t, size_t), size_t low, size_t high)
|
||||||
size_t low, size_t high)
|
|
||||||
{
|
{
|
||||||
for (size_t i = low + 1; i <= high; i++)
|
for (size_t i = low + 1; i <= high; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
+7
-34
@@ -30,13 +30,11 @@ struct stack_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct stack *s_new(size_t capacity, struct stack_fval *f_val);
|
struct stack *s_new(size_t capacity, struct stack_fval *f_val);
|
||||||
struct stack *s_new_custom(size_t capacity, struct stack_fval *f_val,
|
struct stack *s_new_custom(size_t capacity, struct stack_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void s_clear(struct stack *_stack_);
|
void s_clear(struct stack *_stack_);
|
||||||
void s_free(struct stack *_stack_);
|
void s_free(struct stack *_stack_);
|
||||||
void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc,
|
void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool s_push(struct stack *_stack_, size_t value);
|
_Bool s_push(struct stack *_stack_, size_t value);
|
||||||
_Bool s_pop(struct stack *_stack_);
|
_Bool s_pop(struct stack *_stack_);
|
||||||
size_t s_top(struct stack *_stack_);
|
size_t s_top(struct stack *_stack_);
|
||||||
@@ -89,8 +87,7 @@ struct stack *s_new(size_t capacity, struct stack_fval *f_val)
|
|||||||
_stack_->callbacks = ((void *)0);
|
_stack_->callbacks = ((void *)0);
|
||||||
return _stack_;
|
return _stack_;
|
||||||
}
|
}
|
||||||
struct stack *s_new_custom(size_t capacity, struct stack_fval *f_val,
|
struct stack *s_new_custom(size_t capacity, struct stack_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (capacity < 1)
|
if (capacity < 1)
|
||||||
@@ -137,8 +134,7 @@ void s_free(struct stack *_stack_)
|
|||||||
_stack_->alloc->free(_stack_->buffer);
|
_stack_->alloc->free(_stack_->buffer);
|
||||||
_stack_->alloc->free(_stack_);
|
_stack_->alloc->free(_stack_);
|
||||||
}
|
}
|
||||||
void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc,
|
void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_stack_->alloc = &cmc_alloc_node_default;
|
_stack_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -230,8 +226,7 @@ _Bool s_resize(struct stack *_stack_, size_t capacity)
|
|||||||
_stack_->flag = CMC_FLAG_INVALID;
|
_stack_->flag = CMC_FLAG_INVALID;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t *new_buffer =
|
size_t *new_buffer = _stack_->alloc->realloc(_stack_->buffer, sizeof(size_t) * capacity);
|
||||||
_stack_->alloc->realloc(_stack_->buffer, sizeof(size_t) * capacity);
|
|
||||||
if (!new_buffer)
|
if (!new_buffer)
|
||||||
{
|
{
|
||||||
_stack_->flag = CMC_FLAG_ALLOC;
|
_stack_->flag = CMC_FLAG_ALLOC;
|
||||||
@@ -247,8 +242,7 @@ success:
|
|||||||
}
|
}
|
||||||
struct stack *s_copy_of(struct stack *_stack_)
|
struct stack *s_copy_of(struct stack *_stack_)
|
||||||
{
|
{
|
||||||
struct stack *result = s_new_custom(_stack_->capacity, _stack_->f_val,
|
struct stack *result = s_new_custom(_stack_->capacity, _stack_->f_val, _stack_->alloc, _stack_->callbacks);
|
||||||
_stack_->alloc, _stack_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_stack_->flag = CMC_FLAG_ERROR;
|
_stack_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -260,8 +254,7 @@ struct stack *s_copy_of(struct stack *_stack_)
|
|||||||
result->buffer[i] = _stack_->f_val->cpy(_stack_->buffer[i]);
|
result->buffer[i] = _stack_->f_val->cpy(_stack_->buffer[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(result->buffer, _stack_->buffer,
|
memcpy(result->buffer, _stack_->buffer, sizeof(size_t) * _stack_->count);
|
||||||
sizeof(size_t) * _stack_->count);
|
|
||||||
result->count = _stack_->count;
|
result->count = _stack_->count;
|
||||||
_stack_->flag = CMC_FLAG_OK;
|
_stack_->flag = CMC_FLAG_OK;
|
||||||
return result;
|
return result;
|
||||||
@@ -279,26 +272,6 @@ _Bool s_equals(struct stack *_stack1_, struct stack *_stack2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string s_to_string(struct stack *_stack_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct stack *s_ = _stack_;
|
|
||||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_stack,
|
|
||||||
"CMC_PARAM_SNAME((s, stack, , , size_t))",
|
|
||||||
"CMC_PARAM_V((s, stack, , , size_t))", s_, s_->buffer,
|
|
||||||
s_->capacity, s_->count, s_->flag, s_->f_val, s_->alloc,
|
|
||||||
s_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool s_print(struct stack *_stack_, FILE *fptr)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < _stack_->count; i++)
|
|
||||||
{
|
|
||||||
if (!_stack_->f_val->str(fptr, _stack_->buffer[i]))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct stack_iter s_iter_start(struct stack *target)
|
struct stack_iter s_iter_start(struct stack *target)
|
||||||
{
|
{
|
||||||
struct stack_iter iter;
|
struct stack_iter iter;
|
||||||
|
|||||||
+11
-69
@@ -51,17 +51,13 @@ struct treemap_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct treemap *tm_new(struct treemap_fkey *f_key, struct treemap_fval *f_val);
|
struct treemap *tm_new(struct treemap_fkey *f_key, struct treemap_fval *f_val);
|
||||||
struct treemap *tm_new_custom(struct treemap_fkey *f_key,
|
struct treemap *tm_new_custom(struct treemap_fkey *f_key, struct treemap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct treemap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void tm_clear(struct treemap *_map_);
|
void tm_clear(struct treemap *_map_);
|
||||||
void tm_free(struct treemap *_map_);
|
void tm_free(struct treemap *_map_);
|
||||||
void tm_customize(struct treemap *_map_, struct cmc_alloc_node *alloc,
|
void tm_customize(struct treemap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool tm_insert(struct treemap *_map_, size_t key, size_t value);
|
_Bool tm_insert(struct treemap *_map_, size_t key, size_t value);
|
||||||
_Bool tm_update(struct treemap *_map_, size_t key, size_t new_value,
|
_Bool tm_update(struct treemap *_map_, size_t key, size_t new_value, size_t *old_value);
|
||||||
size_t *old_value);
|
|
||||||
_Bool tm_remove(struct treemap *_map_, size_t key, size_t *out_value);
|
_Bool tm_remove(struct treemap *_map_, size_t key, size_t *out_value);
|
||||||
_Bool tm_max(struct treemap *_map_, size_t *key, size_t *value);
|
_Bool tm_max(struct treemap *_map_, size_t *key, size_t *value);
|
||||||
_Bool tm_min(struct treemap *_map_, size_t *key, size_t *value);
|
_Bool tm_min(struct treemap *_map_, size_t *key, size_t *value);
|
||||||
@@ -90,8 +86,7 @@ size_t tm_iter_key(struct treemap_iter *iter);
|
|||||||
size_t tm_iter_value(struct treemap_iter *iter);
|
size_t tm_iter_value(struct treemap_iter *iter);
|
||||||
size_t *tm_iter_rvalue(struct treemap_iter *iter);
|
size_t *tm_iter_rvalue(struct treemap_iter *iter);
|
||||||
size_t tm_iter_index(struct treemap_iter *iter);
|
size_t tm_iter_index(struct treemap_iter *iter);
|
||||||
static struct treemap_node *tm_impl_new_node(struct treemap *_map_, size_t key,
|
static struct treemap_node *tm_impl_new_node(struct treemap *_map_, size_t key, size_t value);
|
||||||
size_t value);
|
|
||||||
static struct treemap_node *tm_impl_get_node(struct treemap *_map_, size_t key);
|
static struct treemap_node *tm_impl_get_node(struct treemap *_map_, size_t key);
|
||||||
static unsigned char tm_impl_h(struct treemap_node *node);
|
static unsigned char tm_impl_h(struct treemap_node *node);
|
||||||
static unsigned char tm_impl_hupdate(struct treemap_node *node);
|
static unsigned char tm_impl_hupdate(struct treemap_node *node);
|
||||||
@@ -115,9 +110,7 @@ struct treemap *tm_new(struct treemap_fkey *f_key, struct treemap_fval *f_val)
|
|||||||
_map_->callbacks = ((void *)0);
|
_map_->callbacks = ((void *)0);
|
||||||
return _map_;
|
return _map_;
|
||||||
}
|
}
|
||||||
struct treemap *tm_new_custom(struct treemap_fkey *f_key,
|
struct treemap *tm_new_custom(struct treemap_fkey *f_key, struct treemap_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct treemap_fval *f_val,
|
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
struct cmc_callbacks *callbacks)
|
||||||
{
|
{
|
||||||
if (!f_key || !f_val)
|
if (!f_key || !f_val)
|
||||||
@@ -198,8 +191,7 @@ void tm_free(struct treemap *_map_)
|
|||||||
tm_clear(_map_);
|
tm_clear(_map_);
|
||||||
_map_->alloc->free(_map_);
|
_map_->alloc->free(_map_);
|
||||||
}
|
}
|
||||||
void tm_customize(struct treemap *_map_, struct cmc_alloc_node *alloc,
|
void tm_customize(struct treemap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_map_->alloc = &cmc_alloc_node_default;
|
_map_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -267,8 +259,7 @@ _Bool tm_insert(struct treemap *_map_, size_t key, size_t value)
|
|||||||
_map_->callbacks->create();
|
_map_->callbacks->create();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
_Bool tm_update(struct treemap *_map_, size_t key, size_t new_value,
|
_Bool tm_update(struct treemap *_map_, size_t key, size_t new_value, size_t *old_value)
|
||||||
size_t *old_value)
|
|
||||||
{
|
{
|
||||||
struct treemap_node *node = tm_impl_get_node(_map_, key);
|
struct treemap_node *node = tm_impl_get_node(_map_, key);
|
||||||
if (!node)
|
if (!node)
|
||||||
@@ -491,8 +482,7 @@ int tm_flag(struct treemap *_map_)
|
|||||||
}
|
}
|
||||||
struct treemap *tm_copy_of(struct treemap *_map_)
|
struct treemap *tm_copy_of(struct treemap *_map_)
|
||||||
{
|
{
|
||||||
struct treemap *result =
|
struct treemap *result = tm_new_custom(_map_->f_key, _map_->f_val, _map_->alloc, ((void *)0));
|
||||||
tm_new_custom(_map_->f_key, _map_->f_val, _map_->alloc, ((void *)0));
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_map_->flag = CMC_FLAG_ERROR;
|
_map_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -522,8 +512,7 @@ _Bool tm_equals(struct treemap *_map1_, struct treemap *_map2_)
|
|||||||
struct treemap_iter iter = tm_iter_start(_map1_);
|
struct treemap_iter iter = tm_iter_start(_map1_);
|
||||||
for (; !tm_iter_at_end(&iter); tm_iter_next(&iter))
|
for (; !tm_iter_at_end(&iter); tm_iter_next(&iter))
|
||||||
{
|
{
|
||||||
struct treemap_node *node =
|
struct treemap_node *node = tm_impl_get_node(_map2_, tm_iter_key(&iter));
|
||||||
tm_impl_get_node(_map2_, tm_iter_key(&iter));
|
|
||||||
if (node == ((void *)0))
|
if (node == ((void *)0))
|
||||||
return 0;
|
return 0;
|
||||||
if (_map1_->f_val->cmp(node->value, tm_iter_value(&iter)) != 0)
|
if (_map1_->f_val->cmp(node->value, tm_iter_value(&iter)) != 0)
|
||||||
@@ -531,51 +520,6 @@ _Bool tm_equals(struct treemap *_map1_, struct treemap *_map2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string tm_to_string(struct treemap *_map_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct treemap *m_ = _map_;
|
|
||||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_treemap,
|
|
||||||
"CMC_PARAM_SNAME((tm, treemap, , size_t, size_t))",
|
|
||||||
"CMC_PARAM_K((tm, treemap, , size_t, size_t))",
|
|
||||||
"CMC_PARAM_V((tm, treemap, , size_t, size_t))", m_,
|
|
||||||
m_->root, m_->count, m_->flag, m_->f_key, m_->f_val,
|
|
||||||
m_->alloc, m_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool tm_print(struct treemap *_map_, FILE *fptr)
|
|
||||||
{
|
|
||||||
struct treemap_node *root = _map_->root;
|
|
||||||
_Bool left_done = 0;
|
|
||||||
while (root)
|
|
||||||
{
|
|
||||||
if (!left_done)
|
|
||||||
{
|
|
||||||
while (root->left)
|
|
||||||
root = root->left;
|
|
||||||
}
|
|
||||||
if (!_map_->f_key->str(fptr, root->key) &&
|
|
||||||
!_map_->f_val->str(fptr, root->value))
|
|
||||||
return 0;
|
|
||||||
left_done = 1;
|
|
||||||
if (root->right)
|
|
||||||
{
|
|
||||||
left_done = 0;
|
|
||||||
root = root->right;
|
|
||||||
}
|
|
||||||
else if (root->parent)
|
|
||||||
{
|
|
||||||
while (root->parent && root == root->parent->right)
|
|
||||||
root = root->parent;
|
|
||||||
if (!root->parent)
|
|
||||||
break;
|
|
||||||
root = root->parent;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct treemap_iter tm_iter_start(struct treemap *target)
|
struct treemap_iter tm_iter_start(struct treemap *target)
|
||||||
{
|
{
|
||||||
struct treemap_iter iter;
|
struct treemap_iter iter;
|
||||||
@@ -771,11 +715,9 @@ size_t tm_iter_index(struct treemap_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->index;
|
return iter->index;
|
||||||
}
|
}
|
||||||
static struct treemap_node *tm_impl_new_node(struct treemap *_map_, size_t key,
|
static struct treemap_node *tm_impl_new_node(struct treemap *_map_, size_t key, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
struct treemap_node *node =
|
struct treemap_node *node = _map_->alloc->malloc(sizeof(struct treemap_node));
|
||||||
_map_->alloc->malloc(sizeof(struct treemap_node));
|
|
||||||
if (!node)
|
if (!node)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
node->key = key;
|
node->key = key;
|
||||||
|
|||||||
+16
-75
@@ -40,13 +40,11 @@ struct treeset_iter
|
|||||||
_Bool end;
|
_Bool end;
|
||||||
};
|
};
|
||||||
struct treeset *ts_new(struct treeset_fval *f_val);
|
struct treeset *ts_new(struct treeset_fval *f_val);
|
||||||
struct treeset *ts_new_custom(struct treeset_fval *f_val,
|
struct treeset *ts_new_custom(struct treeset_fval *f_val, struct cmc_alloc_node *alloc,
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks);
|
struct cmc_callbacks *callbacks);
|
||||||
void ts_clear(struct treeset *_set_);
|
void ts_clear(struct treeset *_set_);
|
||||||
void ts_free(struct treeset *_set_);
|
void ts_free(struct treeset *_set_);
|
||||||
void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc,
|
void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks);
|
||||||
struct cmc_callbacks *callbacks);
|
|
||||||
_Bool ts_insert(struct treeset *_set_, size_t value);
|
_Bool ts_insert(struct treeset *_set_, size_t value);
|
||||||
_Bool ts_remove(struct treeset *_set_, size_t value);
|
_Bool ts_remove(struct treeset *_set_, size_t value);
|
||||||
_Bool ts_max(struct treeset *_set_, size_t *value);
|
_Bool ts_max(struct treeset *_set_, size_t *value);
|
||||||
@@ -62,8 +60,7 @@ _Bool ts_print(struct treeset *_set_, FILE *fptr);
|
|||||||
struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_);
|
struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_);
|
struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_);
|
struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
struct treeset *ts_symmetric_difference(struct treeset *_set1_,
|
struct treeset *ts_symmetric_difference(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
struct treeset *_set2_);
|
|
||||||
_Bool ts_is_subset(struct treeset *_set1_, struct treeset *_set2_);
|
_Bool ts_is_subset(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
_Bool ts_is_superset(struct treeset *_set1_, struct treeset *_set2_);
|
_Bool ts_is_superset(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
_Bool ts_is_proper_subset(struct treeset *_set1_, struct treeset *_set2_);
|
_Bool ts_is_proper_subset(struct treeset *_set1_, struct treeset *_set2_);
|
||||||
@@ -88,10 +85,8 @@ static inline size_t ts_impl_default_value(void)
|
|||||||
memset(&_empty_value_, 0, sizeof(size_t));
|
memset(&_empty_value_, 0, sizeof(size_t));
|
||||||
return _empty_value_;
|
return _empty_value_;
|
||||||
}
|
}
|
||||||
static struct treeset_node *ts_impl_new_node(struct treeset *_set_,
|
static struct treeset_node *ts_impl_new_node(struct treeset *_set_, size_t value);
|
||||||
size_t value);
|
static struct treeset_node *ts_impl_get_node(struct treeset *_set_, size_t value);
|
||||||
static struct treeset_node *ts_impl_get_node(struct treeset *_set_,
|
|
||||||
size_t value);
|
|
||||||
static unsigned char ts_impl_h(struct treeset_node *node);
|
static unsigned char ts_impl_h(struct treeset_node *node);
|
||||||
static unsigned char ts_impl_hupdate(struct treeset_node *node);
|
static unsigned char ts_impl_hupdate(struct treeset_node *node);
|
||||||
static void ts_impl_rotate_right(struct treeset_node **Z);
|
static void ts_impl_rotate_right(struct treeset_node **Z);
|
||||||
@@ -113,9 +108,7 @@ struct treeset *ts_new(struct treeset_fval *f_val)
|
|||||||
_set_->callbacks = ((void *)0);
|
_set_->callbacks = ((void *)0);
|
||||||
return _set_;
|
return _set_;
|
||||||
}
|
}
|
||||||
struct treeset *ts_new_custom(struct treeset_fval *f_val,
|
struct treeset *ts_new_custom(struct treeset_fval *f_val, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_alloc_node *alloc,
|
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!f_val)
|
if (!f_val)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
@@ -190,8 +183,7 @@ void ts_free(struct treeset *_set_)
|
|||||||
ts_clear(_set_);
|
ts_clear(_set_);
|
||||||
_set_->alloc->free(_set_);
|
_set_->alloc->free(_set_);
|
||||||
}
|
}
|
||||||
void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc,
|
void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks)
|
||||||
struct cmc_callbacks *callbacks)
|
|
||||||
{
|
{
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
_set_->alloc = &cmc_alloc_node_default;
|
_set_->alloc = &cmc_alloc_node_default;
|
||||||
@@ -422,8 +414,7 @@ int ts_flag(struct treeset *_set_)
|
|||||||
}
|
}
|
||||||
struct treeset *ts_copy_of(struct treeset *_set_)
|
struct treeset *ts_copy_of(struct treeset *_set_)
|
||||||
{
|
{
|
||||||
struct treeset *result =
|
struct treeset *result = ts_new_custom(_set_->f_val, _set_->alloc, _set_->callbacks);
|
||||||
ts_new_custom(_set_->f_val, _set_->alloc, _set_->callbacks);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_set_->flag = CMC_FLAG_ERROR;
|
_set_->flag = CMC_FLAG_ERROR;
|
||||||
@@ -457,52 +448,9 @@ _Bool ts_equals(struct treeset *_set1_, struct treeset *_set2_)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct cmc_string ts_to_string(struct treeset *_set_)
|
|
||||||
{
|
|
||||||
struct cmc_string str;
|
|
||||||
struct treeset *s_ = _set_;
|
|
||||||
int n = snprintf(str.s, cmc_string_len, cmc_cmc_string_fmt_treeset,
|
|
||||||
"CMC_PARAM_SNAME((ts, treeset, , , size_t))",
|
|
||||||
"CMC_PARAM_V((ts, treeset, , , size_t))", s_, s_->root,
|
|
||||||
s_->count, s_->flag, s_->f_val, s_->alloc, s_->callbacks);
|
|
||||||
return n >= 0 ? str : (struct cmc_string){ 0 };
|
|
||||||
}
|
|
||||||
_Bool ts_print(struct treeset *_set_, FILE *fptr)
|
|
||||||
{
|
|
||||||
struct treeset_node *root = _set_->root;
|
|
||||||
_Bool left_done = 0;
|
|
||||||
while (root)
|
|
||||||
{
|
|
||||||
if (!left_done)
|
|
||||||
{
|
|
||||||
while (root->left)
|
|
||||||
root = root->left;
|
|
||||||
}
|
|
||||||
if (!_set_->f_val->str(fptr, root->value))
|
|
||||||
return 0;
|
|
||||||
left_done = 1;
|
|
||||||
if (root->right)
|
|
||||||
{
|
|
||||||
left_done = 0;
|
|
||||||
root = root->right;
|
|
||||||
}
|
|
||||||
else if (root->parent)
|
|
||||||
{
|
|
||||||
while (root->parent && root == root->parent->right)
|
|
||||||
root = root->parent;
|
|
||||||
if (!root->parent)
|
|
||||||
break;
|
|
||||||
root = root->parent;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_)
|
struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_)
|
||||||
{
|
{
|
||||||
struct treeset *_set_r_ =
|
struct treeset *_set_r_ = ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
||||||
ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct treeset_iter iter1 = ts_iter_start(_set1_);
|
struct treeset_iter iter1 = ts_iter_start(_set1_);
|
||||||
@@ -519,8 +467,7 @@ struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_)
|
|||||||
}
|
}
|
||||||
struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_)
|
struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_)
|
||||||
{
|
{
|
||||||
struct treeset *_set_r_ =
|
struct treeset *_set_r_ = ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
||||||
ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct treeset *_set_A_ = _set1_->count < _set2_->count ? _set1_ : _set2_;
|
struct treeset *_set_A_ = _set1_->count < _set2_->count ? _set1_ : _set2_;
|
||||||
@@ -536,8 +483,7 @@ struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_)
|
|||||||
}
|
}
|
||||||
struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_)
|
struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_)
|
||||||
{
|
{
|
||||||
struct treeset *_set_r_ =
|
struct treeset *_set_r_ = ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
||||||
ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct treeset_iter iter = ts_iter_start(_set1_);
|
struct treeset_iter iter = ts_iter_start(_set1_);
|
||||||
@@ -549,11 +495,9 @@ struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_)
|
|||||||
}
|
}
|
||||||
return _set_r_;
|
return _set_r_;
|
||||||
}
|
}
|
||||||
struct treeset *ts_symmetric_difference(struct treeset *_set1_,
|
struct treeset *ts_symmetric_difference(struct treeset *_set1_, struct treeset *_set2_)
|
||||||
struct treeset *_set2_)
|
|
||||||
{
|
{
|
||||||
struct treeset *_set_r_ =
|
struct treeset *_set_r_ = ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
||||||
ts_new_custom(_set1_->f_val, _set1_->alloc, _set1_->callbacks);
|
|
||||||
if (!_set_r_)
|
if (!_set_r_)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
struct treeset_iter iter1 = ts_iter_start(_set1_);
|
struct treeset_iter iter1 = ts_iter_start(_set1_);
|
||||||
@@ -811,11 +755,9 @@ size_t ts_iter_index(struct treeset_iter *iter)
|
|||||||
{
|
{
|
||||||
return iter->index;
|
return iter->index;
|
||||||
}
|
}
|
||||||
static struct treeset_node *ts_impl_new_node(struct treeset *_set_,
|
static struct treeset_node *ts_impl_new_node(struct treeset *_set_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
struct treeset_node *node =
|
struct treeset_node *node = _set_->alloc->malloc(sizeof(struct treeset_node));
|
||||||
_set_->alloc->malloc(sizeof(struct treeset_node));
|
|
||||||
if (!node)
|
if (!node)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
node->value = value;
|
node->value = value;
|
||||||
@@ -825,8 +767,7 @@ static struct treeset_node *ts_impl_new_node(struct treeset *_set_,
|
|||||||
node->height = 0;
|
node->height = 0;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
static struct treeset_node *ts_impl_get_node(struct treeset *_set_,
|
static struct treeset_node *ts_impl_get_node(struct treeset *_set_, size_t value)
|
||||||
size_t value)
|
|
||||||
{
|
{
|
||||||
struct treeset_node *scan = _set_->root;
|
struct treeset_node *scan = _set_->root;
|
||||||
while (scan != ((void *)0))
|
while (scan != ((void *)0))
|
||||||
|
|||||||
+17
-34
@@ -4,9 +4,8 @@
|
|||||||
|
|
||||||
#include "../src/bitset.c"
|
#include "../src/bitset.c"
|
||||||
|
|
||||||
struct cmc_alloc_node *bs_alloc_node = &(struct cmc_alloc_node){
|
struct cmc_alloc_node *bs_alloc_node =
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
};
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(BitSet, true, {
|
CMC_CREATE_UNIT(BitSet, true, {
|
||||||
const size_t word_bytes = sizeof(cmc_bitset_word);
|
const size_t word_bytes = sizeof(cmc_bitset_word);
|
||||||
@@ -137,18 +136,14 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
bs->buffer[0] = 0;
|
bs->buffer[0] = 0;
|
||||||
|
|
||||||
cmc_assert(bs_set(bs, word_bits - 1));
|
cmc_assert(bs_set(bs, word_bits - 1));
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE,
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 1)), bs->buffer[0]);
|
||||||
((cmc_bitset_word)1 << (word_bits - 1)),
|
|
||||||
bs->buffer[0]);
|
|
||||||
|
|
||||||
cmc_assert(bs_set(bs, word_bits * 8 - 1));
|
cmc_assert(bs_set(bs, word_bits * 8 - 1));
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE,
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 1)),
|
||||||
((cmc_bitset_word)1 << (word_bits - 1)),
|
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 8 - 1)]);
|
bs->buffer[bs_bit_to_index(word_bits * 8 - 1)]);
|
||||||
|
|
||||||
cmc_assert(bs_set(bs, word_bits * 18 - 2));
|
cmc_assert(bs_set(bs, word_bits * 18 - 2));
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE,
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 2)),
|
||||||
((cmc_bitset_word)1 << (word_bits - 2)),
|
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 18 - 2)]);
|
bs->buffer[bs_bit_to_index(word_bits * 18 - 2)]);
|
||||||
|
|
||||||
bs_free(bs);
|
bs_free(bs);
|
||||||
@@ -177,28 +172,23 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
cmc_assert_equals(uint8_t, 244, bs->buffer[0]);
|
cmc_assert_equals(uint8_t, 244, bs->buffer[0]);
|
||||||
|
|
||||||
cmc_assert(bs_set_range(bs, word_bits * 6 - 2, word_bits * 6 - 2));
|
cmc_assert(bs_set_range(bs, word_bits * 6 - 2, word_bits * 6 - 2));
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE,
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ((cmc_bitset_word)1 << (word_bits - 2)),
|
||||||
((cmc_bitset_word)1 << (word_bits - 2)),
|
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 6 - 2)]);
|
bs->buffer[bs_bit_to_index(word_bits * 6 - 2)]);
|
||||||
|
|
||||||
// Make sure we have at least word_bits * 40 slots
|
// Make sure we have at least word_bits * 40 slots
|
||||||
bs_set(bs, word_bits * 40);
|
bs_set(bs, word_bits * 40);
|
||||||
|
|
||||||
cmc_assert(bs_set_range(bs, word_bits * 20, word_bits * 21 - 1));
|
cmc_assert(bs_set_range(bs, word_bits * 20, word_bits * 21 - 1));
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, (~(cmc_bitset_word)0),
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, (~(cmc_bitset_word)0), bs->buffer[bs_bit_to_index(word_bits * 20)]);
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 20)]);
|
|
||||||
|
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0,
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[bs_bit_to_index(word_bits * 20 - 1)]);
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 20 - 1)]);
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0, bs->buffer[bs_bit_to_index(word_bits * 21 + 1)]);
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, 0,
|
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 21 + 1)]);
|
|
||||||
|
|
||||||
cmc_assert(bs_set_range(bs, 0, word_bits * 100 - 1));
|
cmc_assert(bs_set_range(bs, 0, word_bits * 100 - 1));
|
||||||
cmc_assert_equals(size_t, 100, bs->capacity);
|
cmc_assert_equals(size_t, 100, bs->capacity);
|
||||||
|
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0),
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0), bs->buffer[i]);
|
||||||
bs->buffer[i]);
|
|
||||||
|
|
||||||
bs_free(bs);
|
bs_free(bs);
|
||||||
});
|
});
|
||||||
@@ -239,8 +229,7 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
cmc_assert(bs_set_range(bs, word_bits * 20, word_bits * 21 - 1));
|
cmc_assert(bs_set_range(bs, word_bits * 20, word_bits * 21 - 1));
|
||||||
cmc_assert(bs_clear_range(bs, word_bits * 20, word_bits * 21 - 1));
|
cmc_assert(bs_clear_range(bs, word_bits * 20, word_bits * 21 - 1));
|
||||||
|
|
||||||
cmc_assert_equals(uint32_t, 0,
|
cmc_assert_equals(uint32_t, 0, bs->buffer[bs_bit_to_index(word_bits * 20)]);
|
||||||
bs->buffer[bs_bit_to_index(word_bits * 20)]);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
bs->buffer[i] = ~((cmc_bitset_word)0);
|
bs->buffer[i] = ~((cmc_bitset_word)0);
|
||||||
@@ -309,8 +298,7 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
cmc_assert_equals(size_t, 100, bs->capacity);
|
cmc_assert_equals(size_t, 100, bs->capacity);
|
||||||
|
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0),
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0), bs->buffer[i]);
|
||||||
bs->buffer[i]);
|
|
||||||
|
|
||||||
bs_free(bs);
|
bs_free(bs);
|
||||||
});
|
});
|
||||||
@@ -359,8 +347,7 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
cmc_assert_equals(size_t, 100, bs->capacity);
|
cmc_assert_equals(size_t, 100, bs->capacity);
|
||||||
|
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0),
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0), bs->buffer[i]);
|
||||||
bs->buffer[i]);
|
|
||||||
|
|
||||||
cmc_assert(bs_put_range(bs, 0, word_bits * 100 - 1, false));
|
cmc_assert(bs_put_range(bs, 0, word_bits * 100 - 1, false));
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
@@ -377,8 +364,7 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
cmc_assert(bs_set_all(bs));
|
cmc_assert(bs_set_all(bs));
|
||||||
|
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0),
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0), bs->buffer[i]);
|
||||||
bs->buffer[i]);
|
|
||||||
|
|
||||||
bs_free(bs);
|
bs_free(bs);
|
||||||
});
|
});
|
||||||
@@ -404,8 +390,7 @@ CMC_CREATE_UNIT(BitSet, true, {
|
|||||||
|
|
||||||
cmc_assert(bs_flip_all(bs));
|
cmc_assert(bs_flip_all(bs));
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0),
|
cmc_assert_equals(CMC_BITSET_WORD_TYPE, ~((cmc_bitset_word)0), bs->buffer[i]);
|
||||||
bs->buffer[i]);
|
|
||||||
|
|
||||||
cmc_assert(bs_flip_all(bs));
|
cmc_assert(bs_flip_all(bs));
|
||||||
for (size_t i = 0; i < bs->capacity; i++)
|
for (size_t i = 0; i < bs->capacity; i++)
|
||||||
@@ -457,12 +442,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = BitSet() + BitSetIter();
|
int result = BitSet() + BitSetIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | BitSet Suit : %-47s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | BitSet Suit : %-47s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+22
-42
@@ -4,24 +4,17 @@
|
|||||||
|
|
||||||
#include "../src/deque.c"
|
#include "../src/deque.c"
|
||||||
|
|
||||||
struct deque_fval *d_fval = &(struct deque_fval){ .cmp = cmc_size_cmp,
|
struct deque_fval *d_fval = &(struct deque_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct deque_fval *d_fval_counter = &(struct deque_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *d_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct deque_fval *d_fval_counter = &(struct deque_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *d_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(Deque, true, {
|
CMC_CREATE_UNIT(Deque, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct deque *d = d_new(1000000, d_fval);
|
struct deque *d = d_new(1000000, d_fval);
|
||||||
@@ -50,8 +43,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct deque *d =
|
struct deque *d = d_new_custom(1000000, d_fval, d_alloc_node, callbacks);
|
||||||
d_new_custom(1000000, d_fval, d_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, d);
|
cmc_assert_not_equals(ptr, NULL, d);
|
||||||
cmc_assert_not_equals(ptr, NULL, d->buffer);
|
cmc_assert_not_equals(ptr, NULL, d->buffer);
|
||||||
@@ -176,8 +168,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
cmc_assert_equals(size_t, 1000, d_count(d));
|
cmc_assert_equals(size_t, 1000, d_count(d));
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
|
|
||||||
cmc_assert_equals(size_t, 500500, sum);
|
cmc_assert_equals(size_t, 500500, sum);
|
||||||
@@ -219,8 +210,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
cmc_assert_equals(size_t, 1000, d_count(d));
|
cmc_assert_equals(size_t, 1000, d_count(d));
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
|
|
||||||
cmc_assert_equals(size_t, 500500, sum);
|
cmc_assert_equals(size_t, 500500, sum);
|
||||||
@@ -319,8 +309,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -367,8 +356,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -417,8 +405,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -437,8 +424,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -482,8 +468,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -502,8 +487,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -802,8 +786,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -1093,8 +1076,7 @@ CMC_CREATE_UNIT(Deque, true, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (size_t i = d->front, j = 0; j < d->count;
|
for (size_t i = d->front, j = 0; j < d->count; i = (i + 1) % d->capacity, j++)
|
||||||
i = (i + 1) % d->capacity, j++)
|
|
||||||
sum += d->buffer[i];
|
sum += d->buffer[i];
|
||||||
|
|
||||||
cmc_assert_equals(size_t, 1200, d_count(d));
|
cmc_assert_equals(size_t, 1200, d_count(d));
|
||||||
@@ -1732,12 +1714,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = Deque() + DequeIter();
|
int result = Deque() + DequeIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | Deque Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | Deque Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+102
-117
@@ -31,13 +31,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<Deque>, {
|
CMC_CREATE_TEST(CMC<Deque>, {
|
||||||
struct deque *d =
|
struct deque *d = d_new(10000, &(struct deque_fval){ .cmp = cmc_size_cmp,
|
||||||
d_new(10000, &(struct deque_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
d_push_back(d, i);
|
d_push_back(d, i);
|
||||||
@@ -81,20 +80,19 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<HashMap>, {
|
CMC_CREATE_TEST(CMC<HashMap>, {
|
||||||
struct hashmap *hm =
|
struct hashmap *hm = hm_new(10000, 0.6,
|
||||||
hm_new(10000, 0.6,
|
&(struct hashmap_fkey){ .cmp = cmc_size_cmp,
|
||||||
&(struct hashmap_fkey){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp },
|
||||||
.pri = cmc_size_cmp },
|
&(struct hashmap_fval){ .cmp = cmc_size_cmp,
|
||||||
&(struct hashmap_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
hm_insert(hm, i, i);
|
hm_insert(hm, i, i);
|
||||||
@@ -123,20 +121,19 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<HashMultiMap>, {
|
CMC_CREATE_TEST(CMC<HashMultiMap>, {
|
||||||
struct hashmultimap *hmm =
|
struct hashmultimap *hmm = hmm_new(10000, 0.6,
|
||||||
hmm_new(10000, 0.6,
|
&(struct hashmultimap_fkey){ .cmp = cmc_size_cmp,
|
||||||
&(struct hashmultimap_fkey){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp },
|
||||||
.pri = cmc_size_cmp },
|
&(struct hashmultimap_fval){ .cmp = cmc_size_cmp,
|
||||||
&(struct hashmultimap_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
hmm_insert(hmm, i, i);
|
hmm_insert(hmm, i, i);
|
||||||
@@ -165,14 +162,13 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<HashMultiSet>, {
|
CMC_CREATE_TEST(CMC<HashMultiSet>, {
|
||||||
struct hashmultiset *hms =
|
struct hashmultiset *hms = hms_new(10000, 0.6,
|
||||||
hms_new(10000, 0.6,
|
&(struct hashmultiset_fval){ .cmp = cmc_size_cmp,
|
||||||
&(struct hashmultiset_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
hms_insert_many(hms, i, i);
|
hms_insert_many(hms, i, i);
|
||||||
@@ -201,14 +197,13 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<HashSet>, {
|
CMC_CREATE_TEST(CMC<HashSet>, {
|
||||||
struct hashset *hs =
|
struct hashset *hs = hs_new(10000, 0.6,
|
||||||
hs_new(10000, 0.6,
|
&(struct hashset_fval){ .cmp = cmc_size_cmp,
|
||||||
&(struct hashset_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
hs_insert(hs, i);
|
hs_insert(hs, i);
|
||||||
@@ -260,13 +255,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<IntervalHeap>, {
|
CMC_CREATE_TEST(CMC<IntervalHeap>, {
|
||||||
struct intervalheap *ih =
|
struct intervalheap *ih = ih_new(10000, &(struct intervalheap_fval){ .cmp = cmc_size_cmp,
|
||||||
ih_new(10000, &(struct intervalheap_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
ih_insert(ih, i);
|
ih_insert(ih, i);
|
||||||
@@ -289,13 +283,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<LinkedList>, {
|
CMC_CREATE_TEST(CMC<LinkedList>, {
|
||||||
struct linkedlist *ll =
|
struct linkedlist *ll = ll_new(&(struct linkedlist_fval){ .cmp = cmc_size_cmp,
|
||||||
ll_new(&(struct linkedlist_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
ll_push_back(ll, i);
|
ll_push_back(ll, i);
|
||||||
@@ -318,13 +311,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<List>, {
|
CMC_CREATE_TEST(CMC<List>, {
|
||||||
struct list *l =
|
struct list *l = l_new(10000, &(struct list_fval){ .cmp = cmc_size_cmp,
|
||||||
l_new(10000, &(struct list_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
l_push_back(l, i);
|
l_push_back(l, i);
|
||||||
@@ -347,13 +339,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<Queue>, {
|
CMC_CREATE_TEST(CMC<Queue>, {
|
||||||
struct queue *q =
|
struct queue *q = q_new(10000, &(struct queue_fval){ .cmp = cmc_size_cmp,
|
||||||
q_new(10000, &(struct queue_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
q_enqueue(q, i);
|
q_enqueue(q, i);
|
||||||
@@ -376,13 +367,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<SortedList>, {
|
CMC_CREATE_TEST(CMC<SortedList>, {
|
||||||
struct sortedlist *sl =
|
struct sortedlist *sl = sl_new(10000, &(struct sortedlist_fval){ .cmp = cmc_size_cmp,
|
||||||
sl_new(10000, &(struct sortedlist_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
sl_insert(sl, i);
|
sl_insert(sl, i);
|
||||||
@@ -405,13 +395,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<Stack>, {
|
CMC_CREATE_TEST(CMC<Stack>, {
|
||||||
struct stack *s =
|
struct stack *s = s_new(10000, &(struct stack_fval){ .cmp = cmc_size_cmp,
|
||||||
s_new(10000, &(struct stack_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
s_push(s, i);
|
s_push(s, i);
|
||||||
@@ -434,19 +423,18 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<TreeMap>, {
|
CMC_CREATE_TEST(CMC<TreeMap>, {
|
||||||
struct treemap *tm =
|
struct treemap *tm = tm_new(&(struct treemap_fkey){ .cmp = cmc_size_cmp,
|
||||||
tm_new(&(struct treemap_fkey){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp },
|
||||||
.pri = cmc_size_cmp },
|
&(struct treemap_fval){ .cmp = cmc_size_cmp,
|
||||||
&(struct treemap_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
tm_insert(tm, i, i);
|
tm_insert(tm, i, i);
|
||||||
@@ -475,13 +463,12 @@ CMC_CREATE_UNIT(ForEach, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(CMC<TreeSet>, {
|
CMC_CREATE_TEST(CMC<TreeSet>, {
|
||||||
struct treeset *ts =
|
struct treeset *ts = ts_new(&(struct treeset_fval){ .cmp = cmc_size_cmp,
|
||||||
ts_new(&(struct treeset_fval){ .cmp = cmc_size_cmp,
|
.cpy = NULL,
|
||||||
.cpy = NULL,
|
.str = cmc_size_str,
|
||||||
.str = cmc_size_str,
|
.free = NULL,
|
||||||
.free = NULL,
|
.hash = cmc_size_hash,
|
||||||
.hash = cmc_size_hash,
|
.pri = cmc_size_cmp });
|
||||||
.pri = cmc_size_cmp });
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= 10000; i++)
|
for (size_t i = 1; i <= 10000; i++)
|
||||||
ts_insert(ts, i);
|
ts_insert(ts, i);
|
||||||
@@ -509,12 +496,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = ForEach();
|
int result = ForEach();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | ForEach Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | ForEach Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,42 +4,25 @@
|
|||||||
|
|
||||||
#include "../src/hashbidimap.c"
|
#include "../src/hashbidimap.c"
|
||||||
|
|
||||||
struct hashbidimap_fkey *hbm_fkey =
|
struct hashbidimap_fkey *hbm_fkey = &(struct hashbidimap_fkey){
|
||||||
&(struct hashbidimap_fkey){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashbidimap_fval *hbm_fval =
|
|
||||||
&(struct hashbidimap_fval){ .cmp = cmc_size_cmp,
|
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashbidimap_fkey *hbm_fkey_counter =
|
|
||||||
&(struct hashbidimap_fkey){ .cmp = k_c_cmp,
|
|
||||||
.cpy = k_c_cpy,
|
|
||||||
.str = k_c_str,
|
|
||||||
.free = k_c_free,
|
|
||||||
.hash = k_c_hash,
|
|
||||||
.pri = k_c_pri };
|
|
||||||
|
|
||||||
struct hashbidimap_fval *hbm_fval_counter =
|
|
||||||
&(struct hashbidimap_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *hbm_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct hashbidimap_fval *hbm_fval = &(struct hashbidimap_fval){
|
||||||
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hashbidimap_fkey *hbm_fkey_counter = &(struct hashbidimap_fkey){
|
||||||
|
.cmp = k_c_cmp, .cpy = k_c_cpy, .str = k_c_str, .free = k_c_free, .hash = k_c_hash, .pri = k_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hashbidimap_fval *hbm_fval_counter = &(struct hashbidimap_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *hbm_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashBidiMap, true, {
|
CMC_CREATE_UNIT(HashBidiMap, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct hashbidimap *map = hbm_new(943722, 0.6, hbm_fkey, hbm_fval);
|
struct hashbidimap *map = hbm_new(943722, 0.6, hbm_fkey, hbm_fval);
|
||||||
@@ -87,8 +70,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct hashbidimap *map = hbm_new_custom(
|
struct hashbidimap *map = hbm_new_custom(943722, 0.6, hbm_fkey, hbm_fval, hbm_alloc_node, callbacks);
|
||||||
943722, 0.6, hbm_fkey, hbm_fval, hbm_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
cmc_assert_not_equals(ptr, NULL, map->buffer);
|
cmc_assert_not_equals(ptr, NULL, map->buffer);
|
||||||
@@ -123,8 +105,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
CMC_CREATE_TEST(PFX##_clear(), {
|
CMC_CREATE_TEST(PFX##_clear(), {
|
||||||
k_total_free = 0;
|
k_total_free = 0;
|
||||||
v_total_free = 0;
|
v_total_free = 0;
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new(100, 0.6, hbm_fkey_counter, hbm_fval_counter);
|
||||||
hbm_new(100, 0.6, hbm_fkey_counter, hbm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -149,8 +130,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
CMC_CREATE_TEST(PFX##_free(), {
|
CMC_CREATE_TEST(PFX##_free(), {
|
||||||
k_total_free = 0;
|
k_total_free = 0;
|
||||||
v_total_free = 0;
|
v_total_free = 0;
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new(100, 0.6, hbm_fkey_counter, hbm_fval_counter);
|
||||||
hbm_new(100, 0.6, hbm_fkey_counter, hbm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -178,8 +158,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(customize, {
|
CMC_CREATE_TEST(customize, {
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new_custom(100, 0.6, hbm_fkey, hbm_fval, NULL, NULL);
|
||||||
hbm_new_custom(100, 0.6, hbm_fkey, hbm_fval, NULL, NULL);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -313,8 +292,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(insert[ftab hash calls], {
|
CMC_CREATE_TEST(insert[ftab hash calls], {
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new(100, 0.7, hbm_fkey_counter, hbm_fval_counter);
|
||||||
hbm_new(100, 0.7, hbm_fkey_counter, hbm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -468,13 +446,10 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(remove_by_key[cleanup custom], {
|
CMC_CREATE_TEST(remove_by_key[cleanup custom], {
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new_custom(
|
||||||
hbm_new_custom(10000, 0.6, hbm_fkey, hbm_fval,
|
10000, 0.6, hbm_fkey, hbm_fval,
|
||||||
&(struct cmc_alloc_node){ .malloc = malloc,
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free },
|
||||||
.calloc = calloc,
|
&(struct cmc_callbacks){ 0 });
|
||||||
.realloc = realloc,
|
|
||||||
.free = free },
|
|
||||||
&(struct cmc_callbacks){ 0 });
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -493,21 +468,17 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
struct hashbidimap_entry *k = map->buffer[i][0];
|
struct hashbidimap_entry *k = map->buffer[i][0];
|
||||||
struct hashbidimap_entry *v = map->buffer[i][1];
|
struct hashbidimap_entry *v = map->buffer[i][1];
|
||||||
|
|
||||||
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) &&
|
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) && (v == NULL || v == CMC_ENTRY_DELETED));
|
||||||
(v == NULL || v == CMC_ENTRY_DELETED));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hbm_free(map);
|
hbm_free(map);
|
||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(remove_by_val[cleanup custom], {
|
CMC_CREATE_TEST(remove_by_val[cleanup custom], {
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new_custom(
|
||||||
hbm_new_custom(10000, 0.6, hbm_fkey, hbm_fval,
|
10000, 0.6, hbm_fkey, hbm_fval,
|
||||||
&(struct cmc_alloc_node){ .malloc = malloc,
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free },
|
||||||
.calloc = calloc,
|
&(struct cmc_callbacks){ 0 });
|
||||||
.realloc = realloc,
|
|
||||||
.free = free },
|
|
||||||
&(struct cmc_callbacks){ 0 });
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -526,8 +497,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
struct hashbidimap_entry *k = map->buffer[i][0];
|
struct hashbidimap_entry *k = map->buffer[i][0];
|
||||||
struct hashbidimap_entry *v = map->buffer[i][1];
|
struct hashbidimap_entry *v = map->buffer[i][1];
|
||||||
|
|
||||||
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) &&
|
cmc_assert((k == NULL || k == CMC_ENTRY_DELETED) && (v == NULL || v == CMC_ENTRY_DELETED));
|
||||||
(v == NULL || v == CMC_ENTRY_DELETED));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hbm_free(map);
|
hbm_free(map);
|
||||||
@@ -601,8 +571,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
cmc_assert_equals(int32_t, CMC_FLAG_OK, hbm_flag(map));
|
cmc_assert_equals(int32_t, CMC_FLAG_OK, hbm_flag(map));
|
||||||
|
|
||||||
// customize
|
// customize
|
||||||
hbm_customize(map, &cmc_alloc_node_default,
|
hbm_customize(map, &cmc_alloc_node_default, &(struct cmc_callbacks){ 0 });
|
||||||
&(struct cmc_callbacks){ 0 });
|
|
||||||
cmc_assert_equals(int32_t, CMC_FLAG_OK, hbm_flag(map));
|
cmc_assert_equals(int32_t, CMC_FLAG_OK, hbm_flag(map));
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
@@ -731,8 +700,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(callbacks, {
|
CMC_CREATE_TEST(callbacks, {
|
||||||
struct hashbidimap *map =
|
struct hashbidimap *map = hbm_new_custom(100, 0.7, hbm_fkey, hbm_fval, NULL, callbacks);
|
||||||
hbm_new_custom(100, 0.7, hbm_fkey, hbm_fval, NULL, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
cmc_assert_equals(ptr, callbacks, map->callbacks);
|
cmc_assert_equals(ptr, callbacks, map->callbacks);
|
||||||
@@ -835,13 +803,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = HashBidiMap() + HashBidiMapIter();
|
int result = HashBidiMap() + HashBidiMapIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | HashBidiMap Suit : %-42s |\n",
|
printf(" | HashBidiMap Suit : %-42s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
result == 0 ? "PASSED" : "FAILED");
|
printf(" +---------------------------------------------------------------+");
|
||||||
printf(
|
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+29
-55
@@ -4,38 +4,25 @@
|
|||||||
|
|
||||||
#include "../src/hashmap.c"
|
#include "../src/hashmap.c"
|
||||||
|
|
||||||
struct hashmap_fkey *hm_fkey = &(struct hashmap_fkey){ .cmp = cmc_size_cmp,
|
struct hashmap_fkey *hm_fkey = &(struct hashmap_fkey){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashmap_fval *hm_fval = &(struct hashmap_fval){ .cmp = cmc_size_cmp,
|
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashmap_fkey *hm_fkey_counter = &(struct hashmap_fkey){ .cmp = k_c_cmp,
|
|
||||||
.cpy = k_c_cpy,
|
|
||||||
.str = k_c_str,
|
|
||||||
.free = k_c_free,
|
|
||||||
.hash = k_c_hash,
|
|
||||||
.pri = k_c_pri };
|
|
||||||
|
|
||||||
struct hashmap_fval *hm_fval_counter = &(struct hashmap_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *hm_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct hashmap_fval *hm_fval = &(struct hashmap_fval){
|
||||||
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hashmap_fkey *hm_fkey_counter = &(struct hashmap_fkey){
|
||||||
|
.cmp = k_c_cmp, .cpy = k_c_cpy, .str = k_c_str, .free = k_c_free, .hash = k_c_hash, .pri = k_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hashmap_fval *hm_fval_counter = &(struct hashmap_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *hm_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashMap, true, {
|
CMC_CREATE_UNIT(HashMap, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct hashmap *map = hm_new(943722, 0.6, hm_fkey, hm_fval);
|
struct hashmap *map = hm_new(943722, 0.6, hm_fkey, hm_fval);
|
||||||
@@ -71,8 +58,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct hashmap *map = hm_new_custom(943722, 0.6, hm_fkey, hm_fval,
|
struct hashmap *map = hm_new_custom(943722, 0.6, hm_fkey, hm_fval, hm_alloc_node, callbacks);
|
||||||
hm_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
cmc_assert_not_equals(ptr, NULL, map->buffer);
|
cmc_assert_not_equals(ptr, NULL, map->buffer);
|
||||||
@@ -172,8 +158,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
CMC_CREATE_TEST(PFX##_clear(), {
|
CMC_CREATE_TEST(PFX##_clear(), {
|
||||||
k_total_free = 0;
|
k_total_free = 0;
|
||||||
v_total_free = 0;
|
v_total_free = 0;
|
||||||
struct hashmap *map =
|
struct hashmap *map = hm_new(100, 0.6, hm_fkey_counter, hm_fval_counter);
|
||||||
hm_new(100, 0.6, hm_fkey_counter, hm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -205,8 +190,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
CMC_CREATE_TEST(PFX##_free(), {
|
CMC_CREATE_TEST(PFX##_free(), {
|
||||||
k_total_free = 0;
|
k_total_free = 0;
|
||||||
v_total_free = 0;
|
v_total_free = 0;
|
||||||
struct hashmap *map =
|
struct hashmap *map = hm_new(100, 0.6, hm_fkey_counter, hm_fval_counter);
|
||||||
hm_new(100, 0.6, hm_fkey_counter, hm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -360,8 +344,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
capacity = hm_capacity(map);
|
capacity = hm_capacity(map);
|
||||||
|
|
||||||
// Just to be sure, not part of the test
|
// Just to be sure, not part of the test
|
||||||
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1,
|
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1, hashcapminus1(0));
|
||||||
hashcapminus1(0));
|
|
||||||
cmc_assert_equals(size_t, capacity - 1, hashcapminus1(0));
|
cmc_assert_equals(size_t, capacity - 1, hashcapminus1(0));
|
||||||
|
|
||||||
cmc_assert(hm_insert(map, 0, 0));
|
cmc_assert(hm_insert(map, 0, 0));
|
||||||
@@ -636,8 +619,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_full(), {
|
CMC_CREATE_TEST(PFX##_full(), {
|
||||||
struct hashmap *map =
|
struct hashmap *map = hm_new(cmc_hashtable_primes[0], 0.99999, hm_fkey, hm_fval);
|
||||||
hm_new(cmc_hashtable_primes[0], 0.99999, hm_fkey, hm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -676,8 +658,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6),
|
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6), hm_capacity(map));
|
||||||
hm_capacity(map));
|
|
||||||
|
|
||||||
hm_free(map);
|
hm_free(map);
|
||||||
|
|
||||||
@@ -811,8 +792,7 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(callbacks, {
|
CMC_CREATE_TEST(callbacks, {
|
||||||
struct hashmap *map =
|
struct hashmap *map = hm_new_custom(100, 0.6, hm_fkey, hm_fval, NULL, callbacks);
|
||||||
hm_new_custom(100, 0.6, hm_fkey, hm_fval, NULL, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -890,13 +870,9 @@ CMC_CREATE_UNIT(HashMap, true, {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
struct hashmap_fkey *hm_fkey_numhash =
|
struct hashmap_fkey *hm_fkey_numhash = &(struct hashmap_fkey){
|
||||||
&(struct hashmap_fkey){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
};
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = numhash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashMapIter, true, {
|
CMC_CREATE_UNIT(HashMapIter, true, {
|
||||||
CMC_CREATE_TEST(PFX##_iter_start(), {
|
CMC_CREATE_TEST(PFX##_iter_start(), {
|
||||||
@@ -1344,12 +1320,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = HashMap() + HashMapIter();
|
int result = HashMap() + HashMapIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | HashMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | HashMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,42 +4,25 @@
|
|||||||
|
|
||||||
#include "../src/hashmultimap.c"
|
#include "../src/hashmultimap.c"
|
||||||
|
|
||||||
struct hashmultimap_fkey *hmm_fkey =
|
struct hashmultimap_fkey *hmm_fkey = &(struct hashmultimap_fkey){
|
||||||
&(struct hashmultimap_fkey){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashmultimap_fval *hmm_fval =
|
|
||||||
&(struct hashmultimap_fval){ .cmp = cmc_size_cmp,
|
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashmultimap_fkey *hmm_fkey_counter =
|
|
||||||
&(struct hashmultimap_fkey){ .cmp = k_c_cmp,
|
|
||||||
.cpy = k_c_cpy,
|
|
||||||
.str = k_c_str,
|
|
||||||
.free = k_c_free,
|
|
||||||
.hash = k_c_hash,
|
|
||||||
.pri = k_c_pri };
|
|
||||||
|
|
||||||
struct hashmultimap_fval *hmm_fval_counter =
|
|
||||||
&(struct hashmultimap_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *hmm_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct hashmultimap_fval *hmm_fval = &(struct hashmultimap_fval){
|
||||||
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hashmultimap_fkey *hmm_fkey_counter = &(struct hashmultimap_fkey){
|
||||||
|
.cmp = k_c_cmp, .cpy = k_c_cpy, .str = k_c_str, .free = k_c_free, .hash = k_c_hash, .pri = k_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct hashmultimap_fval *hmm_fval_counter = &(struct hashmultimap_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *hmm_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashMultiMap, true, {
|
CMC_CREATE_UNIT(HashMultiMap, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct hashmultimap *map = hmm_new(943722, 0.6, hmm_fkey, hmm_fval);
|
struct hashmultimap *map = hmm_new(943722, 0.6, hmm_fkey, hmm_fval);
|
||||||
@@ -87,8 +70,7 @@ CMC_CREATE_UNIT(HashMultiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct hashmultimap *map = hmm_new_custom(
|
struct hashmultimap *map = hmm_new_custom(943722, 0.6, hmm_fkey, hmm_fval, hmm_alloc_node, callbacks);
|
||||||
943722, 0.6, hmm_fkey, hmm_fval, hmm_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
cmc_assert_not_equals(ptr, NULL, map->buffer);
|
cmc_assert_not_equals(ptr, NULL, map->buffer);
|
||||||
@@ -123,8 +105,7 @@ CMC_CREATE_UNIT(HashMultiMap, true, {
|
|||||||
CMC_CREATE_TEST(PFX##_clear(), {
|
CMC_CREATE_TEST(PFX##_clear(), {
|
||||||
k_total_free = 0;
|
k_total_free = 0;
|
||||||
v_total_free = 0;
|
v_total_free = 0;
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_counter, hmm_fval_counter);
|
||||||
hmm_new(100, 0.6, hmm_fkey_counter, hmm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -149,8 +130,7 @@ CMC_CREATE_UNIT(HashMultiMap, true, {
|
|||||||
CMC_CREATE_TEST(PFX##_free(), {
|
CMC_CREATE_TEST(PFX##_free(), {
|
||||||
k_total_free = 0;
|
k_total_free = 0;
|
||||||
v_total_free = 0;
|
v_total_free = 0;
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_counter, hmm_fval_counter);
|
||||||
hmm_new(100, 0.6, hmm_fkey_counter, hmm_fval_counter);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -380,8 +360,7 @@ CMC_CREATE_UNIT(HashMultiMap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(callbacks, {
|
CMC_CREATE_TEST(callbacks, {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new_custom(100, 0.8, hmm_fkey, hmm_fval, NULL, callbacks);
|
||||||
hmm_new_custom(100, 0.8, hmm_fkey, hmm_fval, NULL, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -481,18 +460,13 @@ CMC_CREATE_UNIT(HashMultiMap, true, {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
struct hashmultimap_fkey *hmm_fkey_numhash =
|
struct hashmultimap_fkey *hmm_fkey_numhash = &(struct hashmultimap_fkey){
|
||||||
&(struct hashmultimap_fkey){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
};
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = numhash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
||||||
CMC_CREATE_TEST(PFX##_iter_start(), {
|
CMC_CREATE_TEST(PFX##_iter_start(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -526,8 +500,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_iter_end(), {
|
CMC_CREATE_TEST(PFX##_iter_end(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -607,8 +580,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_iter_to_start(), {
|
CMC_CREATE_TEST(PFX##_iter_to_start(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -639,8 +611,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_iter_to_end(), {
|
CMC_CREATE_TEST(PFX##_iter_to_end(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -681,8 +652,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
hmm_insert(map, i, i);
|
hmm_insert(map, i, i);
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (it = hmm_iter_start(map); !hmm_iter_at_end(&it);
|
for (it = hmm_iter_start(map); !hmm_iter_at_end(&it); hmm_iter_next(&it))
|
||||||
hmm_iter_next(&it))
|
|
||||||
{
|
{
|
||||||
sum += hmm_iter_value(&it);
|
sum += hmm_iter_value(&it);
|
||||||
}
|
}
|
||||||
@@ -715,8 +685,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
hmm_insert(map, i, i);
|
hmm_insert(map, i, i);
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (it = hmm_iter_end(map); !hmm_iter_at_start(&it);
|
for (it = hmm_iter_end(map); !hmm_iter_at_start(&it); hmm_iter_prev(&it))
|
||||||
hmm_iter_prev(&it))
|
|
||||||
{
|
{
|
||||||
sum += hmm_iter_value(&it);
|
sum += hmm_iter_value(&it);
|
||||||
}
|
}
|
||||||
@@ -737,8 +706,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_iter_advance(), {
|
CMC_CREATE_TEST(PFX##_iter_advance(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -772,8 +740,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_iter_rewind(), {
|
CMC_CREATE_TEST(PFX##_iter_rewind(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -807,8 +774,7 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_iter_go_to(), {
|
CMC_CREATE_TEST(PFX##_iter_go_to(), {
|
||||||
struct hashmultimap *map =
|
struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
||||||
hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, map);
|
cmc_assert_not_equals(ptr, NULL, map);
|
||||||
|
|
||||||
@@ -944,13 +910,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = HashMultiMap() + HashMultiMapIter();
|
int result = HashMultiMap() + HashMultiMapIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | HashMultiMap Suit : %-41s |\n",
|
printf(" | HashMultiMap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
result == 0 ? "PASSED" : "FAILED");
|
printf(" +---------------------------------------------------------------+");
|
||||||
printf(
|
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,26 +4,17 @@
|
|||||||
|
|
||||||
#include "../src/hashmultiset.c"
|
#include "../src/hashmultiset.c"
|
||||||
|
|
||||||
struct hashmultiset_fval *hms_fval =
|
struct hashmultiset_fval *hms_fval = &(struct hashmultiset_fval){
|
||||||
&(struct hashmultiset_fval){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashmultiset_fval *hms_fval_counter =
|
|
||||||
&(struct hashmultiset_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *hms_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct hashmultiset_fval *hms_fval_counter = &(struct hashmultiset_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *hms_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashMultiSet, true, {
|
CMC_CREATE_UNIT(HashMultiSet, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct hashmultiset *set = hms_new(943722, 0.6, hms_fval);
|
struct hashmultiset *set = hms_new(943722, 0.6, hms_fval);
|
||||||
@@ -55,8 +46,7 @@ CMC_CREATE_UNIT(HashMultiSet, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct hashmultiset *set =
|
struct hashmultiset *set = hms_new_custom(943722, 0.6, hms_fval, hms_alloc_node, callbacks);
|
||||||
hms_new_custom(943722, 0.6, hms_fval, hms_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, set);
|
cmc_assert_not_equals(ptr, NULL, set);
|
||||||
cmc_assert_not_equals(ptr, NULL, set->buffer);
|
cmc_assert_not_equals(ptr, NULL, set->buffer);
|
||||||
@@ -336,8 +326,7 @@ CMC_CREATE_UNIT(HashMultiSet, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(callbacks, {
|
CMC_CREATE_TEST(callbacks, {
|
||||||
struct hashmultiset *set =
|
struct hashmultiset *set = hms_new_custom(100, 0.8, hms_fval, NULL, callbacks);
|
||||||
hms_new_custom(100, 0.8, hms_fval, NULL, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, set);
|
cmc_assert_not_equals(ptr, NULL, set);
|
||||||
|
|
||||||
@@ -425,13 +414,9 @@ CMC_CREATE_UNIT(HashMultiSet, true, {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
struct hashmultiset_fval *hms_fval_numhash =
|
struct hashmultiset_fval *hms_fval_numhash = &(struct hashmultiset_fval){
|
||||||
&(struct hashmultiset_fval){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
};
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = numhash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashMultiSetIter, true, {
|
CMC_CREATE_UNIT(HashMultiSetIter, true, {
|
||||||
CMC_CREATE_TEST(PFX##_iter_start(), {
|
CMC_CREATE_TEST(PFX##_iter_start(), {
|
||||||
@@ -621,8 +606,7 @@ CMC_CREATE_UNIT(HashMultiSetIter, true, {
|
|||||||
hms_insert(set, i);
|
hms_insert(set, i);
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (it = hms_iter_start(set); !hms_iter_at_end(&it);
|
for (it = hms_iter_start(set); !hms_iter_at_end(&it); hms_iter_next(&it))
|
||||||
hms_iter_next(&it))
|
|
||||||
{
|
{
|
||||||
sum += hms_iter_value(&it);
|
sum += hms_iter_value(&it);
|
||||||
}
|
}
|
||||||
@@ -655,8 +639,7 @@ CMC_CREATE_UNIT(HashMultiSetIter, true, {
|
|||||||
hms_insert(set, i);
|
hms_insert(set, i);
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (it = hms_iter_end(set); !hms_iter_at_start(&it);
|
for (it = hms_iter_end(set); !hms_iter_at_start(&it); hms_iter_prev(&it))
|
||||||
hms_iter_prev(&it))
|
|
||||||
{
|
{
|
||||||
sum += hms_iter_value(&it);
|
sum += hms_iter_value(&it);
|
||||||
}
|
}
|
||||||
@@ -864,13 +847,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = HashMultiSet() + HashMultiSetIter();
|
int result = HashMultiSet() + HashMultiSetIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | HashMultiSet Suit : %-41s |\n",
|
printf(" | HashMultiSet Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
result == 0 ? "PASSED" : "FAILED");
|
printf(" +---------------------------------------------------------------+");
|
||||||
printf(
|
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+18
-35
@@ -4,24 +4,17 @@
|
|||||||
|
|
||||||
#include "../src/hashset.c"
|
#include "../src/hashset.c"
|
||||||
|
|
||||||
struct hashset_fval *hs_fval = &(struct hashset_fval){ .cmp = cmc_size_cmp,
|
struct hashset_fval *hs_fval = &(struct hashset_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct hashset_fval *hs_fval_counter = &(struct hashset_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *hs_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct hashset_fval *hs_fval_counter = &(struct hashset_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *hs_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashSet, true, {
|
CMC_CREATE_UNIT(HashSet, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct hashset *set = hs_new(943722, 0.6, hs_fval);
|
struct hashset *set = hs_new(943722, 0.6, hs_fval);
|
||||||
@@ -53,8 +46,7 @@ CMC_CREATE_UNIT(HashSet, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct hashset *set =
|
struct hashset *set = hs_new_custom(943722, 0.6, hs_fval, hs_alloc_node, callbacks);
|
||||||
hs_new_custom(943722, 0.6, hs_fval, hs_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, set);
|
cmc_assert_not_equals(ptr, NULL, set);
|
||||||
cmc_assert_not_equals(ptr, NULL, set->buffer);
|
cmc_assert_not_equals(ptr, NULL, set->buffer);
|
||||||
@@ -165,8 +157,7 @@ CMC_CREATE_UNIT(HashSet, true, {
|
|||||||
cmc_assert(hs_insert(set, capacity - 1));
|
cmc_assert(hs_insert(set, capacity - 1));
|
||||||
cmc_assert(hs_insert(set, capacity));
|
cmc_assert(hs_insert(set, capacity));
|
||||||
|
|
||||||
cmc_assert_equals(size_t, capacity - 1,
|
cmc_assert_equals(size_t, capacity - 1, set->buffer[capacity - 1].value);
|
||||||
set->buffer[capacity - 1].value);
|
|
||||||
cmc_assert_equals(size_t, capacity, set->buffer[0].value);
|
cmc_assert_equals(size_t, capacity, set->buffer[0].value);
|
||||||
|
|
||||||
hs_fval->hash = cmc_size_hash;
|
hs_fval->hash = cmc_size_hash;
|
||||||
@@ -206,8 +197,7 @@ CMC_CREATE_UNIT(HashSet, true, {
|
|||||||
size_t capacity = hs_capacity(set);
|
size_t capacity = hs_capacity(set);
|
||||||
|
|
||||||
// Just to be sure, not part of the test
|
// Just to be sure, not part of the test
|
||||||
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1,
|
cmc_assert_equals(size_t, cmc_hashtable_primes[0] - 1, hashcapminus1(0));
|
||||||
hashcapminus1(0));
|
|
||||||
cmc_assert_equals(size_t, capacity - 1, hashcapminus1(0));
|
cmc_assert_equals(size_t, capacity - 1, hashcapminus1(0));
|
||||||
|
|
||||||
cmc_assert(hs_insert(set, 0));
|
cmc_assert(hs_insert(set, 0));
|
||||||
@@ -451,8 +441,7 @@ CMC_CREATE_UNIT(HashSet, true, {
|
|||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, set);
|
cmc_assert_not_equals(ptr, NULL, set);
|
||||||
|
|
||||||
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6),
|
cmc_assert_greater_equals(size_t, (size_t)(2500 / 0.6), hs_capacity(set));
|
||||||
hs_capacity(set));
|
|
||||||
|
|
||||||
hs_free(set);
|
hs_free(set);
|
||||||
});
|
});
|
||||||
@@ -625,13 +614,9 @@ CMC_CREATE_UNIT(HashSet, true, {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
struct hashset_fval *hs_fval_numhash =
|
struct hashset_fval *hs_fval_numhash = &(struct hashset_fval){
|
||||||
&(struct hashset_fval){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
};
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = numhash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(HashSetIter, true, {
|
CMC_CREATE_UNIT(HashSetIter, true, {
|
||||||
CMC_CREATE_TEST(PFX##_iter_start(), {
|
CMC_CREATE_TEST(PFX##_iter_start(), {
|
||||||
@@ -1042,12 +1027,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = HashSet() + HashSetIter();
|
int result = HashSet() + HashSetIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | HashSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | HashSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+6
-12
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/heap.c"
|
#include "../src/heap.c"
|
||||||
|
|
||||||
struct heap_fval *h_fval = &(struct heap_fval){ .cmp = cmc_size_cmp,
|
struct heap_fval *h_fval = &(struct heap_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(Heap, true, {
|
CMC_CREATE_UNIT(Heap, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -222,8 +219,7 @@ CMC_CREATE_UNIT(Heap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(callbacks, {
|
CMC_CREATE_TEST(callbacks, {
|
||||||
struct heap *h =
|
struct heap *h = h_new_custom(100, CMC_MAX_HEAP, h_fval, NULL, callbacks);
|
||||||
h_new_custom(100, CMC_MAX_HEAP, h_fval, NULL, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, h);
|
cmc_assert_not_equals(ptr, NULL, h);
|
||||||
|
|
||||||
@@ -720,12 +716,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = Heap() + HeapIter();
|
int result = Heap() + HeapIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | Heap Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | Heap Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,26 +4,17 @@
|
|||||||
|
|
||||||
#include "../src/intervalheap.c"
|
#include "../src/intervalheap.c"
|
||||||
|
|
||||||
struct intervalheap_fval *ih_fval =
|
struct intervalheap_fval *ih_fval = &(struct intervalheap_fval){
|
||||||
&(struct intervalheap_fval){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct intervalheap_fval *ih_fval_counter =
|
|
||||||
&(struct intervalheap_fval){ .cmp = v_c_cmp,
|
|
||||||
.cpy = v_c_cpy,
|
|
||||||
.str = v_c_str,
|
|
||||||
.free = v_c_free,
|
|
||||||
.hash = v_c_hash,
|
|
||||||
.pri = v_c_pri };
|
|
||||||
|
|
||||||
struct cmc_alloc_node *ih_alloc_node = &(struct cmc_alloc_node){
|
|
||||||
.malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct intervalheap_fval *ih_fval_counter = &(struct intervalheap_fval){
|
||||||
|
.cmp = v_c_cmp, .cpy = v_c_cpy, .str = v_c_str, .free = v_c_free, .hash = v_c_hash, .pri = v_c_pri
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmc_alloc_node *ih_alloc_node =
|
||||||
|
&(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free };
|
||||||
|
|
||||||
CMC_CREATE_UNIT(IntervalHeap, true, {
|
CMC_CREATE_UNIT(IntervalHeap, true, {
|
||||||
CMC_CREATE_TEST(PFX##_new(), {
|
CMC_CREATE_TEST(PFX##_new(), {
|
||||||
struct intervalheap *ih = ih_new(1000000, ih_fval);
|
struct intervalheap *ih = ih_new(1000000, ih_fval);
|
||||||
@@ -72,8 +63,7 @@ CMC_CREATE_UNIT(IntervalHeap, true, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
CMC_CREATE_TEST(PFX##_new_custom(), {
|
CMC_CREATE_TEST(PFX##_new_custom(), {
|
||||||
struct intervalheap *ih =
|
struct intervalheap *ih = ih_new_custom(1000000, ih_fval, ih_alloc_node, callbacks);
|
||||||
ih_new_custom(1000000, ih_fval, ih_alloc_node, callbacks);
|
|
||||||
|
|
||||||
cmc_assert_not_equals(ptr, NULL, ih);
|
cmc_assert_not_equals(ptr, NULL, ih);
|
||||||
cmc_assert_not_equals(ptr, NULL, ih->buffer);
|
cmc_assert_not_equals(ptr, NULL, ih->buffer);
|
||||||
@@ -1044,13 +1034,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = IntervalHeap() + IntervalHeapIter();
|
int result = IntervalHeap() + IntervalHeapIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | IntervalHeap Suit : %-41s |\n",
|
printf(" | IntervalHeap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
result == 0 ? "PASSED" : "FAILED");
|
printf(" +---------------------------------------------------------------+");
|
||||||
printf(
|
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,13 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/linkedlist.c"
|
#include "../src/linkedlist.c"
|
||||||
|
|
||||||
struct linkedlist_fval *ll_fval =
|
struct linkedlist_fval *ll_fval = &(struct linkedlist_fval){
|
||||||
&(struct linkedlist_fval){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
};
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(LinkedList, true, {
|
CMC_CREATE_UNIT(LinkedList, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -804,12 +800,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = LinkedList() + LinkedListIter();
|
int result = LinkedList() + LinkedListIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | LinkedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | LinkedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+5
-10
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/list.c"
|
#include "../src/list.c"
|
||||||
|
|
||||||
struct list_fval *l_fval = &(struct list_fval){ .cmp = cmc_size_cmp,
|
struct list_fval *l_fval = &(struct list_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(List, true, {
|
CMC_CREATE_UNIT(List, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -1070,12 +1067,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = List() + ListIter();
|
int result = List() + ListIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | List Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | List Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+9
-18
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/queue.c"
|
#include "../src/queue.c"
|
||||||
|
|
||||||
struct queue_fval *q_fval = &(struct queue_fval){ .cmp = cmc_size_cmp,
|
struct queue_fval *q_fval = &(struct queue_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(Queue, true, {
|
CMC_CREATE_UNIT(Queue, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -78,8 +75,7 @@ CMC_CREATE_UNIT(Queue, true, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
for (size_t i = q->front, j = 0; j < q->count;
|
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
|
||||||
i = (i + 1) % q->capacity, j++)
|
|
||||||
sum += q->buffer[i];
|
sum += q->buffer[i];
|
||||||
|
|
||||||
cmc_assert_equals(size_t, 1200, q_count(q));
|
cmc_assert_equals(size_t, 1200, q_count(q));
|
||||||
@@ -112,8 +108,7 @@ CMC_CREATE_UNIT(Queue, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = q->front, j = 0; j < q->count;
|
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
|
||||||
i = (i + 1) % q->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += q->buffer[i];
|
sum += q->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -154,8 +149,7 @@ CMC_CREATE_UNIT(Queue, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = q->front, j = 0; j < q->count;
|
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
|
||||||
i = (i + 1) % q->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += q->buffer[i];
|
sum += q->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -326,8 +320,7 @@ CMC_CREATE_UNIT(Queue, true, {
|
|||||||
|
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for (size_t i = q->front, j = 0; j < q->count;
|
for (size_t i = q->front, j = 0; j < q->count; i = (i + 1) % q->capacity, j++)
|
||||||
i = (i + 1) % q->capacity, j++)
|
|
||||||
{
|
{
|
||||||
sum += q->buffer[i];
|
sum += q->buffer[i];
|
||||||
}
|
}
|
||||||
@@ -960,12 +953,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = Queue() + QueueIter();
|
int result = Queue() + QueueIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | Queue Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | Queue Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,13 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/sortedlist.c"
|
#include "../src/sortedlist.c"
|
||||||
|
|
||||||
struct sortedlist_fval *sl_fval =
|
struct sortedlist_fval *sl_fval = &(struct sortedlist_fval){
|
||||||
&(struct sortedlist_fval){ .cmp = cmc_size_cmp,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.cpy = NULL,
|
};
|
||||||
.str = cmc_size_str,
|
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(SortedList, true, {
|
CMC_CREATE_UNIT(SortedList, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -66,8 +62,7 @@ CMC_CREATE_UNIT(SortedList, true, {
|
|||||||
sl_sort(sl);
|
sl_sort(sl);
|
||||||
|
|
||||||
cmc_assert_equals(size_t, 50, sl_count(sl));
|
cmc_assert_equals(size_t, 50, sl_count(sl));
|
||||||
cmc_assert_array_sorted_any(size_t, sl->buffer, cmc_size_cmp, 0,
|
cmc_assert_array_sorted_any(size_t, sl->buffer, cmc_size_cmp, 0, sl->count - 1);
|
||||||
sl->count - 1);
|
|
||||||
|
|
||||||
sl_free(sl);
|
sl_free(sl);
|
||||||
});
|
});
|
||||||
@@ -705,12 +700,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = SortedList() + SortedListIter();
|
int result = SortedList() + SortedListIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | SortedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | SortedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+5
-10
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/stack.c"
|
#include "../src/stack.c"
|
||||||
|
|
||||||
struct stack_fval *s_fval = &(struct stack_fval){ .cmp = cmc_size_cmp,
|
struct stack_fval *s_fval = &(struct stack_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(Stack, true, {
|
CMC_CREATE_UNIT(Stack, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -838,12 +835,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = Stack() + StackIter();
|
int result = Stack() + StackIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | Stack Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | Stack Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,19 +4,13 @@
|
|||||||
|
|
||||||
#include "../src/treemap.c"
|
#include "../src/treemap.c"
|
||||||
|
|
||||||
struct treemap_fkey *tm_fkey = &(struct treemap_fkey){ .cmp = cmc_size_cmp,
|
struct treemap_fkey *tm_fkey = &(struct treemap_fkey){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
struct treemap_fval *tm_fval = &(struct treemap_fval){ .cmp = cmc_size_cmp,
|
struct treemap_fval *tm_fval = &(struct treemap_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(TreeMap, true, {
|
CMC_CREATE_UNIT(TreeMap, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -659,12 +653,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = TreeMap() + TreeMapIter();
|
int result = TreeMap() + TreeMapIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | TreeMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | TreeMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
#include "../src/treeset.c"
|
#include "../src/treeset.c"
|
||||||
|
|
||||||
struct treeset_fval *ts_fval = &(struct treeset_fval){ .cmp = cmc_size_cmp,
|
struct treeset_fval *ts_fval = &(struct treeset_fval){
|
||||||
.cpy = NULL,
|
.cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp
|
||||||
.str = cmc_size_str,
|
};
|
||||||
.free = NULL,
|
|
||||||
.hash = cmc_size_hash,
|
|
||||||
.pri = cmc_size_cmp };
|
|
||||||
|
|
||||||
CMC_CREATE_UNIT(TreeSet, true, {
|
CMC_CREATE_UNIT(TreeSet, true, {
|
||||||
CMC_CREATE_TEST(new, {
|
CMC_CREATE_TEST(new, {
|
||||||
@@ -574,12 +571,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int result = TreeSet() + TreeSetIter();
|
int result = TreeSet() + TreeSetIter();
|
||||||
|
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" | TreeSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
printf(" | TreeSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED");
|
||||||
printf(
|
printf(" +---------------------------------------------------------------+");
|
||||||
" +---------------------------------------------------------------+");
|
|
||||||
printf("\n\n\n");
|
printf("\n\n\n");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+5
-15
@@ -2,15 +2,6 @@
|
|||||||
#ifndef CMC_UNIT_TEST_UTL__
|
#ifndef CMC_UNIT_TEST_UTL__
|
||||||
#define CMC_UNIT_TEST_UTL__
|
#define CMC_UNIT_TEST_UTL__
|
||||||
|
|
||||||
/**
|
|
||||||
* TEMPORARY
|
|
||||||
*/
|
|
||||||
struct cmc_string
|
|
||||||
{
|
|
||||||
char s[400];
|
|
||||||
};
|
|
||||||
static const size_t cmc_string_len = 400;
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -163,11 +154,10 @@ void callback_resize(void)
|
|||||||
total_resize++;
|
total_resize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmc_callbacks *callbacks =
|
struct cmc_callbacks *callbacks = &(struct cmc_callbacks){ .create = callback_create,
|
||||||
&(struct cmc_callbacks){ .create = callback_create,
|
.read = callback_read,
|
||||||
.read = callback_read,
|
.update = callback_update,
|
||||||
.update = callback_update,
|
.delete = callback_delete,
|
||||||
.delete = callback_delete,
|
.resize = callback_resize };
|
||||||
.resize = callback_resize };
|
|
||||||
|
|
||||||
#endif /* CMC_UNIT_TEST_UTL__ */
|
#endif /* CMC_UNIT_TEST_UTL__ */
|
||||||
Reference in new issue
Block a user