Rizin
unix-like reverse engineering framework and cli tools
rz_list.h
Go to the documentation of this file.
1 #ifndef RZ_LIST_H
2 #define RZ_LIST_H
3 
4 #include <rz_types.h>
5 #include <ht_pp.h>
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 typedef void (*RzListFree)(void *ptr);
12 
13 typedef struct rz_list_iter_t {
14  void *data;
15  struct rz_list_iter_t *n, *p;
17 
18 typedef struct rz_list_t {
23  bool sorted;
25 
26 typedef struct rz_list_range_t {
27  HtPP *h;
29  // RzListComparator c;
31 
32 // RzListComparator should return -1, 0, 1 to indicate "value < list_data", "value == list_data", "value > list_data".
33 typedef int (*RzListComparator)(const void *value, const void *list_data);
34 
35 #ifdef RZ_API
36 
37 #define rz_list_foreach(list, it, pos) \
38  if (list) \
39  for (it = list->head; it && (pos = it->data, 1); it = it->n)
40 #define rz_list_foreach_iter(list, it) \
41  if (list) \
42  for (it = list->head; it; it = it->n)
43 /* Safe when calling rz_list_delete() while iterating over the list. */
44 #define rz_list_foreach_safe(list, it, tmp, pos) \
45  if (list) \
46  for (it = list->head; it && (pos = it->data, tmp = it->n, 1); it = tmp)
47 #define rz_list_foreach_prev(list, it, pos) \
48  if (list) \
49  for (it = list->tail; it && (pos = it->data, 1); it = it->p)
50 #define rz_list_foreach_prev_safe(list, it, tmp, pos) \
51  for (it = list->tail; it && (pos = it->data, tmp = it->p, 1); it = tmp)
52 
53 #define rz_list_empty(x) (!(x) || !(x)->length)
54 #define rz_list_head(x) ((x) ? (x)->head : NULL)
55 #define rz_list_tail(x) ((x) ? (x)->tail : NULL)
56 
57 #define rz_list_iter_get(x) \
58  x->data; \
59  x = x->n
60 #define rz_list_iter_next(x) (x ? 1 : 0)
61 #define rz_list_iter_cur(x) x->p
62 
65 RZ_API RZ_OWN RzList *rz_list_new_from_array(RZ_NONNULL const void **arr, size_t arr_size);
87 RZ_API void rz_list_split(RZ_NONNULL RzList *list, void *ptr);
102 
103 /* hashlike api */
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif
113 #endif
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
static int value
Definition: cmd_api.c:93
#define RZ_API
uint32_t ut32
void * p
Definition: libc.cpp:67
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_BORROW RzListIter * rz_list_iter_get_next(RzListIter *list)
returns the next RzList iterator in the list
Definition: list.c:20
RZ_API void rz_list_insertion_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Insertion sorts the list via the RzListComparator.
Definition: list.c:718
RZ_API RZ_BORROW void * rz_list_iter_get_next_data(RzListIter *list)
returns the value stored in the next RzList iterator
Definition: list.c:29
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
Definition: list.c:620
RZ_API RZ_BORROW RzListIter * rz_list_contains(RZ_NONNULL const RzList *list, RZ_NONNULL const void *ptr)
Returns the RzListIter of the given pointer, if found.
Definition: list.c:592
RZ_API RZ_OWN RzList * rz_list_uniq(RZ_NONNULL const RzList *list, RZ_NONNULL RzListComparator cmp)
Returns a new RzList which contains only unique values.
Definition: list.c:756
RZ_API RZ_BORROW RzListIter * rz_list_prepend(RZ_NONNULL RzList *list, void *data)
Appends at the beginning of the list a new element.
Definition: list.c:316
RZ_API void rz_list_split(RZ_NONNULL RzList *list, void *ptr)
Definition: list.c:172
RZ_API RZ_BORROW RzListIter * rz_list_iterator(const RzList *list)
returns the first RzList iterator int the list
Definition: list.c:51
RZ_API RZ_BORROW RzListIter * rz_list_insert(RZ_NONNULL RzList *list, ut32 n, void *data)
Inserts a new element at the N-th position.
Definition: list.c:342
RZ_API void rz_list_reverse(RZ_NONNULL RzList *list)
Reverses the list.
Definition: list.c:477
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_find_ptr(RZ_NONNULL const RzList *list, RZ_NONNULL const void *ptr)
Returns the RzListIter of the given pointer, if found.
Definition: list.c:600
RZ_API void rz_list_merge_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Merge sorts the list via the RzListComparator.
Definition: list.c:698
RZ_API RZ_BORROW void * rz_list_get_bottom(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:467
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
RZ_API RZ_OWN RzList * rz_list_clone(RZ_NONNULL const RzList *list)
Shallow copies of the list (but doesn't free its elements)
Definition: list.c:496
RZ_API RZ_OWN RzList * rz_list_new_from_array(RZ_NONNULL const void **arr, size_t arr_size)
Allocates a new RzList and adds an array elements to it.
Definition: list.c:260
RZ_API void * rz_list_iter_get_data(RzListIter *list)
returns the value stored in the list element
Definition: list.c:42
RZ_API bool rz_list_delete_data(RZ_NONNULL RzList *list, void *ptr)
Deletes an entry in the list by searching for a pointer.
Definition: list.c:148
RZ_API RZ_BORROW void * rz_list_get_top(RZ_NONNULL const RzList *list)
Returns the last element of the list.
Definition: list.c:457
RZ_API RZ_OWN void * rz_list_pop(RZ_NONNULL RzList *list)
Removes and returns the last element of the list.
Definition: list.c:376
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_OWN RzList * rz_list_of_sdblist(SdbList *sl)
Converts a SdbList into a RzList.
Definition: list.c:802
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
Definition: list.c:743
RZ_API RZ_OWN char * rz_list_to_str(RZ_NONNULL RzList *list, char ch)
Casts a RzList containg strings into a concatenated string.
Definition: list.c:785
RZ_API ut32 rz_list_del_n(RZ_NONNULL RzList *list, ut32 n)
Removes the N-th element of the list.
Definition: list.c:425
RZ_API RZ_OWN RzListIter * rz_list_item_new(void *data)
Creates a RzListIter element that can be inserted into a RzList.
Definition: list.c:276
RZ_API ut32 rz_list_set_n(RZ_NONNULL RzList *list, ut32 n, void *p)
Sets the N-th element of the list.
Definition: list.c:552
RZ_API bool rz_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2)
Joins 2 list into one (list2 pointer needs to be freed by the user)
Definition: list.c:209
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:77
RZ_API RZ_BORROW void * rz_list_last(RZ_NONNULL const RzList *list)
Returns the last element of the list.
Definition: list.c:86
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
RZ_API RZ_OWN void * rz_list_pop_head(RZ_NONNULL RzList *list)
Removes and returns the first element of the list.
Definition: list.c:401
RZ_API void rz_list_split_iter(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Definition: list.c:187
RZ_API void rz_list_init(RZ_NONNULL RzList *list)
Initializes the RzList pointer.
Definition: list.c:95
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API RZ_BORROW RzListIter * rz_list_add_sorted(RZ_NONNULL RzList *list, void *data, RZ_NONNULL RzListComparator cmp)
Adds an element to a sorted list via the RzListComparator.
Definition: list.c:518
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
int n
Definition: mipsasm.c:19
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
int(* RzListComparator)(const void *value, const void *list_data)
Definition: rz_list.h:33
struct rz_list_t RzList
struct rz_list_range_t RzListRange
struct rz_list_iter_t RzListIter
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
static int
Definition: sfsocketcall.h:114
#define f(i)
Definition: sha256.c:46
Definition: ls.h:22
struct rz_list_iter_t * n
Definition: rz_list.h:15
void * data
Definition: rz_list.h:14
struct rz_list_iter_t * p
Definition: rz_list.h:15
HtPP * h
Definition: rz_list.h:27
RzList * l
Definition: rz_list.h:28
RzListIter * head
Definition: rz_list.h:19
RzListFree free
Definition: rz_list.h:21
RzListIter * tail
Definition: rz_list.h:20
bool sorted
Definition: rz_list.h:23
ut32 length
Definition: rz_list.h:22