2010-01-14 11:13:48 +00:00
|
|
|
#ifndef _INCLUDE_R_LIST_H_
|
|
|
|
#define _INCLUDE_R_LIST_H_
|
|
|
|
|
2012-07-20 15:14:28 +00:00
|
|
|
#include <r_types.h>
|
2010-06-16 07:42:46 +00:00
|
|
|
#include <r_flist.h>
|
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-08-16 09:24:13 +00:00
|
|
|
// TODO: implement r_list_foreach_prev
|
|
|
|
|
2012-06-07 01:41:21 +00:00
|
|
|
#ifndef _INCLUDE_R_LIST_HEAD_H_
|
|
|
|
#define _INCLUDE_R_LIST_HEAD_H_
|
2010-02-04 12:23:53 +00:00
|
|
|
typedef void (*RListFree)(void *ptr);
|
2010-01-14 11:13:48 +00:00
|
|
|
|
|
|
|
typedef struct r_list_iter_t {
|
2010-01-18 12:45:02 +00:00
|
|
|
void *data;
|
2010-02-15 21:59:26 +00:00
|
|
|
struct r_list_iter_t *n, *p;
|
2010-02-04 12:23:53 +00:00
|
|
|
} RListIter;
|
2010-01-14 11:13:48 +00:00
|
|
|
|
|
|
|
typedef struct r_list_t {
|
2012-08-27 03:59:44 +00:00
|
|
|
RListIter *head;
|
|
|
|
RListIter *tail;
|
2010-02-04 12:23:53 +00:00
|
|
|
RListFree free;
|
|
|
|
} RList;
|
2010-01-14 11:13:48 +00:00
|
|
|
|
2010-07-21 23:14:13 +00:00
|
|
|
typedef int (*RListComparator)(void *a, void *b);
|
|
|
|
|
2010-06-17 22:06:19 +00:00
|
|
|
#define ROFList_Parent RList
|
|
|
|
typedef struct r_oflist_t {
|
|
|
|
ROFList_Parent super; // super class
|
|
|
|
RFList *array; // statical readonly cache of linked list as a pointer array
|
|
|
|
} ROFList;
|
2012-06-07 01:41:21 +00:00
|
|
|
#endif
|
2010-06-16 07:42:46 +00:00
|
|
|
|
2010-02-15 21:59:26 +00:00
|
|
|
#ifdef R_API
|
2012-12-09 00:39:27 +00:00
|
|
|
//#define R_LIST_NEW(x,y) x=r_list_new();x->free=(RListFree)y
|
2010-03-08 11:31:14 +00:00
|
|
|
#define r_list_foreach(list, it, pos) \
|
2011-05-20 20:42:11 +00:00
|
|
|
if (list) for (it = list->head; it && (pos = it->data); it = it->n)
|
2012-02-14 17:10:52 +00:00
|
|
|
/* Safe when calling r_list_delete() while iterating over the list. */
|
|
|
|
#define r_list_foreach_safe(list, it, tmp, pos) \
|
|
|
|
if (list) for (it = list->head; it && (pos = it->data) && ((tmp = it->n) || 1); it = tmp)
|
2010-09-24 14:45:56 +00:00
|
|
|
#define r_list_foreach_prev(list, it, pos) \
|
2012-02-14 17:10:52 +00:00
|
|
|
if (list) for (it = list->tail; it && (pos = it->data); it = it->p)
|
2012-07-20 15:23:24 +00:00
|
|
|
#ifndef _R_LIST_C_
|
|
|
|
#define r_list_push(x,y) r_list_append(x,y)
|
2010-12-17 09:58:38 +00:00
|
|
|
#define r_list_iterator(x) (x)?(x)->head:NULL
|
2011-02-21 17:10:22 +00:00
|
|
|
#define r_list_empty(x) (x==NULL || (x->head==NULL && x->tail==NULL))
|
2010-01-18 12:45:02 +00:00
|
|
|
#define r_list_head(x) x->head
|
|
|
|
#define r_list_tail(x) x->tail
|
2010-03-10 12:23:43 +00:00
|
|
|
#define r_list_unref(x) x
|
2011-10-04 08:10:00 +00:00
|
|
|
|
2010-02-15 21:59:26 +00:00
|
|
|
#define r_list_iter_get(x) x->data; x=x->n
|
2010-01-18 12:45:02 +00:00
|
|
|
#define r_list_iter_next(x) (x?1:0)
|
2011-10-04 08:10:00 +00:00
|
|
|
|
2010-03-03 01:41:41 +00:00
|
|
|
#define r_list_iter_cur(x) x->p
|
2010-03-10 12:23:43 +00:00
|
|
|
#define r_list_iter_unref(x) x
|
2011-09-28 09:50:20 +00:00
|
|
|
#define r_list_iter_free(x) x
|
2012-07-20 15:23:24 +00:00
|
|
|
#endif
|
2011-02-27 19:30:41 +00:00
|
|
|
R_API RList *r_list_new();
|
2012-12-13 17:32:26 +00:00
|
|
|
R_API RList *r_list_newf(RListFree f);
|
2012-09-17 15:49:23 +00:00
|
|
|
//R_API void r_list_iter_free (RListIter *x);
|
2012-06-07 01:41:21 +00:00
|
|
|
R_API RListIter *r_list_iter_get_next(RListIter *list);
|
2013-10-20 00:09:03 +00:00
|
|
|
R_API int r_list_set_n(RList *list, int n, void *p);
|
2012-06-07 01:41:21 +00:00
|
|
|
R_API void *r_list_iter_get_data(RListIter *list);
|
2011-03-23 19:35:40 +00:00
|
|
|
R_API RListIter *r_list_append(RList *list, void *data);
|
|
|
|
R_API RListIter *r_list_prepend(RList *list, void *data);
|
2010-05-21 15:35:05 +00:00
|
|
|
R_API int r_list_length(RList *list);
|
2010-07-21 23:14:13 +00:00
|
|
|
R_API void r_list_add_sorted(RList *list, void *data, RListComparator cmp);
|
|
|
|
R_API void r_list_sort(RList *list, RListComparator cmp);
|
2010-01-14 11:13:48 +00:00
|
|
|
|
2010-02-04 12:23:53 +00:00
|
|
|
R_API void r_list_init(RList *list);
|
2010-02-27 14:56:07 +00:00
|
|
|
R_API void r_list_delete (RList *list, RListIter *iter);
|
2011-03-17 18:05:39 +00:00
|
|
|
R_API boolt r_list_delete_data (RList *list, void *ptr);
|
2010-02-04 12:23:53 +00:00
|
|
|
R_API void r_list_iter_init (RListIter *iter, RList *list);
|
|
|
|
R_API void r_list_destroy (RList *list);
|
2011-11-30 09:27:01 +00:00
|
|
|
R_API void r_list_purge (RList *list);
|
2010-03-10 12:23:43 +00:00
|
|
|
R_API void r_list_free (RList *list);
|
2010-02-04 12:23:53 +00:00
|
|
|
R_API RListIter *r_list_item_new (void *data);
|
|
|
|
R_API void r_list_unlink (RList *list, void *ptr);
|
2010-02-27 14:56:07 +00:00
|
|
|
R_API void r_list_split (RList *list, void *ptr);
|
|
|
|
R_API void r_list_split_iter (RList *list, RListIter *iter);
|
2011-04-24 11:46:28 +00:00
|
|
|
R_API void r_list_join (RList *list1, RList *list2);
|
2011-03-12 14:04:48 +00:00
|
|
|
R_API void *r_list_get_n (RList *list, int n);
|
|
|
|
R_API int r_list_del_n (RList *list, int n);
|
|
|
|
R_API void *r_list_get_top (RList *list);
|
|
|
|
R_API void *r_list_pop (RList *list);
|
|
|
|
R_API void r_list_reverse (RList *list);
|
|
|
|
R_API RList *r_list_clone (RList *list);
|
2010-06-16 07:42:46 +00:00
|
|
|
|
2010-09-01 18:32:24 +00:00
|
|
|
/* hashlike api */
|
|
|
|
R_API void *r_list_get_by_int(RList *list, int off, int n);
|
|
|
|
R_API void *r_list_get_by_int64(RList *list, int off, ut64 n);
|
|
|
|
R_API void *r_list_get_by_string(RList *list, int off, const char *str);
|
2011-11-25 03:32:32 +00:00
|
|
|
R_API RListIter *r_list_contains (RList *list, void *p);
|
2013-11-24 00:44:00 +00:00
|
|
|
R_API RListIter *r_list_find (RList *list, void *p, RListComparator cmp);
|
2010-09-01 18:32:24 +00:00
|
|
|
|
2010-06-16 07:42:46 +00:00
|
|
|
/* rlistflist */
|
2010-06-17 22:06:19 +00:00
|
|
|
// TODO: rename to init or so.. #define r_oflist_new() R_NEW(ROFList);memset
|
|
|
|
#define r_oflist_length(x,y) r_list_length(x,y)
|
|
|
|
#define r_oflist_destroy(x) r_oflist_deserialize(x), r_list_destroy(x)
|
|
|
|
#define r_oflist_free(x) r_oflist_deserialize(x), r_list_free(x)
|
|
|
|
#define r_oflist_append(x,y) r_oflist_deserialize(x), r_list_append(x,y)
|
|
|
|
#define r_oflist_prepend(x,y) r_oflist_deserialize(x), r_list_prepend(x,y)
|
|
|
|
#define r_oflist_delete(x,y) r_oflist_deserialize(x), r_list_delete(x,y)
|
|
|
|
#define r_oflist_array(x) x->array?x->array:(x->array=r_oflist_serialize(x)),x->array
|
|
|
|
#define r_oflist_deserialize(x) \
|
2010-06-16 07:42:46 +00:00
|
|
|
free(x->array-1),x->array=0
|
2010-06-17 22:06:19 +00:00
|
|
|
#define r_oflist_serialize(x) \
|
2010-06-16 07:42:46 +00:00
|
|
|
x->array = r_flist_new(r_list_length(x)), { \
|
|
|
|
int idx = 0; \
|
|
|
|
void *ptr; \
|
|
|
|
RListIter *iter; \
|
|
|
|
r_list_foreach (x, iter, ptr) \
|
|
|
|
r_flist_set (x->array, idx++, ptr); \
|
|
|
|
} x->array;
|
2010-01-14 11:13:48 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-14 11:13:48 +00:00
|
|
|
#endif
|