forked from gatsby/df_datalink
119 lines
1.8 KiB
C
119 lines
1.8 KiB
C
|
|
//
|
|
// clist.h
|
|
//
|
|
// Copyright (c) 2010 TJ Holowaychuk <[email protected]>
|
|
//
|
|
|
|
#ifndef __CLIST_H__
|
|
#define __CLIST_H__
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
|
|
/*
|
|
* clist_t iterator direction.
|
|
*/
|
|
|
|
typedef enum
|
|
{
|
|
LIST_HEAD,
|
|
LIST_TAIL
|
|
} clist_direction_t;
|
|
|
|
/*
|
|
* clist_t node struct.
|
|
*/
|
|
|
|
typedef struct clist_node
|
|
{
|
|
struct clist_node *prev;
|
|
struct clist_node *next;
|
|
void *val;
|
|
} clist_node_t;
|
|
|
|
/*
|
|
* clist_t struct.
|
|
*/
|
|
|
|
typedef struct
|
|
{
|
|
clist_node_t *head;
|
|
clist_node_t *tail;
|
|
uint32_t len;
|
|
void (*free)(void *val);
|
|
int8_t (*compare)(void *a, void *b);
|
|
} clist_t;
|
|
|
|
/*
|
|
* clist_t iterator struct.
|
|
*/
|
|
|
|
typedef struct
|
|
{
|
|
clist_node_t *next;
|
|
clist_direction_t direction;
|
|
} clist_iterator_t;
|
|
|
|
// Node prototypes.
|
|
|
|
clist_node_t *
|
|
clist_node_new(void *val);
|
|
|
|
// clist_t prototypes.
|
|
|
|
clist_t *
|
|
clist_new(void);
|
|
|
|
clist_node_t *
|
|
clist_rpush(clist_t *self, clist_node_t *node);
|
|
|
|
clist_node_t *
|
|
clist_lpush(clist_t *self, clist_node_t *node);
|
|
|
|
clist_node_t *
|
|
clist_find(clist_t *self, void *val);
|
|
|
|
clist_node_t *
|
|
clist_at(clist_t *self, int index);
|
|
|
|
clist_node_t *
|
|
clist_rpop(clist_t *self);
|
|
|
|
clist_node_t *
|
|
clist_lpop(clist_t *self);
|
|
|
|
void
|
|
clist_remove(clist_t *self, clist_node_t *node);
|
|
|
|
void
|
|
clist_clear(clist_t *self);
|
|
|
|
void
|
|
clist_destroy(clist_t *self);
|
|
|
|
// clist_t iterator prototypes.
|
|
|
|
clist_iterator_t *
|
|
clist_iterator_new(clist_t *list, clist_direction_t direction);
|
|
|
|
clist_iterator_t *
|
|
clist_iterator_new_from_node(clist_node_t *node, clist_direction_t direction);
|
|
|
|
clist_node_t *
|
|
clist_iterator_next(clist_iterator_t *self);
|
|
|
|
void
|
|
clist_iterator_destroy(clist_iterator_t *self);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __CLIBS_LIST_H__ */
|