Commit deffba65 authored by Chris Müller's avatar Chris Müller

Add List modifier (swap, replace, remove) to struct CryList*.

parent 67493c26
......@@ -164,6 +164,24 @@ cry_list_end(struct CryList* list)
}
struct CryPosition*
cry_list_index(struct CryList* list, size_t index)
{
assert(list != 0);
struct Node* node = list->head;
while(node != 0 && index > 0) {
node = node->next;
--index;
}
return cry_cast(struct CryPosition*, node);
}
struct CryPosition*
cry_list_next(struct CryPosition* position)
{
......@@ -183,6 +201,26 @@ cry_list_prev(struct CryPosition* position)
}
struct CryPosition*
cry_list_step(struct CryPosition* position, int index)
{
assert(position != 0);
struct Node* node = cry_cast(struct Node*, position);
while(node != 0 && index != 0) {
if(index < 0) {
node = node->prev;
++index;
} else {
node = node->next;
--index;
}
}
return cry_cast(struct CryPosition*, node);
}
pointer
cry_list_data(struct CryPosition* position)
......@@ -223,6 +261,10 @@ cry_list_remove(struct CryList* list, struct CryPosition* position)
else
list->tail = node->prev;
cry_free(node);
return data;
}
......@@ -36,9 +36,11 @@ 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_index(struct CryList* list, size_t index);
struct CryPosition* cry_list_next(struct CryPosition* position);
struct CryPosition* cry_list_prev(struct CryPosition* position);
struct CryPosition* cry_list_step(struct CryPosition* position, int steps);
pointer cry_list_data(struct CryPosition* position);
pointer cry_list_swap(struct CryPosition* position, pointer new_data);
......
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