370 while (a != b && !less (a,
list_prev (a), aux));
391 while (a0 != a1b0 && a1b0 != b1)
392 if (!less (a1b0, a0, aux))
407 size_t output_run_cnt;
437 while (output_run_cnt > 1);
456 if (less (elem, e, aux))
478 if (!less (elem,
next, aux) && !less (
next, elem, aux))
481 if (duplicates !=
NULL)
501 if (less (max, e, aux))
520 if (less (e, min, aux))
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
static int next(int pos)
Returns the position after POS within an intq.
struct list_elem * list_begin(struct list *list)
Returns the beginning of LIST.
struct list_elem * list_min(struct list *list, list_less_func *less, void *aux)
Returns the element in LIST with the smallest value according to LESS given auxiliary data AUX.
struct list_elem * list_remove(struct list_elem *elem)
Removes ELEM from its list and returns the element that followed it.
struct list_elem * list_pop_front(struct list *list)
Removes the front element from LIST and returns it.
void list_push_front(struct list *list, struct list_elem *elem)
Inserts ELEM at the beginning of LIST, so that it becomes the front in LIST.
static void inplace_merge(struct list_elem *a0, struct list_elem *a1b0, struct list_elem *b1, list_less_func *less, void *aux)
Merges A0 through A1B0 (exclusive) with A1B0 through B1 (exclusive) to form a combined range also end...
struct list_elem * list_rbegin(struct list *list)
Returns the LIST's reverse beginning, for iterating through LIST in reverse order,...
void list_unique(struct list *list, struct list *duplicates, list_less_func *less, void *aux)
Iterates through LIST and removes all but the first in each set of adjacent elements that are equal a...
struct list_elem * list_front(struct list *list)
Returns the front element in LIST.
struct list_elem * list_prev(struct list_elem *elem)
Returns the element before ELEM in its list.
static bool is_sorted(struct list_elem *a, struct list_elem *b, list_less_func *less, void *aux) UNUSED
Our doubly linked lists have two header elements: the "head" just before the first element and the "t...
struct list_elem * list_end(struct list *list)
Returns LIST's tail.
bool list_empty(struct list *list)
Returns true if LIST is empty, false otherwise.
void list_insert(struct list_elem *before, struct list_elem *elem)
Inserts ELEM just before BEFORE, which may be either an interior element or a tail.
void list_splice(struct list_elem *before, struct list_elem *first, struct list_elem *last)
Removes elements FIRST though LAST (exclusive) from their current list, then inserts them just before...
struct list_elem * list_max(struct list *list, list_less_func *less, void *aux)
Returns the element in LIST with the largest value according to LESS given auxiliary data AUX.
struct list_elem * list_head(struct list *list)
Return's LIST's head.
void list_init(struct list *list)
Initializes LIST as an empty list.
struct list_elem * list_rend(struct list *list)
Returns LIST's head.
void list_push_back(struct list *list, struct list_elem *elem)
Inserts ELEM at the end of LIST, so that it becomes the back in LIST.
struct list_elem * list_tail(struct list *list)
Return's LIST's tail.
size_t list_size(struct list *list)
Returns the number of elements in LIST.
struct list_elem * list_next(struct list_elem *elem)
Returns the element after ELEM in its list.
void list_reverse(struct list *list)
Reverses the order of LIST.
struct list_elem * list_back(struct list *list)
Returns the back element in LIST.
void list_sort(struct list *list, list_less_func *less, void *aux)
Sorts LIST according to LESS given auxiliary data AUX, using a natural iterative merge sort that runs...
static void swap(struct list_elem **a, struct list_elem **b)
Swaps the `struct list_elem *'s that A and B point to.
static bool is_interior(struct list_elem *elem)
Returns true if ELEM is an interior element, false otherwise.
void list_insert_ordered(struct list *list, struct list_elem *elem, list_less_func *less, void *aux)
Inserts ELEM in the proper position in LIST, which must be sorted according to LESS given auxiliary d...
struct list_elem * list_pop_back(struct list *list)
Removes the back element from LIST and returns it.
static bool is_head(struct list_elem *elem)
Returns true if ELEM is a head, false otherwise.
static struct list_elem * find_end_of_run(struct list_elem *a, struct list_elem *b, list_less_func *less, void *aux)
Finds a run, starting at A and ending not after B, of list elements that are in nondecreasing order a...
static bool is_tail(struct list_elem *elem)
Returns true if ELEM is a tail, false otherwise.
bool list_less_func(const struct list_elem *a, const struct list_elem *b, void *aux)
Compares the value of two list elements A and B, given auxiliary data AUX.
struct list_elem * next
Next list element.
struct list_elem * prev
Previous list element.
struct list_elem tail
List tail.
struct list_elem head
List head.