diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/list.h | 16 | ||||
-rw-r--r-- | libdimension/list.c | 15 |
2 files changed, 24 insertions, 7 deletions
diff --git a/libdimension/dimension/list.h b/libdimension/dimension/list.h index 0b68e91..ae2aab5 100644 --- a/libdimension/dimension/list.h +++ b/libdimension/dimension/list.h @@ -76,39 +76,41 @@ dmnsn_new_list(size_t obj_size) return list; } -/* Construction from arrays */ -dmnsn_list *dmnsn_list_from_array(const dmnsn_array *array); +/* Construction to/from arrays */ +dmnsn_list *dmnsn_list_from_array(const dmnsn_array *array); +dmnsn_array *dmnsn_array_from_list(const dmnsn_list *list); + /* Delete a list */ void dmnsn_delete_list(dmnsn_list *list); DMNSN_INLINE dmnsn_list_iterator * -dmnsn_list_first(dmnsn_list *list) +dmnsn_list_first(const dmnsn_list *list) { return list->first; } DMNSN_INLINE dmnsn_list_iterator * -dmnsn_list_last(dmnsn_list *list) +dmnsn_list_last(const dmnsn_list *list) { return list->last; } DMNSN_INLINE dmnsn_list_iterator * -dmnsn_list_prev(dmnsn_list_iterator *i) +dmnsn_list_prev(const dmnsn_list_iterator *i) { dmnsn_assert(i, "NULL list iterator."); return i->prev; } DMNSN_INLINE dmnsn_list_iterator * -dmnsn_list_next(dmnsn_list_iterator *i) +dmnsn_list_next(const dmnsn_list_iterator *i) { dmnsn_assert(i, "NULL list iterator."); return i->next; } DMNSN_INLINE size_t -dmnsn_list_size(dmnsn_list *list) +dmnsn_list_size(const dmnsn_list *list) { return list->length; } diff --git a/libdimension/list.c b/libdimension/list.c index 5b03209..0c01e68 100644 --- a/libdimension/list.c +++ b/libdimension/list.c @@ -32,6 +32,21 @@ dmnsn_list_from_array(const dmnsn_array *array) return list; } +dmnsn_array * +dmnsn_array_from_list(const dmnsn_list *list) +{ + dmnsn_array *array = dmnsn_new_array(list->obj_size); + + for (dmnsn_list_iterator *i = dmnsn_list_first(list); + i != NULL; + i = dmnsn_list_next(i)) + { + dmnsn_array_push(array, i->ptr); + } + + return array; +} + void dmnsn_delete_list(dmnsn_list *list) { |