Rizin
unix-like reverse engineering framework and cli tools
ls.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: MIT
3 
4 #ifndef LS_H
5 #define LS_H
6 
7 #include <stdio.h>
8 #include <rz_types.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 typedef void (*SdbListFree)(void *ptr);
15 typedef int (*SdbListComparator)(const void *a, const void *b);
16 
17 typedef struct ls_iter_t {
18  void *data;
19  struct ls_iter_t *n, *p;
21 
22 typedef struct ls_t {
23  size_t length;
28  bool sorted;
30 
31 #define ls_foreach(list, it, pos) \
32  if ((list)) \
33  for (it = (list)->head; it && (pos = it->data); it = it->n)
34 #define ls_foreach_safe(list, it, tmp, pos) \
35  if ((list)) \
36  for (it = list->head; \
37  it && (pos = it->data) && ((tmp = it->n) || 1); it = tmp)
38 #define ls_foreach_prev(list, it, pos) \
39  if ((list)) \
40  for (it = list->tail; it && (pos = it->data); it = it->p)
41 
42 #define ls_iterator(x) (x) ? (x)->head : NULL
43 // #define ls_empty(x) (!x || (!x->head && !x->tail))
44 #define ls_empty(x) (!x || !x->length)
45 #define ls_head(x) x->head
46 #define ls_tail(x) x->tail
47 #define ls_unref(x) x
48 #define ls_iter_get(x) \
49  x->data; \
50  x = x->n
51 #define ls_iter_next(x) (x ? 1 : 0)
52 #define ls_iter_cur(x) x->p
53 #define ls_iter_unref(x) x
54 #define ls_length(x) x->length
55 RZ_API SdbList *ls_new(void);
57 RZ_API SdbListIter *ls_append(SdbList *list, void *data);
59 // RZ_API void ls_add_sorted(SdbList *list, void *data, SdbListComparator cmp);
62 
64 RZ_API bool ls_delete_data(SdbList *list, void *ptr);
67 RZ_API void ls_free(SdbList *list);
69 RZ_API void ls_unlink(SdbList *list, void *ptr);
70 RZ_API void ls_split(SdbList *list, void *ptr);
71 // Removes element `iter` from `list`.
73 RZ_API void *ls_get_n(SdbList *list, int n);
75 #define ls_push(x, y) ls_append(x, y)
76 RZ_API void *ls_pop(SdbList *list);
79 RZ_API int ls_join(SdbList *first, SdbList *second);
80 RZ_API int ls_del_n(SdbList *list, int n);
81 RZ_API SdbListIter *ls_insert(SdbList *list, int n, void *data);
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
#define RZ_API
static void freefn(HtName_(Ht) *ht, HT_(Kv) *kv)
Definition: ht_inc.c:46
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API void ls_split_iter(SdbList *list, SdbListIter *iter)
Definition: ls.c:157
RZ_API void * ls_pop_head(SdbList *list)
Definition: ls.c:332
RZ_API void ls_split(SdbList *list, void *ptr)
RZ_API void ls_reverse(SdbList *list)
RZ_API SdbList * ls_new(void)
Definition: ls.c:16
RZ_API void ls_destroy(SdbList *list)
Definition: ls.c:176
int(* SdbListComparator)(const void *a, const void *b)
Definition: ls.h:15
RZ_API bool ls_delete_data(SdbList *list, void *ptr)
Definition: ls.c:145
RZ_API SdbListIter * ls_append(SdbList *list, void *data)
Definition: ls.c:200
void(* SdbListFree)(void *ptr)
Definition: ls.h:14
RZ_API SdbListIter * ls_prepend(SdbList *list, void *data)
Definition: ls.c:224
RZ_API void * ls_pop(SdbList *list)
Definition: ls.c:244
RZ_API void * ls_get_top(SdbList *list)
RZ_API void ls_free(SdbList *list)
Definition: ls.c:191
RZ_API SdbListIter * ls_insert(SdbList *list, int n, void *data)
Definition: ls.c:303
struct ls_iter_t SdbListIter
RZ_API int ls_join(SdbList *first, SdbList *second)
Definition: ls.c:281
struct ls_t SdbList
RZ_API void * ls_get_n(SdbList *list, int n)
RZ_API void ls_iter_init(SdbListIter *iter, SdbList *list)
RZ_API int ls_del_n(SdbList *list, int n)
Definition: ls.c:353
RZ_API bool ls_merge_sort(SdbList *list, SdbListComparator cmp)
Definition: ls.c:101
RZ_API SdbList * ls_clone(SdbList *list)
Definition: ls.c:265
RZ_API bool ls_sort(SdbList *list, SdbListComparator cmp)
Definition: ls.c:119
RZ_API void ls_delete(SdbList *list, SdbListIter *iter)
Definition: ls.c:133
RZ_API SdbListIter * ls_item_new(void *data)
RZ_API SdbList * ls_newf(SdbListFree freefn)
Definition: ls.c:8
RZ_API void ls_unlink(SdbList *list, void *ptr)
int n
Definition: mipsasm.c:19
static int
Definition: sfsocketcall.h:114
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
Definition: ls.h:17
struct ls_iter_t * n
Definition: ls.h:19
void * data
Definition: ls.h:18
struct ls_iter_t * p
Definition: ls.h:19
Definition: ls.h:22
SdbListComparator cmp
Definition: ls.h:27
SdbListIter * head
Definition: ls.h:24
size_t length
Definition: ls.h:23
SdbListIter * tail
Definition: ls.h:25
bool sorted
Definition: ls.h:28
SdbListFree free
Definition: ls.h:26