diff options
author | cathook <cat.hook31894@gmail.com> | 2013-11-26 04:08:59 +0800 |
---|---|---|
committer | cathook <cat.hook31894@gmail.com> | 2013-11-26 14:32:14 +0800 |
commit | e4c361850d46e4ea7f9f2b39c3ae8e2d1b521999 (patch) | |
tree | dab412b01e2501855dbe34be95929c7a5088f26c | |
parent | 5cb2c7120019e90d66efa903e0a14b4ffdd0791a (diff) | |
download | ctl-e4c361850d46e4ea7f9f2b39c3ae8e2d1b521999.tar.gz ctl-e4c361850d46e4ea7f9f2b39c3ae8e2d1b521999.tar.zst ctl-e4c361850d46e4ea7f9f2b39c3ae8e2d1b521999.zip |
add header file
-rw-r--r-- | include/list.h | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/include/list.h b/include/list.h new file mode 100644 index 0000000..58913c4 --- /dev/null +++ b/include/list.h @@ -0,0 +1,186 @@ +#ifndef __list_h__ +#define __list_h__ + +#include "utility.h" + +/**********************************************************/ +/* This object is a double link list. */ +/* methods: */ +/* init(addr of the list, size per entry, list size) */ +/* The list's type depends on what user want to store*/ +/* . For example: if you want a list for int, you s- */ +/* hould declare like "int* v", and call the init() */ +/* like "init(&v, sizeof(int), 5)", which will creat */ +/* a double link list with 5 elements. */ +/* */ +/* free(addr of the list) */ +/* Free the memory the list use. You should call it */ +/* when you don't need the container. */ +/* */ +/* */ +/* getSize(addr of the list) */ +/* Return the number of elements. */ +/* */ +/* getEntrySize(addr of the list) */ +/* Return the size per entry, it dependent on what */ +/* type of data you store in the container. */ +/* */ +/* getFront(addr of the list) */ +/* Return a const pointer which point to the entry */ +/* at the head of the list. */ +/* */ +/* getBack(addr of the list) */ +/* Return a const pointer which point to the entry */ +/* at the end of the list. */ +/* */ +/* getFirst(addr of the list) */ +/* Return a pointer which point to the iterator at */ +/* the head of the list. */ +/* */ +/* getLast(addr of the list) */ +/* Return a pointer which point to the iterator at */ +/* the end of the list. */ +/* */ +/* */ +/* setSize(addr of the list, new_size) */ +/* Resize the lsit to new_size at the back of the */ +/* list. Note that it won't initalize the newly ele- */ +/* ments when you increase the size. */ +/* */ +/* setFront(addr of the list, data) */ +/* Let the first element be the data you given. */ +/* */ +/* setBack(addr of the list, data) */ +/* Let the last element be the data you given. */ +/* */ +/* */ +/* addBack(addr of the list, data) */ +/* Add an element which contain data at the back of */ +/* the list. */ +/* */ +/* delBack(addr of the list) */ +/* Remove the last element of the list. */ +/* */ +/* addFront(addr of the vector, data) */ +/* Add an element which contain data at the front of */ +/* the list. */ +/* */ +/* delFront(addr of the list) */ +/* Remove the first element of the list. */ +/* */ +/* */ +/* cat(addr of the l1, addr of the l2) */ +/* Concatenate the list1 to the back of list2. */ +/* */ +/* copy(addr of the l1, addr of the l2) */ +/* Let the contain in the l1 be the one in the l2 */ +/* */ +/* swap(addr of the iterator i1, i2, j1, j2) */ +/* Connect the i1 to the next element of j1. */ +/* Connect the j1 to the next element of i1. */ +/* Connect the previous element of i2 to j2. */ +/* Connect the previous element of j2 to i2. */ +/* */ +/* replace(addr of the iterator i1, count1, */ +/* addr of the iterator i2, coutn2) */ +/* Let i1, next of i1, next of next of i1, ..... */ +/* (number count1) be i2, next of i2, next of next of*/ +/* i2, ...... (number abs(count2)) */ +/* Note that if count2 < 0, this function will repl- */ +/* ace the data in reverse order. */ +/* */ +/* */ +/* iterGetEntry(addr of the iteator) */ +/* Return a const pointer which point to the data of */ +/* the iterator. */ +/* */ +/* iterGetNext(addr of the iterator) */ +/* Return a pointer which point to the next iterator */ +/* */ +/* iterGetPrev(addr of the iterator) */ +/* Return a pointer which point to the previous ite- */ +/* ator. */ +/* */ +/* */ +/* iterSetEntry(addr of the iterator, data) */ +/* Let the data which is stored in iterator be the */ +/* data you given. */ +/* */ +/* iterGoNext(addr of the iterator) */ +/* Instead of return a pointer, it will change the */ +/* pointer you given. */ +/* */ +/* iterGoPrev(addr of the iterator) */ +/* Instead of return a pointer, it will change the */ +/* pointer you given. */ +/* */ +/**********************************************************/ + +pvoid ctl_list_initX(ppvoid l, size_t size, uint count); +pvoid ctl_list_freeX(ppvoid l); + +int ctl_list_getSizeX (ppcvoid l); +int ctl_list_getEntrySizeX(ppcvoid l); +pcvoid ctl_list_getFrontX (ppcvoid l); +pcvoid ctl_list_getBackX (ppcvoid l); +pvoid ctl_list_getFirstX (ppcvoid l); +pvoid ctl_list_getLastX (ppcvoid l); + +int ctl_list_setSizeX (ppvoid l); +pvoid ctl_list_setFrontX(ppvoid l, pcvoid data); +pvoid ctl_list_setBackX (ppvoid l, pcvoid data); + +int ctl_list_addFrontX(ppvoid l, pcvoid data); +int ctl_list_delFrontX(ppvoid l, pcvoid data); +int ctl_list_addBackX (ppvoid l, pcvoid data); +int ctl_list_delBackX (ppvoid l, pcvoid data); + +int ctl_list_catX (ppvoid l, ppcvoid l2); +pvoid ctl_list_copyX (ppvoid l, ppcvoid l2); +int ctl_list_replaceX(ppvoid i1, uint ct1, ppcvoid j1, int ct2); +void ctl_list_swapX (ppvoid i1, ppvoid i2, ppvoid j1, ppvoid j2); + +pcvoid ctl_list_iterGetEntryX(ppcvoid i); +pvoid ctl_list_iterGetNextX (ppcvoid i); +pvoid ctl_list_iterGetPrevX (ppcvoid i); + +pvoid ctl_list_iterSetEntryX(ppvoid i, pcvoid *data); + +pvoid ctl_list_iterGoNextX(ppcvoid i); +pvoid ctl_list_iterGoPrevX(ppcvoid i); + + +#define ctl_list_init(X,Y,Z) ctl_list_initX(ppVoid(X),Y,Z) +#define ctl_list_free(X) ctl_list_freeX(ppVoid(X)) + +#define ctl_list_getSize(X) ctl_list_getSizeX (ppcVoid(X)) +#define ctl_list_getEntrySize(X) ctl_list_getEntrySizeX(ppcVoid(X)) +#define ctl_list_getFront(X) ctl_list_getFrontX (ppcVoid(X)) +#define ctl_list_getBack(X) ctl_list_getBackX (ppcVoid(X)) +#define ctl_list_getFirst(X) ctl_list_getFirstX (ppcVoid(X)) +#define ctl_list_getLast(X) ctl_list_getLastX (ppcVoid(X)) + +#define ctl_list_setSize(X) ctl_list_setSizeX (ppVoid(l)) +#define ctl_list_setFront(X,Y) ctl_list_setFrontX(ppVoid(X),pcVoid(Y)) +#define ctl_list_setBack(X,Y) ctl_list_setBackX (ppVoid(X),pcVoid(Y)) + +#define ctl_list_addFront(X,Y) ctl_list_addFrontX(ppVoid(l),pcVoid(Y)) +#define ctl_list_delFront(X,Y) ctl_list_delFrontX(ppVoid(l),pcVoid(Y)) +#define ctl_list_addBack(X,Y) ctl_list_addBackX (ppVoid(l),pcVoid(Y)) +#define ctl_list_delBack(X,Y) ctl_list_delBackX (ppVoid(l),pcVoid(Y)) + +#define ctl_list_cat(X,Y) ctl_list_catX (ppVoid(X),ppcVoid(Y)) +#define ctl_list_copy(X,Y) ctl_list_copyX(ppVoid(X),ppcVoid(Y)) +#define ctl_list_replace(X,Y,Z,A) ctl_list_replaceX(ppVoid(X),Y,ppcVoid(Z),A) +#define ctl_list_swap(X,Y,Z,A) ctl_list_swapX(ppVoid(X),ppVoid(Y),ppVoid(Z),ppVoid(A)) + +#define ctl_list_iterGetEntry(X) ctl_list_iterGetEntryX(ppcVoid(X)) +#define ctl_list_iterGetNext(X) ctl_list_iterGetNextX (ppcVoid(X)) +#define ctl_list_iterGetPrev(X) ctl_list_iterGetPrevX (ppcVoid(X)) + +#define ctl_list_iterSetEntry(X,Y) ctl_list_iterSetEntryX(ppVoid(X),pcVoid(Y)) + +#define ctl_list_iterGoNext(X) ctl_list_iterGoNextX(ppcVoid(X)) +#define ctl_list_iterGoPrev(X) ctl_list_iterGoPrevX(ppcVoid(X)) + +#endif /* __list_h__ */ |