annotate lib/gl_sublist.c @ 15727:144db791c6fa

Ensure EBADF returns for socket functions on mingw. * lib/accept.c (rpl_accept): Fail with error EBADF if the file descriptor is invalid. * lib/bind.c (rpl_bind): Likewise. * lib/connect.c (rpl_connect): Likewise. * lib/getpeername.c (rpl_getpeername): Likewise. * lib/getsockname.c (rpl_getsockname): Likewise. * lib/getsockopt.c (rpl_getsockopt): Likewise. * lib/listen.c (rpl_listen): Likewise. * lib/recv.c (rpl_recv): Likewise. * lib/recvfrom.c (rpl_recvfrom): Likewise. * lib/send.c (rpl_send): Likewise. * lib/sendto.c (rpl_sendto): Likewise. * lib/setsockopt.c (rpl_setsockopt): Likewise. * lib/shutdown.c (rpl_shutdown): Likewise.
author Bruno Haible <bruno@clisp.org>
date Wed, 21 Sep 2011 00:20:59 +0200
parents 97fc9a21a8fb
children 8250f2777afc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Sequential list data type backed by another list.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12559
diff changeset
2 Copyright (C) 2006-2011 Free Software Foundation, Inc.
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8438
diff changeset
5 This program is free software: you can redistribute it and/or modify
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8438
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8438
diff changeset
8 (at your option) any later version.
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8438
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "gl_sublist.h"
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdlib.h>
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #ifndef uintptr_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 # define uintptr_t unsigned long
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #endif
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 /* -------------------------- gl_list_t Data Type -------------------------- */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Concrete gl_list_impl type, valid for this file only. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 struct gl_list_impl
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 struct gl_list_impl_base base;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 /* Reference to the whole list. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 gl_list_t whole;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* Limits of the index range. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 size_t start;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 size_t end;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 };
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* struct gl_list_node_impl doesn't exist here. The pointers are actually
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 indices + 1. (We don't use the whole list's gl_list_node_t implementation,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 because gl_sublist_next_node and gl_sublist_previous_node would not be easy
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 to implement with this choice.) */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #define INDEX_TO_NODE(index) (gl_list_node_t)(uintptr_t)(size_t)((index) + 1)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #define NODE_TO_INDEX(node) ((uintptr_t)(node) - 1)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 static gl_list_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
50 gl_sublist_nx_create_empty (gl_list_implementation_t implementation,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
51 gl_listelement_equals_fn equals_fn,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
52 gl_listelement_hashcode_fn hashcode_fn,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
53 gl_listelement_dispose_fn dispose_fn,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
54 bool allow_duplicates)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 /* Shouldn't be called. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 static gl_list_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
61 gl_sublist_nx_create_fill (gl_list_implementation_t implementation,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
62 gl_listelement_equals_fn equals_fn,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
63 gl_listelement_hashcode_fn hashcode_fn,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
64 gl_listelement_dispose_fn dispose_fn,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
65 bool allow_duplicates,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
66 size_t count, const void **contents)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 /* Shouldn't be called. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 static size_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 gl_sublist_size (gl_list_t list)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 return list->end - list->start;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 static const void *
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 gl_sublist_node_value (gl_list_t list, gl_list_node_t node)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 uintptr_t index = NODE_TO_INDEX (node);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 if (!(index < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 return gl_list_get_at (list->whole, list->start + index);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
88 static int
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
89 gl_sublist_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
9686
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
90 {
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
91 uintptr_t index = NODE_TO_INDEX (node);
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
92 if (!(index < list->end - list->start))
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
93 /* Invalid argument. */
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
94 abort ();
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
95 if (gl_list_nx_set_at (list->whole, list->start + index, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
96 return -1;
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
97 return 0;
9686
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
98 }
25f7280c9cf0 New abstract list operation 'node_set_value'.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
99
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 static gl_list_node_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 gl_sublist_next_node (gl_list_t list, gl_list_node_t node)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 uintptr_t index = NODE_TO_INDEX (node);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 size_t count = list->end - list->start;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 if (!(index < count))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 index++;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 if (index < count)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 return INDEX_TO_NODE (index);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 return NULL;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 static gl_list_node_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 gl_sublist_previous_node (gl_list_t list, gl_list_node_t node)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 uintptr_t index = NODE_TO_INDEX (node);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 if (!(index < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 if (index > 0)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 return INDEX_TO_NODE (index - 1);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 return NULL;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 static const void *
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 gl_sublist_get_at (gl_list_t list, size_t position)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 if (!(position < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 return gl_list_get_at (list->whole, list->start + position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
138 gl_sublist_nx_set_at (gl_list_t list, size_t position, const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 if (!(position < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 abort ();
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
143 if (gl_list_nx_set_at (list->whole, list->start + position, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
144 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 return INDEX_TO_NODE (position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 static gl_list_node_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 gl_sublist_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
150 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 if (!(start_index <= end_index && end_index <= list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 /* Invalid arguments. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 size_t index =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 gl_list_indexof_from_to (list->whole,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
158 list->start + start_index,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
159 list->start + end_index,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
160 elt);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 if (index != (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 return INDEX_TO_NODE (index - list->start);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 return NULL;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 static size_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 gl_sublist_indexof_from_to (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
170 size_t start_index, size_t end_index,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
171 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 if (!(start_index <= end_index && end_index <= list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 /* Invalid arguments. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 size_t index =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 gl_list_indexof_from_to (list->whole,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
179 list->start + start_index,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
180 list->start + end_index,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
181 elt);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 if (index != (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 index -= list->start;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 return index;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
189 gl_sublist_nx_add_first (gl_list_t list, const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 {
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
191 if (gl_list_nx_add_at (list->whole, list->start, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
192 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 list->end++;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 return INDEX_TO_NODE (0);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
198 gl_sublist_nx_add_last (gl_list_t list, const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 {
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
200 if (gl_list_nx_add_at (list->whole, list->end, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
201 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 list->end++;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 return INDEX_TO_NODE (list->end - list->start - 1);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
207 gl_sublist_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 size_t position = NODE_TO_INDEX (node);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 if (!(position < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 abort ();
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
213 if (gl_list_nx_add_at (list->whole, list->start + position, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
214 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 list->end++;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 return INDEX_TO_NODE (position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
220 gl_sublist_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 size_t position = NODE_TO_INDEX (node);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 if (!(position < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 position++;
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
227 if (gl_list_nx_add_at (list->whole, list->start + position, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
228 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 list->end++;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 return INDEX_TO_NODE (position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
234 gl_sublist_nx_add_at (gl_list_t list, size_t position, const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 if (!(position <= list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 abort ();
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
239 if (gl_list_nx_add_at (list->whole, list->start + position, elt) == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
240 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 list->end++;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 return INDEX_TO_NODE (position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 static bool
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 gl_sublist_remove_node (gl_list_t list, gl_list_node_t node)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 uintptr_t index = NODE_TO_INDEX (node);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 if (!(index < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 return gl_list_remove_at (list->whole, list->start + index);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 static bool
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 gl_sublist_remove_at (gl_list_t list, size_t position)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 if (!(position < list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 /* Invalid argument. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 return gl_list_remove_at (list->whole, list->start + position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 static bool
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 gl_sublist_remove (gl_list_t list, const void *elt)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 size_t position =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 gl_list_indexof_from_to (list->whole, list->start, list->end, elt);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 if (position == (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 return false;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 return gl_list_remove_at (list->whole, position);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 static void
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 gl_sublist_list_free (gl_list_t list)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 free (list);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 /* --------------------- gl_list_iterator_t Data Type --------------------- */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 static gl_list_iterator_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 gl_sublist_iterator (gl_list_t list)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 return gl_list_iterator_from_to (list->whole, list->start, list->end);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 static gl_list_iterator_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 gl_sublist_iterator_from_to (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
291 size_t start_index, size_t end_index)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 if (!(start_index <= end_index && end_index <= list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 /* Invalid arguments. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 return gl_list_iterator_from_to (list->whole,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
297 list->start + start_index,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
298 list->start + end_index);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 static bool
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 gl_sublist_iterator_next (gl_list_iterator_t *iterator,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
303 const void **eltp, gl_list_node_t *nodep)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 /* Shouldn't be called. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 static void
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 gl_sublist_iterator_free (gl_list_iterator_t *iterator)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 /* Shouldn't be called. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 /* ---------------------- Sorted gl_list_t Data Type ---------------------- */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 static gl_list_node_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 gl_sublist_sortedlist_search (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
320 gl_listelement_compar_fn compar,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
321 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 size_t index =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 gl_sortedlist_indexof_from_to (list->whole, compar,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
325 list->start, list->end, elt);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 if (index != (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 return INDEX_TO_NODE (index - list->start);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 return NULL;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 static gl_list_node_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 gl_sublist_sortedlist_search_from_to (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
334 gl_listelement_compar_fn compar,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
335 size_t low, size_t high,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
336 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 size_t index;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 if (!(low <= high && high <= list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 /* Invalid arguments. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 index =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 gl_sortedlist_indexof_from_to (list->whole, compar,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
346 list->start + low, list->start + high, elt);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 if (index != (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 return INDEX_TO_NODE (index - list->start);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 return NULL;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 static size_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 gl_sublist_sortedlist_indexof (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
355 gl_listelement_compar_fn compar,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
356 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 size_t index =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 gl_sortedlist_indexof_from_to (list->whole, compar, list->start, list->end,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
360 elt);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 if (index != (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 index -= list->start;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 return index;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 static size_t
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 gl_sublist_sortedlist_indexof_from_to (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
368 gl_listelement_compar_fn compar,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
369 size_t low, size_t high,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
370 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 size_t index;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 if (!(low <= high && high <= list->end - list->start))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 /* Invalid arguments. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 index = gl_sortedlist_indexof_from_to (list->whole, compar,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
379 list->start + low, list->start + high,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
380 elt);
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 if (index != (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 index -= list->start;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 return index;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 static gl_list_node_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
387 gl_sublist_sortedlist_nx_add (gl_list_t list,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
388 gl_listelement_compar_fn compar,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
389 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 /* It's impossible to implement this method without risking to put the
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 whole list into unsorted order (namely, when the given ELT is smaller
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 or larger than all elements of the sublist). */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 static bool
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 gl_sublist_sortedlist_remove (gl_list_t list,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
399 gl_listelement_compar_fn compar,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
400 const void *elt)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 size_t index = gl_sublist_sortedlist_indexof (list, compar, elt);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 if (index == (size_t)(-1))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 return false;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 return gl_sublist_remove_at (list, index);
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 static const struct gl_list_implementation gl_sublist_list_implementation =
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 {
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
412 gl_sublist_nx_create_empty,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
413 gl_sublist_nx_create_fill,
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 gl_sublist_size,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 gl_sublist_node_value,
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
416 gl_sublist_node_nx_set_value,
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 gl_sublist_next_node,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 gl_sublist_previous_node,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 gl_sublist_get_at,
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
420 gl_sublist_nx_set_at,
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 gl_sublist_search_from_to,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 gl_sublist_indexof_from_to,
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
423 gl_sublist_nx_add_first,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
424 gl_sublist_nx_add_last,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
425 gl_sublist_nx_add_before,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
426 gl_sublist_nx_add_after,
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
427 gl_sublist_nx_add_at,
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 gl_sublist_remove_node,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 gl_sublist_remove_at,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 gl_sublist_remove,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 gl_sublist_list_free,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 gl_sublist_iterator,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 gl_sublist_iterator_from_to,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 gl_sublist_iterator_next,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 gl_sublist_iterator_free,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 gl_sublist_sortedlist_search,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 gl_sublist_sortedlist_search_from_to,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 gl_sublist_sortedlist_indexof,
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 gl_sublist_sortedlist_indexof_from_to,
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
440 gl_sublist_sortedlist_nx_add,
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 gl_sublist_sortedlist_remove
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 };
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 gl_list_t
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
445 gl_sublist_nx_create (gl_list_t whole_list, size_t start_index, size_t end_index)
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 {
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 if (!(start_index <= end_index && end_index <= gl_list_size (whole_list)))
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448 /* Invalid arguments. */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 abort ();
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 {
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
451 struct gl_list_impl *list =
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
452 (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
453
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
454 if (list == NULL)
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
455 return NULL;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457 list->base.vtable = &gl_sublist_list_implementation;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 list->base.equals_fn = whole_list->base.equals_fn; /* actually unused */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 list->base.hashcode_fn = whole_list->base.hashcode_fn; /* actually unused */
8438
238942284e2f Allow the use of a destructor for the values stored in the list.
Bruno Haible <bruno@clisp.org>
parents: 7603
diff changeset
460 list->base.dispose_fn = whole_list->base.dispose_fn; /* actually unused */
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 list->base.allow_duplicates = whole_list->base.allow_duplicates; /* unused */
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 if (whole_list->base.vtable == &gl_sublist_list_implementation)
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
464 /* Optimization of a sublist of a sublist: Collapse the two
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
465 indirections into a single indirection. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
466 list->whole = whole_list->whole;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
467 list->start = whole_list->start + start_index;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
468 list->end = whole_list->start + end_index;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 else
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
472 list->whole = whole_list;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
473 list->start = start_index;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9686
diff changeset
474 list->end = end_index;
7420
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 return list;
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 }
52a8ff5ade8a New module 'sublist'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
479 }