2
Copyright (C) 2010, Parrot Foundation.
6
src/list.c - Implementation of double linked lists.
10
This code implements double linked list of GCable objects.
16
#include "parrot/parrot.h"
17
#include "parrot/list.h"
19
/* HEADERIZER HFILE: include/parrot/list.h */
21
/* HEADERIZER BEGIN: static */
22
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
24
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
25
/* HEADERIZER END: static */
31
=item C<struct Linked_List* Parrot_list_new(PARROT_INTERP)>
33
Allocate a doubly link list
40
PARROT_CANNOT_RETURN_NULL
42
Parrot_list_new(SHIM_INTERP)
44
ASSERT_ARGS(Parrot_list_new)
46
Linked_List * const res = (Linked_List*)mem_sys_allocate_zeroed(sizeof (Linked_List));
52
=item C<void Parrot_list_destroy(PARROT_INTERP, Linked_List* list)>
54
Destroy the specified list (free up memory associated with the list)
62
Parrot_list_destroy(SHIM_INTERP, ARGMOD(Linked_List* list))
64
ASSERT_ARGS(Parrot_list_destroy)
71
=item C<void Parrot_list_append(PARROT_INTERP, Linked_List *list,
72
List_Item_Header *item)>
74
Append an item to the list
82
Parrot_list_append(SHIM_INTERP, ARGMOD(Linked_List *list), ARGMOD(List_Item_Header *item))
84
ASSERT_ARGS(Parrot_list_append)
86
item->prev = item->next = NULL;
89
item->prev = list->last;
90
list->last->next = item;
106
=item C<List_Item_Header* Parrot_list_remove(PARROT_INTERP, Linked_List *list,
107
List_Item_Header *item)>
109
Remove an item from the list, returning the (pointer to) item
116
PARROT_CAN_RETURN_NULL
118
Parrot_list_remove(SHIM_INTERP, ARGMOD(Linked_List *list), ARGMOD(List_Item_Header *item))
120
ASSERT_ARGS(Parrot_list_remove)
122
List_Item_Header * const next = item->next;
123
List_Item_Header * const prev = item->prev;
125
PARROT_ASSERT(list == item->owner);
128
if (list->first == item)
131
if (list->last == item)
145
=item C<List_Item_Header* Parrot_list_pop(PARROT_INTERP, Linked_List *list)>
147
Pop an item off the list - i.e. get the first item in the list and remove it.
154
PARROT_CAN_RETURN_NULL
156
Parrot_list_pop(SHIM_INTERP, ARGIN(Linked_List *list))
158
ASSERT_ARGS(Parrot_list_pop)
160
List_Item_Header * const ret = list->first;
162
LIST_REMOVE(list, ret);
168
=item C<INTVAL Parrot_list_check(PARROT_INTERP, const Linked_List *list)>
170
Check the validity of the list
177
PARROT_CONST_FUNCTION
179
Parrot_list_check(SHIM_INTERP, ARGIN(const Linked_List *list))
181
ASSERT_ARGS(Parrot_list_check)
183
const List_Item_Header *tmp = list->first;
187
List_Item_Header *next = tmp->next;
188
PARROT_ASSERT(tmp->owner == list);
191
PARROT_ASSERT(counter <= list->count);
199
=item C<INTVAL Parrot_list_contains(PARROT_INTERP, const Linked_List *list,
200
const List_Item_Header *item)>
202
Returns True if the is in the list
211
Parrot_list_contains(SHIM_INTERP,
212
ARGIN(const Linked_List *list), ARGIN(const List_Item_Header *item))
214
ASSERT_ARGS(Parrot_list_contains)
216
const List_Item_Header *tmp = list->first;
219
if (item->owner != list)
242
* c-file-style: "parrot"
244
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :