Commit 0ab5f72a authored by Chris Müller's avatar Chris Müller

Add struct CryPosition* for lists and some other functions.

parent c40139fb
......@@ -146,3 +146,83 @@ cry_list_prepend(struct CryList* list, pointer data)
struct CryPosition*
cry_list_begin(struct CryList* list)
{
assert(list != 0);
return cry_cast(struct CryPosition*, list->head);
}
struct CryPosition*
cry_list_end(struct CryList* list)
{
assert(list != 0);
return cry_cast(struct CryPosition*, list->tail);
}
struct CryPosition*
cry_list_next(struct CryPosition* position)
{
assert(position != 0);
return cry_cast(struct CryPosition*, cry_cast(struct Node*, position)->next);
}
struct CryPosition*
cry_list_prev(struct CryPosition* position)
{
assert(position != 0);
return cry_cast(struct CryPosition*, cry_cast(struct Node*, position)->prev);
}
pointer
cry_list_data(struct CryPosition* position)
{
assert(position != 0);
return cry_cast(struct Node*, position)->data;
}
pointer
cry_list_swap(struct CryPosition* position, pointer new_data)
{
struct Node* node = cry_cast(struct Node*, position);
pointer tmp = node->data;
node->data = new_data;
return tmp;
}
pointer
cry_list_remove(struct CryList* list, struct CryPosition* position)
{
assert(list != 0);
assert(position != 0);
struct Node* node = cry_cast(struct Node*, position);
pointer data = node->data;
if(node->prev != 0)
node->prev->next = node->next;
else
list->head = node->next;
if(node->next != 0)
node->next->prev = node->prev;
else
list->tail = node->prev;
return data;
}
......@@ -21,6 +21,7 @@
#include "structures.h"
struct CryPosition;
struct CryList;
struct CryList* cry_list_new(void);
......@@ -33,7 +34,15 @@ pointer cry_list_tail(struct CryList* list);
void cry_list_append(struct CryList* list, pointer data);
void cry_list_prepend(struct CryList* list, pointer data);
struct CryPosition* cry_list_begin(struct CryList* list);
struct CryPosition* cry_list_end(struct CryList* list);
struct CryPosition* cry_list_next(struct CryPosition* position);
struct CryPosition* cry_list_prev(struct CryPosition* position);
pointer cry_list_data(struct CryPosition* position);
pointer cry_list_swap(struct CryPosition* position, pointer new_data);
pointer cry_list_remove(struct CryList* list, struct CryPosition* position);
/*
struct CryList* cry_list_filter(struct CryList* list, cry_predicate_function predicate, pointer context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment