diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-05-07 11:57:07 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-05-07 11:57:07 -0600 |
commit | 9adb64786e6aa8f5f0fca39a67e96c495058fd1e (patch) | |
tree | afb42b751972e2a806d717c8ba1eae1554785859 | |
parent | adb8a2cd0d7bf835f987fa6a6202545cb7336956 (diff) | |
download | dimension-9adb64786e6aa8f5f0fca39a67e96c495058fd1e.tar.xz |
New dmnsn_array_from_list() function.
-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) { |