diff options
author | Bruno Haible <bruno@clisp.org> | 2021-04-03 17:59:47 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-04-03 18:30:45 +0200 |
commit | e108960209b3c13c2d43d745c0898c8778bff186 (patch) | |
tree | 083f3b6cdf6d8016fe6adc804e52de992317cd6c /lib/gl_carray_list.c | |
parent | b7a807df4473a3d9210aff24a3bcff2479c688a9 (diff) | |
download | gnulib-e108960209b3c13c2d43d745c0898c8778bff186.tar.gz |
list: Add operations first_node, last_node.
Reported by Marc Nieper-Wißkirchen in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-04/msg00005.html>.
* lib/gl_list.h (gl_list_first_node, gl_list_last_node): New functions.
(struct gl_list_implementation): Add members first_node, last_node.
* lib/gl_array_list.c (gl_array_first_node, gl_array_last_node): New
functions.
(gl_array_list_implementation): Add the new operations.
* lib/gl_carray_list.c (gl_carray_first_node, gl_carray_last_node): New
functions.
(gl_carray_list_implementation): Add the new operations.
* lib/gl_anylinked_list2.h (gl_linked_first_node, gl_linked_last_node):
New functions.
* lib/gl_linked_list.c (gl_linked_list_implementation): Add the new
operations.
* lib/gl_linkedhash_list.c (gl_linkedhash_list_implementation):
Likewise.
* lib/gl_anytree_list2.h (gl_tree_first_node, gl_tree_last_node): New
functions.
* lib/gl_avltree_list.c (gl_avltree_list_implementation): Add the new
operations.
* lib/gl_avltreehash_list.c (gl_avltreehash_list_implementation):
Likewise.
* lib/gl_rbtree_list.c (gl_rbtree_list_implementation): Likewise.
* lib/gl_rbtreehash_list.c (gl_rbtreehash_list_implementation):
Likewise.
* lib/gl_sublist.c (gl_sublist_first_node, gl_sublist_last_node): New
functions.
(gl_sublist_list_implementation): Add the new operations.
* lib/gl_list.hh (class gl_List): Add member functions first_node,
last_node.
* doc/containers.texi: Update table.
Diffstat (limited to 'lib/gl_carray_list.c')
-rw-r--r-- | lib/gl_carray_list.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/gl_carray_list.c b/lib/gl_carray_list.c index a50f093240..add4cc3c8d 100644 --- a/lib/gl_carray_list.c +++ b/lib/gl_carray_list.c @@ -181,6 +181,24 @@ gl_carray_previous_node (gl_list_t list, gl_list_node_t node) return NULL; } +static gl_list_node_t _GL_ATTRIBUTE_PURE +gl_carray_first_node (gl_list_t list) +{ + if (list->count > 0) + return INDEX_TO_NODE (0); + else + return NULL; +} + +static gl_list_node_t _GL_ATTRIBUTE_PURE +gl_carray_last_node (gl_list_t list) +{ + if (list->count > 0) + return INDEX_TO_NODE (list->count - 1); + else + return NULL; +} + static const void * _GL_ATTRIBUTE_PURE gl_carray_get_at (gl_list_t list, size_t position) { @@ -844,6 +862,8 @@ const struct gl_list_implementation gl_carray_list_implementation = gl_carray_node_nx_set_value, gl_carray_next_node, gl_carray_previous_node, + gl_carray_first_node, + gl_carray_last_node, gl_carray_get_at, gl_carray_nx_set_at, gl_carray_search_from_to, |