2011-11-29 09:28:55 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
|
|
|
* General-purpose list implementations.
|
|
|
|
*/
|
2011-11-29 12:49:19 +04:00
|
|
|
#ifndef LIST_H
|
|
|
|
#define LIST_H
|
|
|
|
|
2011-11-29 09:28:55 +04:00
|
|
|
#include <system.h>
|
|
|
|
|
|
|
|
typedef struct node {
|
|
|
|
struct node * next;
|
|
|
|
struct node * prev;
|
|
|
|
void * value;
|
2011-11-29 23:07:59 +04:00
|
|
|
} __attribute__((packed)) node_t;
|
2011-11-29 09:28:55 +04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
node_t * head;
|
|
|
|
node_t * tail;
|
|
|
|
size_t length;
|
2011-11-29 23:07:59 +04:00
|
|
|
} __attribute__((packed)) list_t;
|
2011-11-29 09:28:55 +04:00
|
|
|
|
|
|
|
void list_destroy(list_t * list);
|
|
|
|
void list_free(list_t * list);
|
2011-11-29 16:52:26 +04:00
|
|
|
void list_append(list_t * list, node_t * item);
|
2011-11-29 09:28:55 +04:00
|
|
|
void list_insert(list_t * list, void * item);
|
|
|
|
list_t * list_create();
|
2011-11-29 12:49:19 +04:00
|
|
|
node_t * list_find(list_t * list, void * value);
|
2011-11-29 09:28:55 +04:00
|
|
|
void list_remove(list_t * list, size_t index);
|
|
|
|
void list_delete(list_t * list, node_t * node);
|
2011-11-29 23:07:59 +04:00
|
|
|
node_t * list_pop(list_t * list);
|
2011-12-09 01:25:48 +04:00
|
|
|
node_t * list_dequeue(list_t * list);
|
2011-11-29 09:28:55 +04:00
|
|
|
list_t * list_copy(list_t * original);
|
2011-11-29 16:52:26 +04:00
|
|
|
void list_merge(list_t * target, list_t * source);
|
2011-11-29 09:45:33 +04:00
|
|
|
|
|
|
|
#define foreach(i, list) for (node_t * i = list->head; i != NULL; i = i->next)
|
2011-11-29 12:49:19 +04:00
|
|
|
|
|
|
|
#endif
|