Subset of the Linux 's list implementation.
To use it, #include <listx.h>"
.
Data nodes in an listx are structures containing a struct list_head member:
typedef struct mydata {
struct list_head node;
int key;
char attr_a;
char attr_b;
char attr_c;
char attr_d;
} mydata_t;
At the head of each listx is an list_head structure, which is initialized to be empty via:
struct list_head mylist = LIST_HEAD_INIT(mylist);
// or define and init
LIST_HEAD(mylist)
mydata_t *search(int key, struct list_head *head) {
mydata_t *data;
list_for_each_entry(data, head, node) {
if (data->key == key)
return data;
}
return NULL;
}
void insert(mydata_t *newdata, struct list_head *head) {
list_add(&newdata->node, head);
}
void delete(mydata_t *olddata) {
list_del(&olddata->node);
}
void replace(mydata_t *olddata, mydata_t *newdata) {
list_replace(&olddata->node, &olddata->node);
}
mkdir build
cd build
cmake ..
make install
make uninstall
Linux Source
Linux List include/linux/list.h