forked from andbof/yastg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptrlist.h
More file actions
55 lines (44 loc) · 1.26 KB
/
ptrlist.h
File metadata and controls
55 lines (44 loc) · 1.26 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _HAS_PTRLIST_H
#define _HAS_PTRLIST_H
#include <stdio.h>
#include "list.h"
#include "mtrandom.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);
void ptrlist_rm(struct ptrlist *l, const unsigned long n);
static inline unsigned long ptrlist_len(const struct ptrlist * const l)
{
return l->len;
}
static inline int ptrlist_empty(const struct ptrlist * const l)
{
if (l->len)
return 0;
else
return 1;
}
static inline void* ptrlist_random(const struct ptrlist * const l)
{
return ptrlist_entry(l, mtrandom_ulong(ptrlist_len(l)));
}
#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