projects
/
pintos-anon
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8051f62
)
Add list_head(), list_tail().
author
Ben Pfaff
<blp@cs.stanford.edu>
Fri, 3 Sep 2004 06:25:36 +0000
(06:25 +0000)
committer
Ben Pfaff
<blp@cs.stanford.edu>
Fri, 3 Sep 2004 06:25:36 +0000
(06:25 +0000)
src/lib/list.c
patch
|
blob
|
history
src/lib/list.h
patch
|
blob
|
history
diff --git
a/src/lib/list.c
b/src/lib/list.c
index 0011fc7e5793f72a9855455af7db6c5734927127..a5f7c1a6c573fb638d2fadcff8a2d034bd51c7f7 100644
(file)
--- a/
src/lib/list.c
+++ b/
src/lib/list.c
@@
-103,6
+103,16
@@
list_rbegin (struct list *list)
return list->tail.prev;
}
return list->tail.prev;
}
+/* Returns the element before ELEM in its list. If ELEM is the
+ first element in its list, returns the list head. Results are
+ undefined if ELEM is itself a list head. */
+list_elem *
+list_prev (list_elem *elem)
+{
+ ASSERT (is_interior (elem) || is_tail (elem));
+ return elem->prev;
+}
+
/* Returns LIST's head.
list_rend() is often used in iterating through a list in
/* Returns LIST's head.
list_rend() is often used in iterating through a list in
@@
-123,14
+133,30
@@
list_rend (struct list *list)
return &list->head;
}
return &list->head;
}
-/* Returns the element before ELEM in its list. If ELEM is the
- first element in its list, returns the list head. Results are
- undefined if ELEM is itself a list head. */
+/* Return's LIST's head.
+
+ list_head() can be used for an alternate style of iterating
+ through a list, e.g.:
+
+ e = list_head (&list);
+ while ((e = list_next (e)) != list_end (&list))
+ {
+ ...
+ }
+*/
list_elem *
list_elem *
-list_
prev (list_elem *elem)
+list_
head (struct list *list)
{
{
- ASSERT (is_interior (elem) || is_tail (elem));
- return elem->prev;
+ ASSERT (list != NULL);
+ return &list->head;
+}
+
+/* Return's LIST's tail. */
+list_elem *
+list_tail (struct list *list)
+{
+ ASSERT (list != NULL);
+ return &list->tail;
}
/* Inserts ELEM just before BEFORE, which may be either an
}
/* Inserts ELEM just before BEFORE, which may be either an
diff --git
a/src/lib/list.h
b/src/lib/list.h
index a8086060adafa1872dd16c51cdfad2fdea676238..1bf66312553cc4ec271840f6fb39c287dd7a2735 100644
(file)
--- a/
src/lib/list.h
+++ b/
src/lib/list.h
@@
-89,16
+89,16
@@
/* List element. */
typedef struct list_elem
{
/* List element. */
typedef struct list_elem
{
- struct list_elem *prev;
/* Previous node in lis
t. */
- struct list_elem *next;
/* Next node in lis
t. */
+ struct list_elem *prev;
/* Previous list elemen
t. */
+ struct list_elem *next;
/* Next list elemen
t. */
}
list_elem;
/* List. */
struct list
{
}
list_elem;
/* List. */
struct list
{
- list_elem head;
/* Start-of-list header node
. */
- list_elem tail;
/* End-of-list header node
. */
+ list_elem head;
/* List head
. */
+ list_elem tail;
/* List tail
. */
};
/* Converts pointer to list element LIST_ELEM into a pointer to
};
/* Converts pointer to list element LIST_ELEM into a pointer to
@@
-120,6
+120,9
@@
list_elem *list_rbegin (struct list *);
list_elem *list_prev (list_elem *);
list_elem *list_rend (struct list *);
list_elem *list_prev (list_elem *);
list_elem *list_rend (struct list *);
+list_elem *list_head (struct list *);
+list_elem *list_tail (struct list *);
+
/* List insertion. */
void list_insert (list_elem *, list_elem *);
void list_splice (list_elem *before,
/* List insertion. */
void list_insert (list_elem *, list_elem *);
void list_splice (list_elem *before,