[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
list.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  list_elem
 
struct  list
 

Macros

#define list_entry(LIST_ELEM, STRUCT, MEMBER)
 

Typedefs

typedef bool list_less_func(const struct list_elem *a, const struct list_elem *b, void *aux)
 

Functions

void list_init (struct list *)
 
struct list_elemlist_begin (struct list *)
 
struct list_elemlist_next (struct list_elem *)
 
struct list_elemlist_end (struct list *)
 
struct list_elemlist_rbegin (struct list *)
 
struct list_elemlist_prev (struct list_elem *)
 
struct list_elemlist_rend (struct list *)
 
struct list_elemlist_head (struct list *)
 
struct list_elemlist_tail (struct list *)
 
void list_insert (struct list_elem *, struct list_elem *)
 
void list_splice (struct list_elem *before, struct list_elem *first, struct list_elem *last)
 
void list_push_front (struct list *, struct list_elem *)
 
void list_push_back (struct list *, struct list_elem *)
 
struct list_elemlist_remove (struct list_elem *)
 
struct list_elemlist_pop_front (struct list *)
 
struct list_elemlist_pop_back (struct list *)
 
struct list_elemlist_front (struct list *)
 
struct list_elemlist_back (struct list *)
 
size_t list_size (struct list *)
 
bool list_empty (struct list *)
 
void list_reverse (struct list *)
 
void list_sort (struct list *, list_less_func *, void *aux)
 
void list_insert_ordered (struct list *, struct list_elem *, list_less_func *, void *aux)
 
void list_unique (struct list *, struct list *duplicates, list_less_func *, void *aux)
 
struct list_elemlist_max (struct list *, list_less_func *, void *aux)
 
struct list_elemlist_min (struct list *, list_less_func *, void *aux)
 

Macro Definition Documentation

◆ list_entry

#define list_entry (   LIST_ELEM,
  STRUCT,
  MEMBER 
)
Value:
((STRUCT *) ((uint8_t *) &(LIST_ELEM)->next \
- offsetof (STRUCT, MEMBER.next)))
static int next(int pos)
Definition: intq.c:74
#define offsetof(TYPE, MEMBER)
Definition: stddef.h:5
unsigned char uint8_t
Definition: stdint.h:20

Typedef Documentation

◆ list_less_func

typedef bool list_less_func(const struct list_elem *a, const struct list_elem *b, void *aux)

Function Documentation

◆ list_back()

struct list_elem * list_back ( struct list list)
277 {
279 return list->tail.prev;
280}
#define ASSERT(CONDITION)
Definition: debug.h:30
bool list_empty(struct list *list)
Definition: list.c:296
struct list_elem * prev
Definition: list.h:88
Definition: list.h:93
struct list_elem tail
Definition: list.h:95
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_begin()

struct list_elem * list_begin ( struct list list)
68 {
69 ASSERT (list != NULL);
70 return list->head.next;
71}
#define NULL
Definition: stddef.h:4
struct list_elem * next
Definition: list.h:89
struct list_elem head
Definition: list.h:94
Here is the caller graph for this function:

◆ list_empty()

bool list_empty ( struct list list)
296 {
297 return list_begin (list) == list_end (list);
298}
struct list_elem * list_begin(struct list *list)
Definition: list.c:68
struct list_elem * list_end(struct list *list)
Definition: list.c:88
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_end()

struct list_elem * list_end ( struct list list)
88 {
89 ASSERT (list != NULL);
90 return &list->tail;
91}
Here is the caller graph for this function:

◆ list_front()

struct list_elem * list_front ( struct list list)
269 {
271 return list->head.next;
272}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_head()

struct list_elem * list_head ( struct list list)
141 {
142 ASSERT (list != NULL);
143 return &list->head;
144}
Here is the caller graph for this function:

◆ list_init()

void list_init ( struct list list)
58 {
59 ASSERT (list != NULL);
60 list->head.prev = NULL;
61 list->head.next = &list->tail;
62 list->tail.prev = &list->head;
63 list->tail.next = NULL;
64}
Here is the caller graph for this function:

◆ list_insert()

void list_insert ( struct list_elem before,
struct list_elem elem 
)
157 {
158 ASSERT (is_interior (before) || is_tail (before));
159 ASSERT (elem != NULL);
160
161 elem->prev = before->prev;
162 elem->next = before;
163 before->prev->next = elem;
164 before->prev = elem;
165}
static bool is_interior(struct list_elem *elem)
Definition: list.c:46
static bool is_tail(struct list_elem *elem)
Definition: list.c:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_insert_ordered()

void list_insert_ordered ( struct list list,
struct list_elem elem,
list_less_func less,
void *  aux 
)
420 {
421 struct list_elem *e;
422
423 ASSERT (list != NULL);
424 ASSERT (elem != NULL);
425 ASSERT (less != NULL);
426
427 for (e = list_begin (list); e != list_end (list); e = list_next (e))
428 if (less (elem, e, aux))
429 break;
430 return list_insert (e, elem);
431}
void list_insert(struct list_elem *before, struct list_elem *elem)
Definition: list.c:157
struct list_elem * list_next(struct list_elem *elem)
Definition: list.c:77
Definition: list.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_max()

struct list_elem * list_max ( struct list list,
list_less_func less,
void *  aux 
)
462 {
463 struct list_elem *max = list_begin (list);
464 if (max != list_end (list)) {
465 struct list_elem *e;
466
467 for (e = list_next (max); e != list_end (list); e = list_next (e))
468 if (less (max, e, aux))
469 max = e;
470 }
471 return max;
472}
Here is the call graph for this function:

◆ list_min()

struct list_elem * list_min ( struct list list,
list_less_func less,
void *  aux 
)
479 {
480 struct list_elem *min = list_begin (list);
481 if (min != list_end (list)) {
482 struct list_elem *e;
483
484 for (e = list_next (min); e != list_end (list); e = list_next (e))
485 if (less (e, min, aux))
486 min = e;
487 }
488 return min;
489}
Here is the call graph for this function:

◆ list_next()

struct list_elem * list_next ( struct list_elem elem)
77 {
78 ASSERT (is_head (elem) || is_interior (elem));
79 return elem->next;
80}
static bool is_head(struct list_elem *elem)
Definition: list.c:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_pop_back()

struct list_elem * list_pop_back ( struct list list)
260 {
261 struct list_elem *back = list_back (list);
262 list_remove (back);
263 return back;
264}
struct list_elem * list_remove(struct list_elem *elem)
Definition: list.c:241
struct list_elem * list_back(struct list *list)
Definition: list.c:277
Here is the call graph for this function:

◆ list_pop_front()

struct list_elem * list_pop_front ( struct list list)
251 {
252 struct list_elem *front = list_front (list);
253 list_remove (front);
254 return front;
255}
struct list_elem * list_front(struct list *list)
Definition: list.c:269
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_prev()

struct list_elem * list_prev ( struct list_elem elem)
105 {
106 ASSERT (is_interior (elem) || is_tail (elem));
107 return elem->prev;
108}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_push_back()

void list_push_back ( struct list list,
struct list_elem elem 
)
202 {
203 list_insert (list_end (list), elem);
204}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_push_front()

void list_push_front ( struct list list,
struct list_elem elem 
)
195 {
196 list_insert (list_begin (list), elem);
197}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_rbegin()

struct list_elem * list_rbegin ( struct list list)
96 {
97 ASSERT (list != NULL);
98 return list->tail.prev;
99}

◆ list_remove()

struct list_elem * list_remove ( struct list_elem elem)
241 {
242 ASSERT (is_interior (elem));
243 elem->prev->next = elem->next;
244 elem->next->prev = elem->prev;
245 return elem->next;
246}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_rend()

struct list_elem * list_rend ( struct list list)
124 {
125 ASSERT (list != NULL);
126 return &list->head;
127}

◆ list_reverse()

void list_reverse ( struct list list)
310 {
311 if (!list_empty (list)) {
312 struct list_elem *e;
313
314 for (e = list_begin (list); e != list_end (list); e = e->prev)
315 swap (&e->prev, &e->next);
316 swap (&list->head.next, &list->tail.prev);
318 }
319}
static void swap(struct list_elem **a, struct list_elem **b)
Definition: list.c:302
Here is the call graph for this function:

◆ list_size()

size_t list_size ( struct list list)
285 {
286 struct list_elem *e;
287 size_t cnt = 0;
288
289 for (e = list_begin (list); e != list_end (list); e = list_next (e))
290 cnt++;
291 return cnt;
292}
Here is the call graph for this function:

◆ list_sort()

void list_sort ( struct list list,
list_less_func less,
void *  aux 
)
381 {
382 size_t output_run_cnt; /* Number of runs output in current pass. */
383
384 ASSERT (list != NULL);
385 ASSERT (less != NULL);
386
387 /* Pass over the list repeatedly, merging adjacent runs of
388 nondecreasing elements, until only one run is left. */
389 do {
390 struct list_elem *a0; /* Start of first run. */
391 struct list_elem *a1b0; /* End of first run, start of second. */
392 struct list_elem *b1; /* End of second run. */
393
394 output_run_cnt = 0;
395 for (a0 = list_begin (list); a0 != list_end (list); a0 = b1) {
396 /* Each iteration produces one output run. */
397 output_run_cnt++;
398
399 /* Locate two adjacent runs of nondecreasing elements
400 A0...A1B0 and A1B0...B1. */
401 a1b0 = find_end_of_run (a0, list_end (list), less, aux);
402 if (a1b0 == list_end (list))
403 break;
404 b1 = find_end_of_run (a1b0, list_end (list), less, aux);
405
406 /* Merge the runs. */
407 inplace_merge (a0, a1b0, b1, less, aux);
408 }
409 }
410 while (output_run_cnt > 1);
411
412 ASSERT (is_sorted (list_begin (list), list_end (list), less, aux));
413}
static void inplace_merge(struct list_elem *a0, struct list_elem *a1b0, struct list_elem *b1, list_less_func *less, void *aux)
Definition: list.c:358
static bool is_sorted(struct list_elem *a, struct list_elem *b, list_less_func *less, void *aux) UNUSED
Definition: list.c:324
static struct list_elem * find_end_of_run(struct list_elem *a, struct list_elem *b, list_less_func *less, void *aux)
Definition: list.c:339
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_splice()

void list_splice ( struct list_elem before,
struct list_elem first,
struct list_elem last 
)
172 {
173 ASSERT (is_interior (before) || is_tail (before));
174 if (first == last)
175 return;
176 last = list_prev (last);
177
178 ASSERT (is_interior (first));
179 ASSERT (is_interior (last));
180
181 /* Cleanly remove FIRST...LAST from its current list. */
182 first->prev->next = last->next;
183 last->next->prev = first->prev;
184
185 /* Splice FIRST...LAST into new list. */
186 first->prev = before->prev;
187 last->next = before;
188 before->prev->next = first;
189 before->prev = last;
190}
struct list_elem * list_prev(struct list_elem *elem)
Definition: list.c:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_tail()

struct list_elem * list_tail ( struct list list)
148 {
149 ASSERT (list != NULL);
150 return &list->tail;
151}

◆ list_unique()

void list_unique ( struct list list,
struct list duplicates,
list_less_func less,
void *  aux 
)
439 {
440 struct list_elem *elem, *next;
441
442 ASSERT (list != NULL);
443 ASSERT (less != NULL);
444 if (list_empty (list))
445 return;
446
447 elem = list_begin (list);
448 while ((next = list_next (elem)) != list_end (list))
449 if (!less (elem, next, aux) && !less (next, elem, aux)) {
451 if (duplicates != NULL)
452 list_push_back (duplicates, next);
453 } else
454 elem = next;
455}
void list_push_back(struct list *list, struct list_elem *elem)
Definition: list.c:202
Here is the call graph for this function: