* Return a list that contains all the cells in list1 that are not in * list2. The returned list is freshly allocated via palloc(), but the * cells themselves point to the same objects as the cells of the * input lists. * * This variant works on lists of pointers, and determines list * membership via equal() */
| 1154 | * membership via equal() |
| 1155 | */ |
| 1156 | List * |
| 1157 | list_difference(const List *list1, const List *list2) |
| 1158 | { |
| 1159 | const ListCell *cell; |
| 1160 | List *result = NIL; |
| 1161 | |
| 1162 | Assert(IsPointerList(list1)); |
| 1163 | Assert(IsPointerList(list2)); |
| 1164 | |
| 1165 | if (list2 == NIL) |
| 1166 | return list_copy(list1); |
| 1167 | |
| 1168 | foreach(cell, list1) |
| 1169 | { |
| 1170 | if (!list_member(list2, lfirst(cell))) |
| 1171 | result = lappend(result, lfirst(cell)); |
| 1172 | } |
| 1173 | |
| 1174 | check_list_invariants(result); |
| 1175 | return result; |
| 1176 | } |
| 1177 | |
| 1178 | /* |
| 1179 | * This variant of list_difference() determines list membership via |
no test coverage detected