00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef PG_LIST_H
00038 #define PG_LIST_H
00039
00040 #include "nodes/nodes.h"
00041
00042
00043 typedef struct ListCell ListCell;
00044
00045 typedef struct List
00046 {
00047 NodeTag type;
00048 int length;
00049 ListCell *head;
00050 ListCell *tail;
00051 } List;
00052
00053 struct ListCell
00054 {
00055 union
00056 {
00057 void *ptr_value;
00058 int int_value;
00059 Oid oid_value;
00060 } data;
00061 ListCell *next;
00062 };
00063
00064
00065
00066
00067
00068
00069 #define NIL ((List *) NULL)
00070
00071
00072
00073
00074
00075
00076
00077
00078 #ifndef PG_USE_INLINE
00079 extern ListCell *list_head(const List *l);
00080 extern ListCell *list_tail(List *l);
00081 extern int list_length(const List *l);
00082 #endif
00083 #if defined(PG_USE_INLINE) || defined(PG_LIST_INCLUDE_DEFINITIONS)
00084 STATIC_IF_INLINE ListCell *
00085 list_head(const List *l)
00086 {
00087 return l ? l->head : NULL;
00088 }
00089
00090 STATIC_IF_INLINE ListCell *
00091 list_tail(List *l)
00092 {
00093 return l ? l->tail : NULL;
00094 }
00095
00096 STATIC_IF_INLINE int
00097 list_length(const List *l)
00098 {
00099 return l ? l->length : 0;
00100 }
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 #define lnext(lc) ((lc)->next)
00115 #define lfirst(lc) ((lc)->data.ptr_value)
00116 #define lfirst_int(lc) ((lc)->data.int_value)
00117 #define lfirst_oid(lc) ((lc)->data.oid_value)
00118
00119 #define linitial(l) lfirst(list_head(l))
00120 #define linitial_int(l) lfirst_int(list_head(l))
00121 #define linitial_oid(l) lfirst_oid(list_head(l))
00122
00123 #define lsecond(l) lfirst(lnext(list_head(l)))
00124 #define lsecond_int(l) lfirst_int(lnext(list_head(l)))
00125 #define lsecond_oid(l) lfirst_oid(lnext(list_head(l)))
00126
00127 #define lthird(l) lfirst(lnext(lnext(list_head(l))))
00128 #define lthird_int(l) lfirst_int(lnext(lnext(list_head(l))))
00129 #define lthird_oid(l) lfirst_oid(lnext(lnext(list_head(l))))
00130
00131 #define lfourth(l) lfirst(lnext(lnext(lnext(list_head(l)))))
00132 #define lfourth_int(l) lfirst_int(lnext(lnext(lnext(list_head(l)))))
00133 #define lfourth_oid(l) lfirst_oid(lnext(lnext(lnext(list_head(l)))))
00134
00135 #define llast(l) lfirst(list_tail(l))
00136 #define llast_int(l) lfirst_int(list_tail(l))
00137 #define llast_oid(l) lfirst_oid(list_tail(l))
00138
00139
00140
00141
00142 #define list_make1(x1) lcons(x1, NIL)
00143 #define list_make2(x1,x2) lcons(x1, list_make1(x2))
00144 #define list_make3(x1,x2,x3) lcons(x1, list_make2(x2, x3))
00145 #define list_make4(x1,x2,x3,x4) lcons(x1, list_make3(x2, x3, x4))
00146
00147 #define list_make1_int(x1) lcons_int(x1, NIL)
00148 #define list_make2_int(x1,x2) lcons_int(x1, list_make1_int(x2))
00149 #define list_make3_int(x1,x2,x3) lcons_int(x1, list_make2_int(x2, x3))
00150 #define list_make4_int(x1,x2,x3,x4) lcons_int(x1, list_make3_int(x2, x3, x4))
00151
00152 #define list_make1_oid(x1) lcons_oid(x1, NIL)
00153 #define list_make2_oid(x1,x2) lcons_oid(x1, list_make1_oid(x2))
00154 #define list_make3_oid(x1,x2,x3) lcons_oid(x1, list_make2_oid(x2, x3))
00155 #define list_make4_oid(x1,x2,x3,x4) lcons_oid(x1, list_make3_oid(x2, x3, x4))
00156
00157
00158
00159
00160
00161 #define foreach(cell, l) \
00162 for ((cell) = list_head(l); (cell) != NULL; (cell) = lnext(cell))
00163
00164
00165
00166
00167
00168
00169 #define for_each_cell(cell, initcell) \
00170 for ((cell) = (initcell); (cell) != NULL; (cell) = lnext(cell))
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 #define forboth(cell1, list1, cell2, list2) \
00181 for ((cell1) = list_head(list1), (cell2) = list_head(list2); \
00182 (cell1) != NULL && (cell2) != NULL; \
00183 (cell1) = lnext(cell1), (cell2) = lnext(cell2))
00184
00185
00186
00187
00188
00189 #define forthree(cell1, list1, cell2, list2, cell3, list3) \
00190 for ((cell1) = list_head(list1), (cell2) = list_head(list2), (cell3) = list_head(list3); \
00191 (cell1) != NULL && (cell2) != NULL && (cell3) != NULL; \
00192 (cell1) = lnext(cell1), (cell2) = lnext(cell2), (cell3) = lnext(cell3))
00193
00194 extern List *lappend(List *list, void *datum);
00195 extern List *lappend_int(List *list, int datum);
00196 extern List *lappend_oid(List *list, Oid datum);
00197
00198 extern ListCell *lappend_cell(List *list, ListCell *prev, void *datum);
00199 extern ListCell *lappend_cell_int(List *list, ListCell *prev, int datum);
00200 extern ListCell *lappend_cell_oid(List *list, ListCell *prev, Oid datum);
00201
00202 extern List *lcons(void *datum, List *list);
00203 extern List *lcons_int(int datum, List *list);
00204 extern List *lcons_oid(Oid datum, List *list);
00205
00206 extern List *list_concat(List *list1, List *list2);
00207 extern List *list_truncate(List *list, int new_size);
00208
00209 extern void *list_nth(const List *list, int n);
00210 extern int list_nth_int(const List *list, int n);
00211 extern Oid list_nth_oid(const List *list, int n);
00212
00213 extern bool list_member(const List *list, const void *datum);
00214 extern bool list_member_ptr(const List *list, const void *datum);
00215 extern bool list_member_int(const List *list, int datum);
00216 extern bool list_member_oid(const List *list, Oid datum);
00217
00218 extern List *list_delete(List *list, void *datum);
00219 extern List *list_delete_ptr(List *list, void *datum);
00220 extern List *list_delete_int(List *list, int datum);
00221 extern List *list_delete_oid(List *list, Oid datum);
00222 extern List *list_delete_first(List *list);
00223 extern List *list_delete_cell(List *list, ListCell *cell, ListCell *prev);
00224
00225 extern List *list_union(const List *list1, const List *list2);
00226 extern List *list_union_ptr(const List *list1, const List *list2);
00227 extern List *list_union_int(const List *list1, const List *list2);
00228 extern List *list_union_oid(const List *list1, const List *list2);
00229
00230 extern List *list_intersection(const List *list1, const List *list2);
00231
00232
00233
00234 extern List *list_difference(const List *list1, const List *list2);
00235 extern List *list_difference_ptr(const List *list1, const List *list2);
00236 extern List *list_difference_int(const List *list1, const List *list2);
00237 extern List *list_difference_oid(const List *list1, const List *list2);
00238
00239 extern List *list_append_unique(List *list, void *datum);
00240 extern List *list_append_unique_ptr(List *list, void *datum);
00241 extern List *list_append_unique_int(List *list, int datum);
00242 extern List *list_append_unique_oid(List *list, Oid datum);
00243
00244 extern List *list_concat_unique(List *list1, List *list2);
00245 extern List *list_concat_unique_ptr(List *list1, List *list2);
00246 extern List *list_concat_unique_int(List *list1, List *list2);
00247 extern List *list_concat_unique_oid(List *list1, List *list2);
00248
00249 extern void list_free(List *list);
00250 extern void list_free_deep(List *list);
00251
00252 extern List *list_copy(const List *list);
00253 extern List *list_copy_tail(const List *list, int nskip);
00254
00255
00256
00257
00258
00259
00260
00261
00262 #ifdef ENABLE_LIST_COMPAT
00263
00264 #define lfirsti(lc) lfirst_int(lc)
00265 #define lfirsto(lc) lfirst_oid(lc)
00266
00267 #define makeList1(x1) list_make1(x1)
00268 #define makeList2(x1, x2) list_make2(x1, x2)
00269 #define makeList3(x1, x2, x3) list_make3(x1, x2, x3)
00270 #define makeList4(x1, x2, x3, x4) list_make4(x1, x2, x3, x4)
00271
00272 #define makeListi1(x1) list_make1_int(x1)
00273 #define makeListi2(x1, x2) list_make2_int(x1, x2)
00274
00275 #define makeListo1(x1) list_make1_oid(x1)
00276 #define makeListo2(x1, x2) list_make2_oid(x1, x2)
00277
00278 #define lconsi(datum, list) lcons_int(datum, list)
00279 #define lconso(datum, list) lcons_oid(datum, list)
00280
00281 #define lappendi(list, datum) lappend_int(list, datum)
00282 #define lappendo(list, datum) lappend_oid(list, datum)
00283
00284 #define nconc(l1, l2) list_concat(l1, l2)
00285
00286 #define nth(n, list) list_nth(list, n)
00287
00288 #define member(datum, list) list_member(list, datum)
00289 #define ptrMember(datum, list) list_member_ptr(list, datum)
00290 #define intMember(datum, list) list_member_int(list, datum)
00291 #define oidMember(datum, list) list_member_oid(list, datum)
00292
00293
00294
00295
00296
00297
00298
00299 #define lremove(elem, list) list_delete_ptr(list, elem)
00300 #define LispRemove(elem, list) list_delete(list, elem)
00301 #define lremovei(elem, list) list_delete_int(list, elem)
00302 #define lremoveo(elem, list) list_delete_oid(list, elem)
00303
00304 #define ltruncate(n, list) list_truncate(list, n)
00305
00306 #define set_union(l1, l2) list_union(l1, l2)
00307 #define set_uniono(l1, l2) list_union_oid(l1, l2)
00308 #define set_ptrUnion(l1, l2) list_union_ptr(l1, l2)
00309
00310 #define set_difference(l1, l2) list_difference(l1, l2)
00311 #define set_differenceo(l1, l2) list_difference_oid(l1, l2)
00312 #define set_ptrDifference(l1, l2) list_difference_ptr(l1, l2)
00313
00314 #define equali(l1, l2) equal(l1, l2)
00315 #define equalo(l1, l2) equal(l1, l2)
00316
00317 #define freeList(list) list_free(list)
00318
00319 #define listCopy(list) list_copy(list)
00320
00321 extern int length(List *list);
00322 #endif
00323
00324 #endif