PostgreSQL Source Code  git master
pg_list.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_list.h
4  * interface for PostgreSQL generic list package
5  *
6  * Once upon a time, parts of Postgres were written in Lisp and used real
7  * cons-cell lists for major data structures. When that code was rewritten
8  * in C, we initially had a faithful emulation of cons-cell lists, which
9  * unsurprisingly was a performance bottleneck. A couple of major rewrites
10  * later, these data structures are actually simple expansible arrays;
11  * but the "List" name and a lot of the notation survives.
12  *
13  * One important concession to the original implementation is that an empty
14  * list is always represented by a null pointer (preferentially written NIL).
15  * Non-empty lists have a header, which will not be relocated as long as the
16  * list remains non-empty, and an expansible data array.
17  *
18  * We support three types of lists:
19  *
20  * T_List: lists of pointers
21  * (in practice usually pointers to Nodes, but not always;
22  * declared as "void *" to minimize casting annoyances)
23  * T_IntList: lists of integers
24  * T_OidList: lists of Oids
25  *
26  * (At the moment, ints and Oids are the same size, but they may not
27  * always be so; try to be careful to maintain the distinction.)
28  *
29  *
30  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
31  * Portions Copyright (c) 1994, Regents of the University of California
32  *
33  * src/include/nodes/pg_list.h
34  *
35  *-------------------------------------------------------------------------
36  */
37 #ifndef PG_LIST_H
38 #define PG_LIST_H
39 
40 #include "nodes/nodes.h"
41 
42 
43 typedef union ListCell
44 {
45  void *ptr_value;
46  int int_value;
48 } ListCell;
49 
50 typedef struct List
51 {
52  NodeTag type; /* T_List, T_IntList, or T_OidList */
53  int length; /* number of elements currently present */
54  int max_length; /* allocated length of elements[] */
55  ListCell *elements; /* re-allocatable array of cells */
56  /* We may allocate some cells along with the List header: */
57  ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER];
58  /* If elements == initial_elements, it's not a separate allocation */
59 } List;
60 
61 /*
62  * The *only* valid representation of an empty list is NIL; in other
63  * words, a non-NIL list is guaranteed to have length >= 1.
64  */
65 #define NIL ((List *) NULL)
66 
67 /*
68  * State structs for various looping macros below.
69  */
70 typedef struct ForEachState
71 {
72  const List *l; /* list we're looping through */
73  int i; /* current element index */
74 } ForEachState;
75 
76 typedef struct ForBothState
77 {
78  const List *l1; /* lists we're looping through */
79  const List *l2;
80  int i; /* common element index */
81 } ForBothState;
82 
83 typedef struct ForBothCellState
84 {
85  const List *l1; /* lists we're looping through */
86  const List *l2;
87  int i1; /* current element indexes */
88  int i2;
90 
91 typedef struct ForThreeState
92 {
93  const List *l1; /* lists we're looping through */
94  const List *l2;
95  const List *l3;
96  int i; /* common element index */
98 
99 typedef struct ForFourState
100 {
101  const List *l1; /* lists we're looping through */
102  const List *l2;
103  const List *l3;
104  const List *l4;
105  int i; /* common element index */
106 } ForFourState;
107 
108 typedef struct ForFiveState
109 {
110  const List *l1; /* lists we're looping through */
111  const List *l2;
112  const List *l3;
113  const List *l4;
114  const List *l5;
115  int i; /* common element index */
116 } ForFiveState;
117 
118 /*
119  * These routines are small enough, and used often enough, to justify being
120  * inline.
121  */
122 
123 /* Fetch address of list's first cell; NULL if empty list */
124 static inline ListCell *
125 list_head(const List *l)
126 {
127  return l ? &l->elements[0] : NULL;
128 }
129 
130 /* Fetch address of list's last cell; NULL if empty list */
131 static inline ListCell *
132 list_tail(const List *l)
133 {
134  return l ? &l->elements[l->length - 1] : NULL;
135 }
136 
137 /* Fetch address of list's second cell, if it has one, else NULL */
138 static inline ListCell *
140 {
141  if (l && l->length >= 2)
142  return &l->elements[1];
143  else
144  return NULL;
145 }
146 
147 /* Fetch list's length */
148 static inline int
149 list_length(const List *l)
150 {
151  return l ? l->length : 0;
152 }
153 
154 /*
155  * Macros to access the data values within List cells.
156  *
157  * Note that with the exception of the "xxx_node" macros, these are
158  * lvalues and can be assigned to.
159  *
160  * NB: There is an unfortunate legacy from a previous incarnation of
161  * the List API: the macro lfirst() was used to mean "the data in this
162  * cons cell". To avoid changing every usage of lfirst(), that meaning
163  * has been kept. As a result, lfirst() takes a ListCell and returns
164  * the data it contains; to get the data in the first cell of a
165  * List, use linitial(). Worse, lsecond() is more closely related to
166  * linitial() than lfirst(): given a List, lsecond() returns the data
167  * in the second list cell.
168  */
169 #define lfirst(lc) ((lc)->ptr_value)
170 #define lfirst_int(lc) ((lc)->int_value)
171 #define lfirst_oid(lc) ((lc)->oid_value)
172 #define lfirst_node(type,lc) castNode(type, lfirst(lc))
173 
174 #define linitial(l) lfirst(list_nth_cell(l, 0))
175 #define linitial_int(l) lfirst_int(list_nth_cell(l, 0))
176 #define linitial_oid(l) lfirst_oid(list_nth_cell(l, 0))
177 #define linitial_node(type,l) castNode(type, linitial(l))
178 
179 #define lsecond(l) lfirst(list_nth_cell(l, 1))
180 #define lsecond_int(l) lfirst_int(list_nth_cell(l, 1))
181 #define lsecond_oid(l) lfirst_oid(list_nth_cell(l, 1))
182 #define lsecond_node(type,l) castNode(type, lsecond(l))
183 
184 #define lthird(l) lfirst(list_nth_cell(l, 2))
185 #define lthird_int(l) lfirst_int(list_nth_cell(l, 2))
186 #define lthird_oid(l) lfirst_oid(list_nth_cell(l, 2))
187 #define lthird_node(type,l) castNode(type, lthird(l))
188 
189 #define lfourth(l) lfirst(list_nth_cell(l, 3))
190 #define lfourth_int(l) lfirst_int(list_nth_cell(l, 3))
191 #define lfourth_oid(l) lfirst_oid(list_nth_cell(l, 3))
192 #define lfourth_node(type,l) castNode(type, lfourth(l))
193 
194 #define llast(l) lfirst(list_last_cell(l))
195 #define llast_int(l) lfirst_int(list_last_cell(l))
196 #define llast_oid(l) lfirst_oid(list_last_cell(l))
197 #define llast_node(type,l) castNode(type, llast(l))
198 
199 /*
200  * Convenience macros for building fixed-length lists
201  */
202 #define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
203 #define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
204 #define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
205 
206 #define list_make1(x1) \
207  list_make1_impl(T_List, list_make_ptr_cell(x1))
208 #define list_make2(x1,x2) \
209  list_make2_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2))
210 #define list_make3(x1,x2,x3) \
211  list_make3_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2), \
212  list_make_ptr_cell(x3))
213 #define list_make4(x1,x2,x3,x4) \
214  list_make4_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2), \
215  list_make_ptr_cell(x3), list_make_ptr_cell(x4))
216 #define list_make5(x1,x2,x3,x4,x5) \
217  list_make5_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2), \
218  list_make_ptr_cell(x3), list_make_ptr_cell(x4), \
219  list_make_ptr_cell(x5))
220 
221 #define list_make1_int(x1) \
222  list_make1_impl(T_IntList, list_make_int_cell(x1))
223 #define list_make2_int(x1,x2) \
224  list_make2_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2))
225 #define list_make3_int(x1,x2,x3) \
226  list_make3_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2), \
227  list_make_int_cell(x3))
228 #define list_make4_int(x1,x2,x3,x4) \
229  list_make4_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2), \
230  list_make_int_cell(x3), list_make_int_cell(x4))
231 #define list_make5_int(x1,x2,x3,x4,x5) \
232  list_make5_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2), \
233  list_make_int_cell(x3), list_make_int_cell(x4), \
234  list_make_int_cell(x5))
235 
236 #define list_make1_oid(x1) \
237  list_make1_impl(T_OidList, list_make_oid_cell(x1))
238 #define list_make2_oid(x1,x2) \
239  list_make2_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2))
240 #define list_make3_oid(x1,x2,x3) \
241  list_make3_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2), \
242  list_make_oid_cell(x3))
243 #define list_make4_oid(x1,x2,x3,x4) \
244  list_make4_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2), \
245  list_make_oid_cell(x3), list_make_oid_cell(x4))
246 #define list_make5_oid(x1,x2,x3,x4,x5) \
247  list_make5_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2), \
248  list_make_oid_cell(x3), list_make_oid_cell(x4), \
249  list_make_oid_cell(x5))
250 
251 /*
252  * Locate the n'th cell (counting from 0) of the list.
253  * It is an assertion failure if there is no such cell.
254  */
255 static inline ListCell *
256 list_nth_cell(const List *list, int n)
257 {
258  Assert(list != NIL);
259  Assert(n >= 0 && n < list->length);
260  return &list->elements[n];
261 }
262 
263 /*
264  * Return the last cell in a non-NIL List.
265  */
266 static inline ListCell *
268 {
269  Assert(list != NIL);
270  return &list->elements[list->length - 1];
271 }
272 
273 /*
274  * Return the pointer value contained in the n'th element of the
275  * specified list. (List elements begin at 0.)
276  */
277 static inline void *
278 list_nth(const List *list, int n)
279 {
280  Assert(IsA(list, List));
281  return lfirst(list_nth_cell(list, n));
282 }
283 
284 /*
285  * Return the integer value contained in the n'th element of the
286  * specified list.
287  */
288 static inline int
289 list_nth_int(const List *list, int n)
290 {
291  Assert(IsA(list, IntList));
292  return lfirst_int(list_nth_cell(list, n));
293 }
294 
295 /*
296  * Return the OID value contained in the n'th element of the specified
297  * list.
298  */
299 static inline Oid
300 list_nth_oid(const List *list, int n)
301 {
302  Assert(IsA(list, OidList));
303  return lfirst_oid(list_nth_cell(list, n));
304 }
305 
306 #define list_nth_node(type,list,n) castNode(type, list_nth(list, n))
307 
308 /*
309  * Get the given ListCell's index (from 0) in the given List.
310  */
311 static inline int
312 list_cell_number(const List *l, const ListCell *c)
313 {
314  Assert(c >= &l->elements[0] && c < &l->elements[l->length]);
315  return c - l->elements;
316 }
317 
318 /*
319  * Get the address of the next cell after "c" within list "l", or NULL if none.
320  */
321 static inline ListCell *
322 lnext(const List *l, const ListCell *c)
323 {
324  Assert(c >= &l->elements[0] && c < &l->elements[l->length]);
325  c++;
326  if (c < &l->elements[l->length])
327  return (ListCell *) c;
328  else
329  return NULL;
330 }
331 
332 /*
333  * foreach -
334  * a convenience macro for looping through a list
335  *
336  * "cell" must be the name of a "ListCell *" variable; it's made to point
337  * to each List element in turn. "cell" will be NULL after normal exit from
338  * the loop, but an early "break" will leave it pointing at the current
339  * List element.
340  *
341  * Beware of changing the List object while the loop is iterating.
342  * The current semantics are that we examine successive list indices in
343  * each iteration, so that insertion or deletion of list elements could
344  * cause elements to be re-visited or skipped unexpectedly. Previous
345  * implementations of foreach() behaved differently. However, it's safe
346  * to append elements to the List (or in general, insert them after the
347  * current element); such new elements are guaranteed to be visited.
348  * Also, the current element of the List can be deleted, if you use
349  * foreach_delete_current() to do so. BUT: either of these actions will
350  * invalidate the "cell" pointer for the remainder of the current iteration.
351  */
352 #define foreach(cell, lst) \
353  for (ForEachState cell##__state = {(lst), 0}; \
354  (cell##__state.l != NIL && \
355  cell##__state.i < cell##__state.l->length) ? \
356  (cell = &cell##__state.l->elements[cell##__state.i], true) : \
357  (cell = NULL, false); \
358  cell##__state.i++)
359 
360 /*
361  * foreach_delete_current -
362  * delete the current list element from the List associated with a
363  * surrounding foreach() loop, returning the new List pointer.
364  *
365  * This is equivalent to list_delete_cell(), but it also adjusts the foreach
366  * loop's state so that no list elements will be missed. Do not delete
367  * elements from an active foreach loop's list in any other way!
368  */
369 #define foreach_delete_current(lst, cell) \
370  (cell##__state.i--, \
371  (List *) (cell##__state.l = list_delete_cell(lst, cell)))
372 
373 /*
374  * foreach_current_index -
375  * get the zero-based list index of a surrounding foreach() loop's
376  * current element; pass the name of the "ListCell *" iterator variable.
377  *
378  * Beware of using this after foreach_delete_current(); the value will be
379  * out of sync for the rest of the current loop iteration. Anyway, since
380  * you just deleted the current element, the value is pretty meaningless.
381  */
382 #define foreach_current_index(cell) (cell##__state.i)
383 
384 /*
385  * for_each_from -
386  * Like foreach(), but start from the N'th (zero-based) list element,
387  * not necessarily the first one.
388  *
389  * It's okay for N to exceed the list length, but not for it to be negative.
390  *
391  * The caveats for foreach() apply equally here.
392  */
393 #define for_each_from(cell, lst, N) \
394  for (ForEachState cell##__state = for_each_from_setup(lst, N); \
395  (cell##__state.l != NIL && \
396  cell##__state.i < cell##__state.l->length) ? \
397  (cell = &cell##__state.l->elements[cell##__state.i], true) : \
398  (cell = NULL, false); \
399  cell##__state.i++)
400 
401 static inline ForEachState
402 for_each_from_setup(const List *lst, int N)
403 {
404  ForEachState r = {lst, N};
405 
406  Assert(N >= 0);
407  return r;
408 }
409 
410 /*
411  * for_each_cell -
412  * a convenience macro which loops through a list starting from a
413  * specified cell
414  *
415  * The caveats for foreach() apply equally here.
416  */
417 #define for_each_cell(cell, lst, initcell) \
418  for (ForEachState cell##__state = for_each_cell_setup(lst, initcell); \
419  (cell##__state.l != NIL && \
420  cell##__state.i < cell##__state.l->length) ? \
421  (cell = &cell##__state.l->elements[cell##__state.i], true) : \
422  (cell = NULL, false); \
423  cell##__state.i++)
424 
425 static inline ForEachState
426 for_each_cell_setup(const List *lst, const ListCell *initcell)
427 {
428  ForEachState r = {lst,
429  initcell ? list_cell_number(lst, initcell) : list_length(lst)};
430 
431  return r;
432 }
433 
434 /*
435  * forboth -
436  * a convenience macro for advancing through two linked lists
437  * simultaneously. This macro loops through both lists at the same
438  * time, stopping when either list runs out of elements. Depending
439  * on the requirements of the call site, it may also be wise to
440  * assert that the lengths of the two lists are equal. (But, if they
441  * are not, some callers rely on the ending cell values being separately
442  * NULL or non-NULL as defined here; don't try to optimize that.)
443  *
444  * The caveats for foreach() apply equally here.
445  */
446 #define forboth(cell1, list1, cell2, list2) \
447  for (ForBothState cell1##__state = {(list1), (list2), 0}; \
448  multi_for_advance_cell(cell1, cell1##__state, l1, i), \
449  multi_for_advance_cell(cell2, cell1##__state, l2, i), \
450  (cell1 != NULL && cell2 != NULL); \
451  cell1##__state.i++)
452 
453 #define multi_for_advance_cell(cell, state, l, i) \
454  (cell = (state.l != NIL && state.i < state.l->length) ? \
455  &state.l->elements[state.i] : NULL)
456 
457 /*
458  * for_both_cell -
459  * a convenience macro which loops through two lists starting from the
460  * specified cells of each. This macro loops through both lists at the same
461  * time, stopping when either list runs out of elements. Depending on the
462  * requirements of the call site, it may also be wise to assert that the
463  * lengths of the two lists are equal, and initcell1 and initcell2 are at
464  * the same position in the respective lists.
465  *
466  * The caveats for foreach() apply equally here.
467  */
468 #define for_both_cell(cell1, list1, initcell1, cell2, list2, initcell2) \
469  for (ForBothCellState cell1##__state = \
470  for_both_cell_setup(list1, initcell1, list2, initcell2); \
471  multi_for_advance_cell(cell1, cell1##__state, l1, i1), \
472  multi_for_advance_cell(cell2, cell1##__state, l2, i2), \
473  (cell1 != NULL && cell2 != NULL); \
474  cell1##__state.i1++, cell1##__state.i2++)
475 
476 static inline ForBothCellState
477 for_both_cell_setup(const List *list1, const ListCell *initcell1,
478  const List *list2, const ListCell *initcell2)
479 {
480  ForBothCellState r = {list1, list2,
481  initcell1 ? list_cell_number(list1, initcell1) : list_length(list1),
482  initcell2 ? list_cell_number(list2, initcell2) : list_length(list2)};
483 
484  return r;
485 }
486 
487 /*
488  * forthree -
489  * the same for three lists
490  */
491 #define forthree(cell1, list1, cell2, list2, cell3, list3) \
492  for (ForThreeState cell1##__state = {(list1), (list2), (list3), 0}; \
493  multi_for_advance_cell(cell1, cell1##__state, l1, i), \
494  multi_for_advance_cell(cell2, cell1##__state, l2, i), \
495  multi_for_advance_cell(cell3, cell1##__state, l3, i), \
496  (cell1 != NULL && cell2 != NULL && cell3 != NULL); \
497  cell1##__state.i++)
498 
499 /*
500  * forfour -
501  * the same for four lists
502  */
503 #define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4) \
504  for (ForFourState cell1##__state = {(list1), (list2), (list3), (list4), 0}; \
505  multi_for_advance_cell(cell1, cell1##__state, l1, i), \
506  multi_for_advance_cell(cell2, cell1##__state, l2, i), \
507  multi_for_advance_cell(cell3, cell1##__state, l3, i), \
508  multi_for_advance_cell(cell4, cell1##__state, l4, i), \
509  (cell1 != NULL && cell2 != NULL && cell3 != NULL && cell4 != NULL); \
510  cell1##__state.i++)
511 
512 /*
513  * forfive -
514  * the same for five lists
515  */
516 #define forfive(cell1, list1, cell2, list2, cell3, list3, cell4, list4, cell5, list5) \
517  for (ForFiveState cell1##__state = {(list1), (list2), (list3), (list4), (list5), 0}; \
518  multi_for_advance_cell(cell1, cell1##__state, l1, i), \
519  multi_for_advance_cell(cell2, cell1##__state, l2, i), \
520  multi_for_advance_cell(cell3, cell1##__state, l3, i), \
521  multi_for_advance_cell(cell4, cell1##__state, l4, i), \
522  multi_for_advance_cell(cell5, cell1##__state, l5, i), \
523  (cell1 != NULL && cell2 != NULL && cell3 != NULL && \
524  cell4 != NULL && cell5 != NULL); \
525  cell1##__state.i++)
526 
527 /* Functions in src/backend/nodes/list.c */
528 
529 extern List *list_make1_impl(NodeTag t, ListCell datum1);
530 extern List *list_make2_impl(NodeTag t, ListCell datum1, ListCell datum2);
531 extern List *list_make3_impl(NodeTag t, ListCell datum1, ListCell datum2,
532  ListCell datum3);
533 extern List *list_make4_impl(NodeTag t, ListCell datum1, ListCell datum2,
534  ListCell datum3, ListCell datum4);
535 extern List *list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2,
536  ListCell datum3, ListCell datum4,
537  ListCell datum5);
538 
539 extern pg_nodiscard List *lappend(List *list, void *datum);
540 extern pg_nodiscard List *lappend_int(List *list, int datum);
541 extern pg_nodiscard List *lappend_oid(List *list, Oid datum);
542 
543 extern pg_nodiscard List *list_insert_nth(List *list, int pos, void *datum);
544 extern pg_nodiscard List *list_insert_nth_int(List *list, int pos, int datum);
545 extern pg_nodiscard List *list_insert_nth_oid(List *list, int pos, Oid datum);
546 
547 extern pg_nodiscard List *lcons(void *datum, List *list);
548 extern pg_nodiscard List *lcons_int(int datum, List *list);
549 extern pg_nodiscard List *lcons_oid(Oid datum, List *list);
550 
551 extern pg_nodiscard List *list_concat(List *list1, const List *list2);
552 extern pg_nodiscard List *list_concat_copy(const List *list1, const List *list2);
553 
554 extern pg_nodiscard List *list_truncate(List *list, int new_size);
555 
556 extern bool list_member(const List *list, const void *datum);
557 extern bool list_member_ptr(const List *list, const void *datum);
558 extern bool list_member_int(const List *list, int datum);
559 extern bool list_member_oid(const List *list, Oid datum);
560 
561 extern pg_nodiscard List *list_delete(List *list, void *datum);
562 extern pg_nodiscard List *list_delete_ptr(List *list, void *datum);
563 extern pg_nodiscard List *list_delete_int(List *list, int datum);
564 extern pg_nodiscard List *list_delete_oid(List *list, Oid datum);
569 
570 extern List *list_union(const List *list1, const List *list2);
571 extern List *list_union_ptr(const List *list1, const List *list2);
572 extern List *list_union_int(const List *list1, const List *list2);
573 extern List *list_union_oid(const List *list1, const List *list2);
574 
575 extern List *list_intersection(const List *list1, const List *list2);
576 extern List *list_intersection_int(const List *list1, const List *list2);
577 
578 /* currently, there's no need for list_intersection_ptr etc */
579 
580 extern List *list_difference(const List *list1, const List *list2);
581 extern List *list_difference_ptr(const List *list1, const List *list2);
582 extern List *list_difference_int(const List *list1, const List *list2);
583 extern List *list_difference_oid(const List *list1, const List *list2);
584 
585 extern pg_nodiscard List *list_append_unique(List *list, void *datum);
586 extern pg_nodiscard List *list_append_unique_ptr(List *list, void *datum);
587 extern pg_nodiscard List *list_append_unique_int(List *list, int datum);
589 
590 extern pg_nodiscard List *list_concat_unique(List *list1, const List *list2);
591 extern pg_nodiscard List *list_concat_unique_ptr(List *list1, const List *list2);
592 extern pg_nodiscard List *list_concat_unique_int(List *list1, const List *list2);
593 extern pg_nodiscard List *list_concat_unique_oid(List *list1, const List *list2);
594 
595 extern void list_deduplicate_oid(List *list);
596 
597 extern void list_free(List *list);
598 extern void list_free_deep(List *list);
599 
600 extern pg_nodiscard List *list_copy(const List *list);
601 extern pg_nodiscard List *list_copy_tail(const List *list, int nskip);
602 extern pg_nodiscard List *list_copy_deep(const List *oldlist);
603 
604 typedef int (*list_sort_comparator) (const ListCell *a, const ListCell *b);
606 
607 extern int list_int_cmp(const ListCell *p1, const ListCell *p2);
608 extern int list_oid_cmp(const ListCell *p1, const ListCell *p2);
609 
610 #endif /* PG_LIST_H */
pg_nodiscard List * list_delete_int(List *list, int datum)
Definition: list.c:830
pg_nodiscard List * list_append_unique_int(List *list, int datum)
Definition: list.c:1220
bool list_member_int(const List *list, int datum)
Definition: list.c:669
#define NIL
Definition: pg_list.h:65
pg_nodiscard List * list_copy_deep(const List *oldlist)
Definition: list.c:1463
static int list_cell_number(const List *l, const ListCell *c)
Definition: pg_list.h:312
#define IsA(nodeptr, _type_)
Definition: nodes.h:587
pg_nodiscard List * list_insert_nth_int(List *list, int pos, int datum)
Definition: list.c:429
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:322
static ListCell * list_nth_cell(const List *list, int n)
Definition: pg_list.h:256
const List * l2
Definition: pg_list.h:102
List * list_difference_ptr(const List *list1, const List *list2)
Definition: list.c:1117
List * list_make4_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4)
Definition: list.c:267
pg_nodiscard List * list_append_unique_oid(List *list, Oid datum)
Definition: list.c:1232
pg_nodiscard List * lcons_int(int datum, List *list)
Definition: list.c:486
List * list_union(const List *list1, const List *list2)
Definition: list.c:930
List * list_make3_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3)
Definition: list.c:254
pg_nodiscard List * list_concat_unique_ptr(List *list1, const List *list2)
Definition: list.c:1274
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
const List * l2
Definition: pg_list.h:86
const List * l1
Definition: pg_list.h:85
pg_nodiscard List * list_delete_cell(List *list, ListCell *cell)
Definition: list.c:782
pg_nodiscard List * list_insert_nth_oid(List *list, int pos, Oid datum)
Definition: list.c:443
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
static ListCell * list_last_cell(const List *list)
Definition: pg_list.h:267
void list_deduplicate_oid(List *list)
Definition: list.c:1340
const List * l3
Definition: pg_list.h:103
static int list_nth_int(const List *list, int n)
Definition: pg_list.h:289
List * list_union_ptr(const List *list1, const List *list2)
Definition: list.c:954
pg_nodiscard List * list_copy(const List *list)
Definition: list.c:1418
List * list_union_oid(const List *list1, const List *list2)
Definition: list.c:1000
static Oid list_nth_oid(const List *list, int n)
Definition: pg_list.h:300
int int_value
Definition: pg_list.h:46
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:689
int list_int_cmp(const ListCell *p1, const ListCell *p2)
Definition: list.c:1513
static ForBothCellState for_both_cell_setup(const List *list1, const ListCell *initcell1, const List *list2, const ListCell *initcell2)
Definition: pg_list.h:477
#define lfirst_int(lc)
Definition: pg_list.h:170
void list_free(List *list)
Definition: list.c:1391
static void * list_nth(const List *list, int n)
Definition: pg_list.h:278
const List * l3
Definition: pg_list.h:112
List * list_union_int(const List *list1, const List *list2)
Definition: list.c:977
pg_nodiscard List * list_truncate(List *list, int new_size)
Definition: list.c:600
static ForEachState for_each_cell_setup(const List *lst, const ListCell *initcell)
Definition: pg_list.h:426
char * c
pg_nodiscard List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
static ListCell * list_second_cell(const List *l)
Definition: pg_list.h:139
pg_nodiscard List * list_delete(List *list, void *datum)
Definition: list.c:792
void list_free_deep(List *list)
Definition: list.c:1405
const List * l4
Definition: pg_list.h:104
struct ForFiveState ForFiveState
List * list_intersection_int(const List *list1, const List *list2)
Definition: list.c:1059
const List * l2
Definition: pg_list.h:79
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
pg_nodiscard List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:415
struct ForThreeState ForThreeState
pg_nodiscard List * list_delete_first(List *list)
Definition: list.c:875
const List * l3
Definition: pg_list.h:95
pg_nodiscard List * list_concat_unique_oid(List *list1, const List *list2)
Definition: list.c:1316
const List * l4
Definition: pg_list.h:113
List * list_make2_impl(NodeTag t, ListCell datum1, ListCell datum2)
Definition: list.c:243
const List * l2
Definition: pg_list.h:111
List * list_difference(const List *list1, const List *list2)
Definition: list.c:1091
pg_nodiscard List * lappend(List *list, void *datum)
Definition: list.c:336
const List * l1
Definition: pg_list.h:78
pg_nodiscard List * list_delete_nth_cell(List *list, int n)
Definition: list.c:711
pg_nodiscard List * lcons_oid(Oid datum, List *list)
Definition: list.c:504
pg_nodiscard List * list_concat_unique_int(List *list1, const List *list2)
Definition: list.c:1295
union ListCell ListCell
pg_nodiscard List * list_copy_tail(const List *list, int nskip)
Definition: list.c:1437
bool list_member(const List *list, const void *datum)
Definition: list.c:628
int(* list_sort_comparator)(const ListCell *a, const ListCell *b)
Definition: pg_list.h:604
pg_nodiscard List * list_append_unique_ptr(List *list, void *datum)
Definition: list.c:1208
pg_nodiscard List * list_delete_last(List *list)
Definition: list.c:892
const List * l1
Definition: pg_list.h:110
int max_length
Definition: pg_list.h:54
ListCell * elements
Definition: pg_list.h:55
pg_nodiscard List * list_delete_ptr(List *list, void *datum)
Definition: list.c:811
int list_oid_cmp(const ListCell *p1, const ListCell *p2)
Definition: list.c:1529
List * list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4, ListCell datum5)
Definition: list.c:281
List * list_make1_impl(NodeTag t, ListCell datum1)
Definition: list.c:233
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
#define pg_nodiscard
Definition: c.h:132
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:649
const List * l2
Definition: pg_list.h:94
const List * l5
Definition: pg_list.h:114
static int list_length(const List *l)
Definition: pg_list.h:149
struct ForFourState ForFourState
pg_nodiscard List * list_concat_unique(List *list1, const List *list2)
Definition: list.c:1252
pg_nodiscard List * lcons(void *datum, List *list)
Definition: list.c:468
int length
Definition: pg_list.h:53
void * ptr_value
Definition: pg_list.h:45
List * list_difference_int(const List *list1, const List *list2)
Definition: list.c:1142
Oid oid_value
Definition: pg_list.h:47
const List * l1
Definition: pg_list.h:101
NodeTag type
Definition: pg_list.h:52
pg_nodiscard List * lappend_int(List *list, int datum)
Definition: list.c:354
struct ForBothState ForBothState
struct ForEachState ForEachState
static ListCell * list_tail(const List *l)
Definition: pg_list.h:132
pg_nodiscard List * list_concat(List *list1, const List *list2)
Definition: list.c:530
pg_nodiscard List * list_delete_oid(List *list, Oid datum)
Definition: list.c:849
struct List List
const List * l1
Definition: pg_list.h:93
struct ForBothCellState ForBothCellState
pg_nodiscard List * list_append_unique(List *list, void *datum)
Definition: list.c:1195
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1496
List * list_intersection(const List *list1, const List *list2)
Definition: list.c:1033
Definition: pg_list.h:50
pg_nodiscard List * list_concat_copy(const List *list1, const List *list2)
Definition: list.c:567
const List * l
Definition: pg_list.h:72
#define lfirst_oid(lc)
Definition: pg_list.h:171
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747
List * list_difference_oid(const List *list1, const List *list2)
Definition: list.c:1167
static ForEachState for_each_from_setup(const List *lst, int N)
Definition: pg_list.h:402