Updating sortedlist iterators
This commit is contained in:
1 parent
7fa41df65a
commit
360e08b6b3
4 files changed
+456
-114
No files matched your search
+38
-62
@@ -83,12 +83,6 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
/* Custom callback functions */ \
|
||||
struct cmc_callbacks *callbacks; \
|
||||
\
|
||||
/* Function that returns an iterator to the start of the list */ \
|
||||
struct SNAME##_iter (*it_start)(struct SNAME *); \
|
||||
\
|
||||
/* Function that returns an iterator to the end of the list */ \
|
||||
struct SNAME##_iter (*it_end)(struct SNAME *); \
|
||||
}; \
|
||||
\
|
||||
/* Value struct function table */ \
|
||||
@@ -164,17 +158,15 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
bool PFX##_print(struct SNAME *_list_, FILE *fptr); \
|
||||
\
|
||||
/* Iterator Functions */ \
|
||||
/* Iterator Allocation and Deallocation */ \
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target); \
|
||||
void PFX##_iter_free(struct SNAME##_iter *iter); \
|
||||
/* Iterator Initialization */ \
|
||||
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target); \
|
||||
struct SNAME##_iter PFX##_iter_start(struct SNAME *target); \
|
||||
struct SNAME##_iter PFX##_iter_end(struct SNAME *target); \
|
||||
/* Iterator State */ \
|
||||
bool PFX##_iter_start(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_end(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_at_start(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_at_end(struct SNAME##_iter *iter); \
|
||||
/* Iterator Movement */ \
|
||||
void PFX##_iter_to_start(struct SNAME##_iter *iter); \
|
||||
void PFX##_iter_to_end(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_to_start(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_to_end(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_next(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_prev(struct SNAME##_iter *iter); \
|
||||
bool PFX##_iter_advance(struct SNAME##_iter *iter, size_t steps); \
|
||||
@@ -198,8 +190,6 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
size_t high); \
|
||||
void PFX##_impl_sort_insertion(V *array, int (*cmp)(V, V), size_t low, \
|
||||
size_t high); \
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_); \
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_); \
|
||||
\
|
||||
struct SNAME *PFX##_new(size_t capacity, struct SNAME##_fval *f_val) \
|
||||
{ \
|
||||
@@ -231,8 +221,6 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
_list_->f_val = f_val; \
|
||||
_list_->alloc = alloc; \
|
||||
_list_->callbacks = NULL; \
|
||||
_list_->it_start = PFX##_impl_it_start; \
|
||||
_list_->it_end = PFX##_impl_it_end; \
|
||||
\
|
||||
return _list_; \
|
||||
} \
|
||||
@@ -267,8 +255,6 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
_list_->f_val = f_val; \
|
||||
_list_->alloc = alloc; \
|
||||
_list_->callbacks = callbacks; \
|
||||
_list_->it_start = PFX##_impl_it_start; \
|
||||
_list_->it_end = PFX##_impl_it_end; \
|
||||
\
|
||||
return _list_; \
|
||||
} \
|
||||
@@ -594,63 +580,73 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target) \
|
||||
struct SNAME##_iter PFX##_iter_start(struct SNAME *target) \
|
||||
{ \
|
||||
struct SNAME##_iter *iter = \
|
||||
target->alloc->malloc(sizeof(struct SNAME##_iter)); \
|
||||
PFX##_sort(target); \
|
||||
\
|
||||
if (!iter) \
|
||||
return NULL; \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
PFX##_iter_init(iter, target); \
|
||||
iter.target = target; \
|
||||
iter.cursor = 0; \
|
||||
iter.start = true; \
|
||||
iter.end = PFX##_empty(target); \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_free(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
iter->target->alloc->free(iter); \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_init(struct SNAME##_iter *iter, struct SNAME *target) \
|
||||
struct SNAME##_iter PFX##_iter_end(struct SNAME *target) \
|
||||
{ \
|
||||
PFX##_sort(target); \
|
||||
\
|
||||
iter->target = target; \
|
||||
iter->cursor = 0; \
|
||||
iter->start = true; \
|
||||
iter->end = PFX##_empty(target); \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
iter.target = target; \
|
||||
iter.cursor = 0; \
|
||||
iter.start = PFX##_empty(target); \
|
||||
iter.end = true; \
|
||||
\
|
||||
if (!PFX##_empty(target)) \
|
||||
iter.cursor = target->count - 1; \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_iter_start(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_at_start(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
return PFX##_empty(iter->target) || iter->start; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_iter_end(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_at_end(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
return PFX##_empty(iter->target) || iter->end; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_to_start(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_to_start(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
if (!PFX##_empty(iter->target)) \
|
||||
{ \
|
||||
iter->cursor = 0; \
|
||||
iter->start = true; \
|
||||
iter->end = PFX##_empty(iter->target); \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
void PFX##_iter_to_end(struct SNAME##_iter *iter) \
|
||||
bool PFX##_iter_to_end(struct SNAME##_iter *iter) \
|
||||
{ \
|
||||
if (!PFX##_empty(iter->target)) \
|
||||
{ \
|
||||
iter->start = PFX##_empty(iter->target); \
|
||||
iter->cursor = \
|
||||
PFX##_empty(iter->target) ? 0 : iter->target->count - 1; \
|
||||
iter->cursor = iter->target->count - 1; \
|
||||
iter->end = true; \
|
||||
\
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
bool PFX##_iter_next(struct SNAME##_iter *iter) \
|
||||
@@ -884,26 +880,6 @@ static const char *cmc_string_fmt_sortedlist = "struct %s<%s> "
|
||||
\
|
||||
array[j] = _tmp_; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static struct SNAME##_iter PFX##_impl_it_start(struct SNAME *_list_) \
|
||||
{ \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
PFX##_iter_init(&iter, _list_); \
|
||||
PFX##_iter_to_start(&iter); \
|
||||
\
|
||||
return iter; \
|
||||
} \
|
||||
\
|
||||
static struct SNAME##_iter PFX##_impl_it_end(struct SNAME *_list_) \
|
||||
{ \
|
||||
struct SNAME##_iter iter; \
|
||||
\
|
||||
PFX##_iter_init(&iter, _list_); \
|
||||
PFX##_iter_to_end(&iter); \
|
||||
\
|
||||
return iter; \
|
||||
}
|
||||
|
||||
#endif /* CMC_SORTEDLIST_H */
|
||||
Reference in new issue
Block a user