forked from andbof/yastg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptrlist.h
38 lines (31 loc) · 1.1 KB
/
ptrlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _HAS_PTRLIST_H
#define _HAS_PTRLIST_H
#include "list.h"
struct ptrlist {
void *data;
struct list_head list;
unsigned long len;
};
int ptrlist_init(struct ptrlist *l);
void ptrlist_free(struct ptrlist *l);
int ptrlist_push(struct ptrlist *l, void *e);
void* ptrlist_pull(struct ptrlist * const l);
struct ptrlist* ptrlist_get(const struct ptrlist * const l, const unsigned long n);
void* ptrlist_entry(const struct ptrlist * const l, const unsigned long n);
unsigned long ptrlist_len(const struct ptrlist * const l);
void* ptrlist_random(const struct ptrlist * const l);
void ptrlist_rm(struct ptrlist *l, const unsigned long n);
void ptrlist_sort(struct ptrlist * const l, void *data,
int (*cmp)(const void*, const void*, void*));
#define ptrlist_data(pos) \
list_entry((pos), struct ptrlist, list)->data
/*
* @iter: variable used as iterator
* @head: struct list_head of the list
* @pos: junk list_head
*/
#define ptrlist_for_each_entry(iter, head, pos) \
for (pos = (head)->list.next, (iter) = ptrlist_data(pos); \
pos != &(head)->list; \
pos = pos->next, (iter) = ptrlist_data(pos))
#endif