1 /* Abstract sequential list data type, with out-of-memory checking.
2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2009.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE,
22 _GL_ATTRIBUTE_RETURNS_NONNULL. */
23 #if !_GL_CONFIG_H_INCLUDED
24 #error "Please include config.h first."
30 _GL_INLINE_HEADER_BEGIN
31 #ifndef GL_XLIST_INLINE
32 # define GL_XLIST_INLINE _GL_INLINE
39 /* These functions are thin wrappers around the corresponding functions with
40 _nx_ infix from gl_list.h. Upon out-of-memory, they invoke xalloc_die (),
41 instead of returning an error indicator. */
42 #if 0 /* These are defined inline below. */
43 extern gl_list_t
gl_list_create_empty (gl_list_implementation_t implementation
,
44 gl_listelement_equals_fn equals_fn
,
45 gl_listelement_hashcode_fn hashcode_fn
,
46 gl_listelement_dispose_fn dispose_fn
,
47 bool allow_duplicates
)
48 /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
49 _GL_ATTRIBUTE_RETURNS_NONNULL
;
50 extern gl_list_t
gl_list_create (gl_list_implementation_t implementation
,
51 gl_listelement_equals_fn equals_fn
,
52 gl_listelement_hashcode_fn hashcode_fn
,
53 gl_listelement_dispose_fn dispose_fn
,
54 bool allow_duplicates
,
55 size_t count
, const void **contents
)
56 /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
57 _GL_ATTRIBUTE_RETURNS_NONNULL
;
58 extern void gl_list_node_set_value (gl_list_t list
, gl_list_node_t node
,
60 extern gl_list_node_t
gl_list_set_at (gl_list_t list
, size_t position
,
62 extern gl_list_node_t
gl_list_set_first (gl_list_t list
, const void *elt
);
63 extern gl_list_node_t
gl_list_set_last (gl_list_t list
, const void *elt
);
64 extern gl_list_node_t
gl_list_add_first (gl_list_t list
, const void *elt
);
65 extern gl_list_node_t
gl_list_add_last (gl_list_t list
, const void *elt
);
66 extern gl_list_node_t
gl_list_add_before (gl_list_t list
, gl_list_node_t node
,
68 extern gl_list_node_t
gl_list_add_after (gl_list_t list
, gl_list_node_t node
,
70 extern gl_list_node_t
gl_list_add_at (gl_list_t list
, size_t position
,
72 extern gl_list_node_t
gl_sortedlist_add (gl_list_t list
,
73 gl_listelement_compar_fn compar
,
78 /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
79 _GL_ATTRIBUTE_RETURNS_NONNULL
81 gl_list_create_empty (gl_list_implementation_t implementation
,
82 gl_listelement_equals_fn equals_fn
,
83 gl_listelement_hashcode_fn hashcode_fn
,
84 gl_listelement_dispose_fn dispose_fn
,
85 bool allow_duplicates
)
88 gl_list_nx_create_empty (implementation
, equals_fn
, hashcode_fn
, dispose_fn
,
96 /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
97 _GL_ATTRIBUTE_RETURNS_NONNULL
99 gl_list_create (gl_list_implementation_t implementation
,
100 gl_listelement_equals_fn equals_fn
,
101 gl_listelement_hashcode_fn hashcode_fn
,
102 gl_listelement_dispose_fn dispose_fn
,
103 bool allow_duplicates
,
104 size_t count
, const void **contents
)
107 gl_list_nx_create (implementation
, equals_fn
, hashcode_fn
, dispose_fn
,
108 allow_duplicates
, count
, contents
);
115 gl_list_node_set_value (gl_list_t list
, gl_list_node_t node
, const void *elt
)
117 int result
= gl_list_node_nx_set_value (list
, node
, elt
);
122 GL_XLIST_INLINE gl_list_node_t
123 gl_list_set_at (gl_list_t list
, size_t position
, const void *elt
)
125 gl_list_node_t result
= gl_list_nx_set_at (list
, position
, elt
);
131 GL_XLIST_INLINE gl_list_node_t
132 gl_list_set_first (gl_list_t list
, const void *elt
)
134 gl_list_node_t result
= gl_list_nx_set_first (list
, elt
);
140 GL_XLIST_INLINE gl_list_node_t
141 gl_list_set_last (gl_list_t list
, const void *elt
)
143 gl_list_node_t result
= gl_list_nx_set_last (list
, elt
);
149 GL_XLIST_INLINE gl_list_node_t
150 gl_list_add_first (gl_list_t list
, const void *elt
)
152 gl_list_node_t result
= gl_list_nx_add_first (list
, elt
);
158 GL_XLIST_INLINE gl_list_node_t
159 gl_list_add_last (gl_list_t list
, const void *elt
)
161 gl_list_node_t result
= gl_list_nx_add_last (list
, elt
);
167 GL_XLIST_INLINE gl_list_node_t
168 gl_list_add_before (gl_list_t list
, gl_list_node_t node
, const void *elt
)
170 gl_list_node_t result
= gl_list_nx_add_before (list
, node
, elt
);
176 GL_XLIST_INLINE gl_list_node_t
177 gl_list_add_after (gl_list_t list
, gl_list_node_t node
, const void *elt
)
179 gl_list_node_t result
= gl_list_nx_add_after (list
, node
, elt
);
185 GL_XLIST_INLINE gl_list_node_t
186 gl_list_add_at (gl_list_t list
, size_t position
, const void *elt
)
188 gl_list_node_t result
= gl_list_nx_add_at (list
, position
, elt
);
194 GL_XLIST_INLINE gl_list_node_t
195 gl_sortedlist_add (gl_list_t list
, gl_listelement_compar_fn compar
,
198 gl_list_node_t result
= gl_sortedlist_nx_add (list
, compar
, elt
);
208 _GL_INLINE_HEADER_END
210 #endif /* _GL_XLIST_H */