68 #define NIL ((List *) NULL)
172 #define lfirst(lc) ((lc)->ptr_value)
173 #define lfirst_int(lc) ((lc)->int_value)
174 #define lfirst_oid(lc) ((lc)->oid_value)
175 #define lfirst_xid(lc) ((lc)->xid_value)
176 #define lfirst_node(type,lc) castNode(type, lfirst(lc))
178 #define linitial(l) lfirst(list_nth_cell(l, 0))
179 #define linitial_int(l) lfirst_int(list_nth_cell(l, 0))
180 #define linitial_oid(l) lfirst_oid(list_nth_cell(l, 0))
181 #define linitial_node(type,l) castNode(type, linitial(l))
183 #define lsecond(l) lfirst(list_nth_cell(l, 1))
184 #define lsecond_int(l) lfirst_int(list_nth_cell(l, 1))
185 #define lsecond_oid(l) lfirst_oid(list_nth_cell(l, 1))
186 #define lsecond_node(type,l) castNode(type, lsecond(l))
188 #define lthird(l) lfirst(list_nth_cell(l, 2))
189 #define lthird_int(l) lfirst_int(list_nth_cell(l, 2))
190 #define lthird_oid(l) lfirst_oid(list_nth_cell(l, 2))
191 #define lthird_node(type,l) castNode(type, lthird(l))
193 #define lfourth(l) lfirst(list_nth_cell(l, 3))
194 #define lfourth_int(l) lfirst_int(list_nth_cell(l, 3))
195 #define lfourth_oid(l) lfirst_oid(list_nth_cell(l, 3))
196 #define lfourth_node(type,l) castNode(type, lfourth(l))
198 #define llast(l) lfirst(list_last_cell(l))
199 #define llast_int(l) lfirst_int(list_last_cell(l))
200 #define llast_oid(l) lfirst_oid(list_last_cell(l))
201 #define llast_xid(l) lfirst_xid(list_last_cell(l))
202 #define llast_node(type,l) castNode(type, llast(l))
207 #define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
208 #define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
209 #define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
210 #define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
212 #define list_make1(x1) \
213 list_make1_impl(T_List, list_make_ptr_cell(x1))
214 #define list_make2(x1,x2) \
215 list_make2_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2))
216 #define list_make3(x1,x2,x3) \
217 list_make3_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2), \
218 list_make_ptr_cell(x3))
219 #define list_make4(x1,x2,x3,x4) \
220 list_make4_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2), \
221 list_make_ptr_cell(x3), list_make_ptr_cell(x4))
222 #define list_make5(x1,x2,x3,x4,x5) \
223 list_make5_impl(T_List, list_make_ptr_cell(x1), list_make_ptr_cell(x2), \
224 list_make_ptr_cell(x3), list_make_ptr_cell(x4), \
225 list_make_ptr_cell(x5))
227 #define list_make1_int(x1) \
228 list_make1_impl(T_IntList, list_make_int_cell(x1))
229 #define list_make2_int(x1,x2) \
230 list_make2_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2))
231 #define list_make3_int(x1,x2,x3) \
232 list_make3_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2), \
233 list_make_int_cell(x3))
234 #define list_make4_int(x1,x2,x3,x4) \
235 list_make4_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2), \
236 list_make_int_cell(x3), list_make_int_cell(x4))
237 #define list_make5_int(x1,x2,x3,x4,x5) \
238 list_make5_impl(T_IntList, list_make_int_cell(x1), list_make_int_cell(x2), \
239 list_make_int_cell(x3), list_make_int_cell(x4), \
240 list_make_int_cell(x5))
242 #define list_make1_oid(x1) \
243 list_make1_impl(T_OidList, list_make_oid_cell(x1))
244 #define list_make2_oid(x1,x2) \
245 list_make2_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2))
246 #define list_make3_oid(x1,x2,x3) \
247 list_make3_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2), \
248 list_make_oid_cell(x3))
249 #define list_make4_oid(x1,x2,x3,x4) \
250 list_make4_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2), \
251 list_make_oid_cell(x3), list_make_oid_cell(x4))
252 #define list_make5_oid(x1,x2,x3,x4,x5) \
253 list_make5_impl(T_OidList, list_make_oid_cell(x1), list_make_oid_cell(x2), \
254 list_make_oid_cell(x3), list_make_oid_cell(x4), \
255 list_make_oid_cell(x5))
257 #define list_make1_xid(x1) \
258 list_make1_impl(T_XidList, list_make_xid_cell(x1))
259 #define list_make2_xid(x1,x2) \
260 list_make2_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2))
261 #define list_make3_xid(x1,x2,x3) \
262 list_make3_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
263 list_make_xid_cell(x3))
264 #define list_make4_xid(x1,x2,x3,x4) \
265 list_make4_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
266 list_make_xid_cell(x3), list_make_xid_cell(x4))
267 #define list_make5_xid(x1,x2,x3,x4,x5) \
268 list_make5_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
269 list_make_xid_cell(x3), list_make_xid_cell(x4), \
270 list_make_xid_cell(x5))
280 Assert(n >= 0 && n < list->length);
281 return &
list->elements[n];
291 return &
list->elements[
list->length - 1];
327 #define list_nth_node(type,list,n) castNode(type, list_nth(list, n))
373 #define foreach(cell, lst) \
374 for (ForEachState cell##__state = {(lst), 0}; \
375 (cell##__state.l != NIL && \
376 cell##__state.i < cell##__state.l->length) ? \
377 (cell = &cell##__state.l->elements[cell##__state.i], true) : \
378 (cell = NULL, false); \
390 #define foreach_delete_current(lst, cell) \
391 (cell##__state.i--, \
392 (List *) (cell##__state.l = list_delete_cell(lst, cell)))
403 #define foreach_current_index(cell) (cell##__state.i)
414 #define for_each_from(cell, lst, N) \
415 for (ForEachState cell##__state = for_each_from_setup(lst, N); \
416 (cell##__state.l != NIL && \
417 cell##__state.i < cell##__state.l->length) ? \
418 (cell = &cell##__state.l->elements[cell##__state.i], true) : \
419 (cell = NULL, false); \
438 #define for_each_cell(cell, lst, initcell) \
439 for (ForEachState cell##__state = for_each_cell_setup(lst, initcell); \
440 (cell##__state.l != NIL && \
441 cell##__state.i < cell##__state.l->length) ? \
442 (cell = &cell##__state.l->elements[cell##__state.i], true) : \
443 (cell = NULL, false); \
467 #define forboth(cell1, list1, cell2, list2) \
468 for (ForBothState cell1##__state = {(list1), (list2), 0}; \
469 multi_for_advance_cell(cell1, cell1##__state, l1, i), \
470 multi_for_advance_cell(cell2, cell1##__state, l2, i), \
471 (cell1 != NULL && cell2 != NULL); \
474 #define multi_for_advance_cell(cell, state, l, i) \
475 (cell = (state.l != NIL && state.i < state.l->length) ? \
476 &state.l->elements[state.i] : NULL)
489 #define for_both_cell(cell1, list1, initcell1, cell2, list2, initcell2) \
490 for (ForBothCellState cell1##__state = \
491 for_both_cell_setup(list1, initcell1, list2, initcell2); \
492 multi_for_advance_cell(cell1, cell1##__state, l1, i1), \
493 multi_for_advance_cell(cell2, cell1##__state, l2, i2), \
494 (cell1 != NULL && cell2 != NULL); \
495 cell1##__state.i1++, cell1##__state.i2++)
512 #define forthree(cell1, list1, cell2, list2, cell3, list3) \
513 for (ForThreeState cell1##__state = {(list1), (list2), (list3), 0}; \
514 multi_for_advance_cell(cell1, cell1##__state, l1, i), \
515 multi_for_advance_cell(cell2, cell1##__state, l2, i), \
516 multi_for_advance_cell(cell3, cell1##__state, l3, i), \
517 (cell1 != NULL && cell2 != NULL && cell3 != NULL); \
524 #define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4) \
525 for (ForFourState cell1##__state = {(list1), (list2), (list3), (list4), 0}; \
526 multi_for_advance_cell(cell1, cell1##__state, l1, i), \
527 multi_for_advance_cell(cell2, cell1##__state, l2, i), \
528 multi_for_advance_cell(cell3, cell1##__state, l3, i), \
529 multi_for_advance_cell(cell4, cell1##__state, l4, i), \
530 (cell1 != NULL && cell2 != NULL && cell3 != NULL && cell4 != NULL); \
537 #define forfive(cell1, list1, cell2, list2, cell3, list3, cell4, list4, cell5, list5) \
538 for (ForFiveState cell1##__state = {(list1), (list2), (list3), (list4), (list5), 0}; \
539 multi_for_advance_cell(cell1, cell1##__state, l1, i), \
540 multi_for_advance_cell(cell2, cell1##__state, l2, i), \
541 multi_for_advance_cell(cell3, cell1##__state, l3, i), \
542 multi_for_advance_cell(cell4, cell1##__state, l4, i), \
543 multi_for_advance_cell(cell5, cell1##__state, l5, i), \
544 (cell1 != NULL && cell2 != NULL && cell3 != NULL && \
545 cell4 != NULL && cell5 != NULL); \
#define FLEXIBLE_ARRAY_MEMBER
static void PGresult const char * p2
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
List * list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4, ListCell datum5)
pg_nodiscard List * list_copy_head(const List *oldlist, int len)
void list_sort(List *list, list_sort_comparator cmp)
static int list_length(const List *l)
pg_nodiscard List * list_copy_deep(const List *oldlist)
pg_nodiscard List * lcons_int(int datum, List *list)
pg_nodiscard List * list_delete_first_n(List *list, int n)
struct ForFiveState ForFiveState
static ForEachState for_each_cell_setup(const List *lst, const ListCell *initcell)
static Oid list_nth_oid(const List *list, int n)
List * list_difference_ptr(const List *list1, const List *list2)
List * list_make2_impl(NodeTag t, ListCell datum1, ListCell datum2)
List * list_union(const List *list1, const List *list2)
pg_nodiscard List * lappend_xid(List *list, TransactionId datum)
pg_nodiscard List * list_delete_oid(List *list, Oid datum)
pg_nodiscard List * list_concat_unique_oid(List *list1, const List *list2)
struct ForThreeState ForThreeState
pg_nodiscard List * lappend_int(List *list, int datum)
pg_nodiscard List * list_delete_ptr(List *list, void *datum)
static ListCell * list_head(const List *l)
List * list_make1_impl(NodeTag t, ListCell datum1)
pg_nodiscard List * list_concat_unique_int(List *list1, const List *list2)
static ListCell * list_nth_cell(const List *list, int n)
List * list_difference_oid(const List *list1, const List *list2)
pg_nodiscard List * list_append_unique_oid(List *list, Oid datum)
pg_nodiscard List * list_concat_copy(const List *list1, const List *list2)
static ListCell * list_last_cell(const List *list)
bool list_member_xid(const List *list, TransactionId datum)
pg_nodiscard List * list_truncate(List *list, int new_size)
pg_nodiscard List * list_concat_unique(List *list1, const List *list2)
pg_nodiscard List * list_delete_int(List *list, int datum)
pg_nodiscard List * lcons(void *datum, List *list)
pg_nodiscard List * list_delete_last(List *list)
List * list_intersection_int(const List *list1, const List *list2)
pg_nodiscard List * list_copy_tail(const List *oldlist, int nskip)
List * list_difference_int(const List *list1, const List *list2)
pg_nodiscard List * list_append_unique_int(List *list, int datum)
pg_nodiscard List * list_copy(const List *oldlist)
pg_nodiscard List * list_concat_unique_ptr(List *list1, const List *list2)
static ListCell * list_tail(const List *l)
List * list_intersection(const List *list1, const List *list2)
pg_nodiscard List * list_insert_nth_oid(List *list, int pos, Oid datum)
pg_nodiscard List * lcons_oid(Oid datum, List *list)
int(* list_sort_comparator)(const ListCell *a, const ListCell *b)
static void * list_nth(const List *list, int n)
void list_deduplicate_oid(List *list)
int list_oid_cmp(const ListCell *p1, const ListCell *p2)
static ListCell * lnext(const List *l, const ListCell *c)
pg_nodiscard List * list_delete_first(List *list)
static ForEachState for_each_from_setup(const List *lst, int N)
static ForBothCellState for_both_cell_setup(const List *list1, const ListCell *initcell1, const List *list2, const ListCell *initcell2)
struct ForBothState ForBothState
List * list_union_oid(const List *list1, const List *list2)
struct ForEachState ForEachState
bool list_member_ptr(const List *list, const void *datum)
void list_free(List *list)
bool list_member_int(const List *list, int datum)
pg_nodiscard List * lappend(List *list, void *datum)
pg_nodiscard List * list_concat(List *list1, const List *list2)
pg_nodiscard List * list_insert_nth_int(List *list, int pos, int datum)
pg_nodiscard List * list_delete_nth_cell(List *list, int n)
bool list_member_oid(const List *list, Oid datum)
List * list_make3_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3)
List * list_make4_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4)
int list_int_cmp(const ListCell *p1, const ListCell *p2)
static ListCell * list_second_cell(const List *l)
bool list_member(const List *list, const void *datum)
struct ForFourState ForFourState
List * list_union_ptr(const List *list1, const List *list2)
pg_nodiscard List * list_insert_nth(List *list, int pos, void *datum)
pg_nodiscard List * list_delete_cell(List *list, ListCell *cell)
List * list_difference(const List *list1, const List *list2)
pg_nodiscard List * list_append_unique(List *list, void *datum)
static int list_nth_int(const List *list, int n)
pg_nodiscard List * lappend_oid(List *list, Oid datum)
pg_nodiscard List * list_append_unique_ptr(List *list, void *datum)
void list_free_deep(List *list)
static int list_cell_number(const List *l, const ListCell *c)
struct ForBothCellState ForBothCellState
List * list_union_int(const List *list1, const List *list2)
pg_nodiscard List * list_delete(List *list, void *datum)
static int cmp(const chr *x, const chr *y, size_t len)
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]