diff options
Diffstat (limited to 'include/vector.h')
-rw-r--r-- | include/vector.h | 118 |
1 files changed, 100 insertions, 18 deletions
diff --git a/include/vector.h b/include/vector.h index b665df0..6dcc244 100644 --- a/include/vector.h +++ b/include/vector.h @@ -3,30 +3,112 @@ #include "utility.h" -void* ctl_vector_initX(void** ptr, size_t size, uint init_count); -void* ctl_vector_freeX(void** ptr); +/**********************************************************/ +/* This object is an array with dynamic table size. */ +/* methods: */ +/* init(addr of the vector, size per entry, size) */ +/* The vector's type depends on what user want to */ +/* store. For example: if you want an array for int, */ +/* you should decleare like "int* v", and call the */ +/* init() like this "init(&v, sizeof(int), 5)", and */ +/* it will initalize an array with 5 elements. */ +/* */ +/* free(addr of the vector) */ +/* Free the memory the vector use. Yous should call */ +/* it when you don't need the container. */ +/* */ +/* */ +/* getSize(addr of the vector) */ +/* Return the number of elements. */ +/* */ +/* getEntrySize(addr of the vector) */ +/* Return the size per entry, it dependent on what */ +/* type of data you store in the container. */ +/* */ +/* getEntry(addr of the vector, index) */ +/* Return a const pointer which point to the entry */ +/* with the index you give. */ +/* */ +/* */ +/* setSize(addr of the vector, new_size) */ +/* Resize the table to new_size. Note that it won't */ +/* initalize the newly element if you increase size. */ +/* */ +/* setEntry(addr of the vector, index, data) */ +/* Let the element with index you give be data. */ +/* */ +/* */ +/* addBack(addr of the vector, data) */ +/* Add an element which contain data at the back of */ +/* the vector. */ +/* */ +/* delBack(addr of the vector) */ +/* Remove the last element of the vector. */ +/* */ +/* addFront(addr of the vector, data) !! UNFINISHED !! */ +/* Add an element which contain data at the front of */ +/* the vector. */ +/* */ +/* delFront(addr of the vector) !! UNFINISHED !! */ +/* Remove the first element of the vector. */ +/* */ +/* */ +/* cat(addr of the v1, addr of the v2) */ +/* Concatenate the vector2 to the back of vector1. */ +/* */ +/* copy(addr of the v1, addr of the v2) */ +/* Let the contain in the v1 be the one in the v2 */ +/* */ +/* replace(addr of the v1, a, b, addr of the v2, x, y) */ +/* If b == 0, it will insert v2[x ... x+y-1] into */ +/* the place between v[a] */ +/* and v[a-1] */ +/* If y >= 0, it will replace v1[a ... a+b-1] */ +/* to v2[x ... x+y-1] */ +/* If y < 0, it will replace v1[a ... a+b-1] */ +/* to v2[x-y-1 ... x] with */ +/* reverse order. */ +/* */ +/**********************************************************/ -int ctl_vector_addBackX(void** ptr, void* entry); -int ctl_vector_delBackX(void** ptr); +pvoid ctl_vector_initX(ppvoid v, size_t size, uint count); +pvoid ctl_vector_freeX(ppvoid v); -int ctl_vector_setSizeX (void** ptr, uint count); -void* ctl_vector_setEntryX(void** ptr, uint index, void* data); +int ctl_vector_getSizeX (ppvoid v); +pcvoid ctl_vector_getEntryX (ppvoid v, uint index); +int ctl_vector_getEntrySizeX(ppvoid v); -int ctl_vector_getSizeX (void** ptr); -void* ctl_vector_getEntryX (void** ptr, uint index); -int ctl_vector_getEntrySizeX(void** ptr); +int ctl_vector_setSizeX (ppvoid v, uint count); +pvoid ctl_vector_setEntryX(ppvoid v, uint index, pcvoid data); -#define ctl_vector_init(X,Y,Z) ctl_vector_initX(ppVOID(X),Y,Z) -#define ctl_vector_free(X) ctl_vector_freeX(ppVOID(X)) +int ctl_vector_addBackX (ppvoid v, pcvoid entry); +int ctl_vector_delBackX (ppvoid v); +//int ctl_vector_addFrontX(ppvoid v, pcvoid entry); +//int ctl_vector_delFrontX(ppvoid v); -#define ctl_vector_addBack(X,Y) ctl_vector_addBackX(ppVOID(X),pVOID(Y)) -#define ctl_vector_delBack(X) ctl_vector_delBackX(ppVOID(X)) +int ctl_vector_catX (ppvoid v, ppcvoid v2); +pvoid ctl_vector_copyX (ppvoid v, ppcvoid v2); +int ctl_vector_replaceX(ppvoid v , uint i1, uint ct1, + ppcvoid v2, uint j1, int ct2); -#define ctl_vector_setSize(X,Y) ctl_vector_setSizeX (ppVOID(X),Y) -#define ctl_vector_setEntry(X,Y,Z) ctl_vector_setEntryX(ppVOID(X),Y,pVOID(Z)) +#define ctl_vector_init(X,Y,Z) ctl_vector_initX(ppVoid(X),Y,Z) +#define ctl_vector_free(X) ctl_vector_freeX(ppVoid(X)) -#define ctl_vector_getSize(X) ctl_vector_getSizeX (ppVOID(X)) -#define ctl_vector_getEntry(X,Y) ctl_vector_getEntryX (ppVOID(X),Y) -#define ctl_vector_getEntrySize(X) ctl_vector_getEntrySizeX(ppVOID(X)) +#define ctl_vector_getSize(X) ctl_vector_getSizeX (ppVoid(X)) +#define ctl_vector_getEntry(X,Y) ctl_vector_getEntryX (ppVoid(X),Y) +#define ctl_vector_getEntrySize(X) ctl_vector_getEntrySizeX(ppVoid(X)) + +#define ctl_vector_setSize(X,Y) ctl_vector_setSizeX (ppVoid(X),Y) +#define ctl_vector_setEntry(X,Y,Z) ctl_vector_setEntryX(ppVoid(X),Y,pcVoid(Z)) + +#define ctl_vector_addBack(X,Y) ctl_vector_addBackX(ppVoid(X),pcVoid(Y)) +#define ctl_vector_delBack(X) ctl_vector_delBackX(ppVoid(X)) +//#define ctl_vector_addFront(X,Y) ctl_vector_addBackX(ppVoid(X),pcVoid(Y)) +//#define ctl_vector_delFront(X) ctl_vector_delBackX(ppVoid(X)) + +#define ctl_vector_cat(X,Y) ctl_vector_catX (ppVoid(X),ppcVoid(Y)) +#define ctl_vector_copy(X,Y) ctl_vector_copyX(ppVoid(X),ppcVoid(Y)) +#define ctl_vector_replace(X,Y,Z,A,B,C) ctl_vector_replaceX( ppVoid(X),Y,Z,\ + ppcVoid(A),B,C) #endif /* __vector_h__ */ |