44 #define DEBUG_LIST_MEMORY_USAGE
48 #define LIST_HEADER_OVERHEAD \
49 ((int) ((offsetof(List, initial_elements) - 1) / sizeof(ListCell) + 1))
55 #define IsPointerList(l) ((l) == NIL || IsA((l), List))
56 #define IsIntegerList(l) ((l) == NIL || IsA((l), IntList))
57 #define IsOidList(l) ((l) == NIL || IsA((l), OidList))
58 #define IsXidList(l) ((l) == NIL || IsA((l), XidList))
60 #ifdef USE_ASSERT_CHECKING
75 list->type == T_IntList ||
76 list->type == T_OidList ||
77 list->type == T_XidList);
80 #define check_list_invariants(l) ((void) 0)
108 #ifndef DEBUG_LIST_MEMORY_USAGE
140 newlist->
length = min_size;
161 #ifndef DEBUG_LIST_MEMORY_USAGE
173 new_max_len = min_size;
176 if (
list->elements ==
list->initial_elements)
188 memcpy(
list->elements,
list->initial_elements,
197 #ifdef CLOBBER_FREED_MEMORY
198 wipe_mem(
list->initial_elements,
207 #ifndef DEBUG_LIST_MEMORY_USAGE
221 memcpy(newelements,
list->elements,
224 list->elements = newelements;
228 list->max_length = new_max_len;
240 list->elements[0] = datum1;
250 list->elements[0] = datum1;
251 list->elements[1] = datum2;
262 list->elements[0] = datum1;
263 list->elements[1] = datum2;
264 list->elements[2] = datum3;
275 list->elements[0] = datum1;
276 list->elements[1] = datum2;
277 list->elements[2] = datum3;
278 list->elements[3] = datum4;
289 list->elements[0] = datum1;
290 list->elements[1] = datum2;
291 list->elements[2] = datum3;
292 list->elements[3] = datum4;
293 list->elements[4] = datum5;
308 if (
list->length >=
list->max_length)
311 memmove(&
list->elements[1], &
list->elements[0],
326 if (
list->length >=
list->max_length)
417 Assert(pos >= 0 && pos <= list->length);
420 if (
list->length >=
list->max_length)
423 if (pos < list->length)
424 memmove(&
list->elements[pos + 1], &
list->elements[pos],
428 return &
list->elements[pos];
638 list->length = new_size;
691 if (
lfirst(cell) == datum)
771 Assert(n >= 0 && n < list->length);
778 if (
list->length == 1)
790 #ifndef DEBUG_LIST_MEMORY_USAGE
791 memmove(&
list->elements[n], &
list->elements[n + 1],
797 int newmaxlen =
list->length - 1;
803 memcpy(&newelems[n], &
list->elements[n + 1],
805 if (
list->elements !=
list->initial_elements)
813 #ifdef CLOBBER_FREED_MEMORY
814 wipe_mem(
list->initial_elements,
821 list->elements = newelems;
822 list->max_length = newmaxlen;
881 if (
lfirst(cell) == datum)
1004 #ifndef DEBUG_LIST_MEMORY_USAGE
1005 memmove(&
list->elements[0], &
list->elements[n],
1011 int newmaxlen =
list->length - n;
1016 memcpy(newelems, &
list->elements[n], newmaxlen *
sizeof(
ListCell));
1017 if (
list->elements !=
list->initial_elements)
1025 #ifdef CLOBBER_FREED_MEMORY
1026 wipe_mem(
list->initial_elements,
1033 list->elements = newelems;
1034 list->max_length = newmaxlen;
1035 list->length = newmaxlen;
1075 foreach(cell, list2)
1099 foreach(cell, list2)
1122 foreach(cell, list2)
1145 foreach(cell, list2)
1179 if (list1 ==
NIL || list2 ==
NIL)
1186 foreach(cell, list1)
1205 if (list1 ==
NIL || list2 ==
NIL)
1212 foreach(cell, list1)
1248 foreach(cell, list1)
1274 foreach(cell, list1)
1299 foreach(cell, list1)
1324 foreach(cell, list1)
1412 foreach(cell, list2)
1434 foreach(cell, list2)
1455 foreach(cell, list2)
1476 foreach(cell, list2)
1506 for (
int j = 1;
j <
len;
j++)
1508 if (elements[
i].oid_value != elements[
j].oid_value)
1511 list->length =
i + 1;
1529 for (
int i = 0;
i <
list->length;
i++)
1532 if (
list->elements !=
list->initial_elements)
1597 if (oldlist ==
NIL ||
len <= 0)
1620 if (oldlist ==
NIL || nskip >= oldlist->
length)
1650 for (
int i = 0;
i < newlist->
length;
i++)
1676 typedef int (*qsort_comparator) (
const void *
a,
const void *
b);
#define Assert(condition)
void * copyObjectImpl(const void *from)
static void PGresult const char * p2
bool equal(const void *a, const void *b)
static int pg_cmp_u32(uint32 a, uint32 b)
static int pg_cmp_s32(int32 a, int32 b)
List * list_delete_int(List *list, int datum)
List * list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2, ListCell datum3, ListCell datum4, ListCell datum5)
static void new_head_cell(List *list)
static ListCell * insert_new_cell(List *list, int pos)
void list_sort(List *list, list_sort_comparator cmp)
List * list_copy_deep(const List *oldlist)
List * list_delete_ptr(List *list, void *datum)
static List * new_list(NodeTag type, int min_size)
List * list_insert_nth(List *list, int pos, void *datum)
List * list_concat_unique(List *list1, const List *list2)
List * list_difference_ptr(const List *list1, const List *list2)
List * list_make2_impl(NodeTag t, ListCell datum1, ListCell datum2)
List * list_delete_first_n(List *list, int n)
List * list_union(const List *list1, const List *list2)
static void enlarge_list(List *list, int min_size)
#define LIST_HEADER_OVERHEAD
List * list_append_unique_int(List *list, int datum)
List * list_make1_impl(NodeTag t, ListCell datum1)
List * list_concat_unique_int(List *list1, const List *list2)
List * lcons_int(int datum, List *list)
List * list_difference_oid(const List *list1, const List *list2)
List * list_concat_unique_oid(List *list1, const List *list2)
List * list_truncate(List *list, int new_size)
List * lappend_xid(List *list, TransactionId datum)
bool list_member_xid(const List *list, TransactionId datum)
List * lappend(List *list, void *datum)
static void list_free_private(List *list, bool deep)
List * list_intersection_int(const List *list1, const List *list2)
List * list_difference_int(const List *list1, const List *list2)
List * list_copy_head(const List *oldlist, int len)
List * lappend_int(List *list, int datum)
List * list_insert_nth_int(List *list, int pos, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_intersection(const List *list1, const List *list2)
List * list_copy(const List *oldlist)
#define check_list_invariants(l)
List * list_delete_first(List *list)
void list_deduplicate_oid(List *list)
static void new_tail_cell(List *list)
List * list_delete_oid(List *list, Oid datum)
int list_oid_cmp(const ListCell *p1, const ListCell *p2)
List * list_append_unique(List *list, void *datum)
List * list_delete_cell(List *list, ListCell *cell)
List * list_delete(List *list, void *datum)
List * list_union_oid(const List *list1, const List *list2)
List * list_delete_nth_cell(List *list, int n)
bool list_member_ptr(const List *list, const void *datum)
List * list_concat_unique_ptr(List *list1, const List *list2)
void list_free(List *list)
bool list_member_int(const List *list, int datum)
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)
List * list_copy_tail(const List *oldlist, int nskip)
int list_int_cmp(const ListCell *p1, const ListCell *p2)
List * list_concat(List *list1, const List *list2)
bool list_member(const List *list, const void *datum)
List * lcons(void *datum, List *list)
List * list_union_ptr(const List *list1, const List *list2)
List * lcons_oid(Oid datum, List *list)
List * list_append_unique_ptr(List *list, void *datum)
List * list_difference(const List *list1, const List *list2)
List * list_concat_copy(const List *list1, const List *list2)
List * list_append_unique_oid(List *list, Oid datum)
void list_free_deep(List *list)
List * list_delete_last(List *list)
List * list_union_int(const List *list1, const List *list2)
List * list_insert_nth_oid(List *list, int pos, Oid datum)
void pfree(void *pointer)
void * repalloc(void *pointer, Size size)
MemoryContext GetMemoryChunkContext(void *pointer)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define VALGRIND_MAKE_MEM_NOACCESS(addr, size)
#define IsA(nodeptr, _type_)
static uint32 pg_nextpower2_32(uint32 num)
static int list_length(const List *l)
#define list_make1_oid(x1)
int(* list_sort_comparator)(const ListCell *a, const ListCell *b)
#define list_make1_int(x1)
#define qsort(a, b, c, d)
static int cmp(const chr *x, const chr *y, size_t len)
ListCell initial_elements[FLEXIBLE_ARRAY_MEMBER]