aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcathook <cat.hook31894@gmail.com>2013-12-02 00:36:00 +0800
committercathook <cat.hook31894@gmail.com>2013-12-02 00:36:00 +0800
commit60ae370b74e632b1cf929a8d76f87f8f21666b4e (patch)
tree5d5460111527ba3dfbb513b96eea8ed91f55f6d4
parent64899ae9839658c7462192def1b31f55a03f0b6b (diff)
parent6692a339fb902f18be22e7d0eaf44a2cd20f486f (diff)
downloadctl-60ae370b74e632b1cf929a8d76f87f8f21666b4e.tar.gz
ctl-60ae370b74e632b1cf929a8d76f87f8f21666b4e.tar.zst
ctl-60ae370b74e632b1cf929a8d76f87f8f21666b4e.zip
Merge branch 'feature-array' into develop
-rw-r--r--include/array.h (renamed from include/vector.h)98
-rw-r--r--include/list.h2
-rw-r--r--src/array.c (renamed from src/vector.c)50
3 files changed, 75 insertions, 75 deletions
diff --git a/include/vector.h b/include/array.h
index 6dcc244..05a6492 100644
--- a/include/vector.h
+++ b/include/array.h
@@ -1,60 +1,60 @@
-#ifndef __vector_h__
-#define __vector_h__
+#ifndef __ARRAY_H__
+#define __ARRAY_H__
#include "utility.h"
/**********************************************************/
/* 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 */
+/* init(addr of the array, size per entry, size) */
+/* The array'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 */
+/* free(addr of the array) */
+/* Free the memory the array use. Yous should call */
/* it when you don't need the container. */
/* */
/* */
-/* getSize(addr of the vector) */
+/* getSize(addr of the array) */
/* Return the number of elements. */
/* */
-/* getEntrySize(addr of the vector) */
+/* getEntrySize(addr of the array) */
/* Return the size per entry, it dependent on what */
/* type of data you store in the container. */
/* */
-/* getEntry(addr of the vector, index) */
+/* getEntry(addr of the array, index) */
/* Return a const pointer which point to the entry */
/* with the index you give. */
/* */
/* */
-/* setSize(addr of the vector, new_size) */
+/* setSize(addr of the array, 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) */
+/* setEntry(addr of the array, index, data) */
/* Let the element with index you give be data. */
/* */
/* */
-/* addBack(addr of the vector, data) */
+/* addBack(addr of the array, data) */
/* Add an element which contain data at the back of */
-/* the vector. */
+/* the array. */
/* */
-/* delBack(addr of the vector) */
-/* Remove the last element of the vector. */
+/* delBack(addr of the array) */
+/* Remove the last element of the array. */
/* */
-/* addFront(addr of the vector, data) !! UNFINISHED !! */
+/* addFront(addr of the array, data) !! UNFINISHED !! */
/* Add an element which contain data at the front of */
-/* the vector. */
+/* the array. */
/* */
-/* delFront(addr of the vector) !! UNFINISHED !! */
-/* Remove the first element of the vector. */
+/* delFront(addr of the array) !! UNFINISHED !! */
+/* Remove the first element of the array. */
/* */
/* */
/* cat(addr of the v1, addr of the v2) */
-/* Concatenate the vector2 to the back of vector1. */
+/* Concatenate the array2 to the back of array1. */
/* */
/* copy(addr of the v1, addr of the v2) */
/* Let the contain in the v1 be the one in the v2 */
@@ -71,44 +71,44 @@
/* */
/**********************************************************/
-pvoid ctl_vector_initX(ppvoid v, size_t size, uint count);
-pvoid ctl_vector_freeX(ppvoid v);
+pvoid ctl_array_initX(ppvoid v, size_t size, uint count);
+pvoid ctl_array_freeX(ppvoid v);
-int ctl_vector_getSizeX (ppvoid v);
-pcvoid ctl_vector_getEntryX (ppvoid v, uint index);
-int ctl_vector_getEntrySizeX(ppvoid v);
+int ctl_array_getSizeX (ppvoid v);
+pcvoid ctl_array_getEntryX (ppvoid v, uint index);
+int ctl_array_getEntrySizeX(ppvoid v);
-int ctl_vector_setSizeX (ppvoid v, uint count);
-pvoid ctl_vector_setEntryX(ppvoid v, uint index, pcvoid data);
+int ctl_array_setSizeX (ppvoid v, uint count);
+pvoid ctl_array_setEntryX(ppvoid v, uint index, pcvoid data);
-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);
+int ctl_array_addBackX (ppvoid v, pcvoid entry);
+int ctl_array_delBackX (ppvoid v);
+//int ctl_array_addFrontX(ppvoid v, pcvoid entry);
+//int ctl_array_delFrontX(ppvoid v);
-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,
+int ctl_array_catX (ppvoid v, ppcvoid v2);
+pvoid ctl_array_copyX (ppvoid v, ppcvoid v2);
+int ctl_array_replaceX(ppvoid v , uint i1, uint ct1,
ppcvoid v2, uint j1, int ct2);
-#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_array_init(X,Y,Z) ctl_array_initX(ppVoid(X),Y,Z)
+#define ctl_array_free(X) ctl_array_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_array_getSize(X) ctl_array_getSizeX (ppVoid(X))
+#define ctl_array_getEntry(X,Y) ctl_array_getEntryX (ppVoid(X),Y)
+#define ctl_array_getEntrySize(X) ctl_array_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_array_setSize(X,Y) ctl_array_setSizeX (ppVoid(X),Y)
+#define ctl_array_setEntry(X,Y,Z) ctl_array_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_array_addBack(X,Y) ctl_array_addBackX(ppVoid(X),pcVoid(Y))
+#define ctl_array_delBack(X) ctl_array_delBackX(ppVoid(X))
+//#define ctl_array_addFront(X,Y) ctl_array_addBackX(ppVoid(X),pcVoid(Y))
+//#define ctl_array_delFront(X) ctl_array_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,\
+#define ctl_array_cat(X,Y) ctl_array_catX (ppVoid(X),ppcVoid(Y))
+#define ctl_array_copy(X,Y) ctl_array_copyX(ppVoid(X),ppcVoid(Y))
+#define ctl_array_replace(X,Y,Z,A,B,C) ctl_array_replaceX( ppVoid(X),Y,Z,\
ppcVoid(A),B,C)
-#endif /* __vector_h__ */
+#endif /* __ARRAY_H_ */
diff --git a/include/list.h b/include/list.h
index 902a39c..8b802f5 100644
--- a/include/list.h
+++ b/include/list.h
@@ -61,7 +61,7 @@
/* delBack(addr of the list) */
/* Remove the last element of the list. */
/* */
-/* addFront(addr of the vector, data) */
+/* addFront(addr of the list, data) */
/* Add an element which contain data at the front of */
/* the list. */
/* */
diff --git a/src/vector.c b/src/array.c
index 2d4db17..2920320 100644
--- a/src/vector.c
+++ b/src/array.c
@@ -1,4 +1,4 @@
-#include "vector.h"
+#include "array.h"
#include "utility.h"
#include <stdlib.h>
@@ -18,7 +18,7 @@ typedef struct{
#define getTotal(X) getTotal2((X)->mem_count,(X)->size)
/********************** initalize *************************/
-pvoid ctl_vector_initX(ppvoid v, size_t size, uint count){
+pvoid ctl_array_initX(ppvoid v, size_t size, uint count){
VectorHeader *tmp;
int mem = 0;
@@ -37,27 +37,27 @@ pvoid ctl_vector_initX(ppvoid v, size_t size, uint count){
}
/******************** destructure *************************/
-pvoid ctl_vector_freeX(ppvoid v){
+pvoid ctl_array_freeX(ppvoid v){
free(pVoid(getHeader(*v)));
*v = NULL;
return NULL;
}
/******************** methods about get??? ****************/
-int ctl_vector_getSizeX(ppvoid v){
+int ctl_array_getSizeX(ppvoid v){
return getHeader(*v)->use_count;
}
-pcvoid ctl_vector_getEntryX(ppvoid v, uint index){
+pcvoid ctl_array_getEntryX(ppvoid v, uint index){
return pcVoid(pChar(*v) + getHeader(*v)->size * index);
}
-int ctl_vector_getEntrySizeX(ppvoid v){
+int ctl_array_getEntrySizeX(ppvoid v){
return getHeader(*v)->size;
}
/******************** methods about set??? ****************/
-int ctl_vector_setSizeX(ppvoid v, uint count){
+int ctl_array_setSizeX(ppvoid v, uint count){
VectorHeader *tmp = getHeader(*v);
int mem = 0;
@@ -71,13 +71,13 @@ int ctl_vector_setSizeX(ppvoid v, uint count){
return tmp->use_count;
}
-pvoid ctl_vector_setEntryX(ppvoid v, uint index, pcvoid data){
+pvoid ctl_array_setEntryX(ppvoid v, uint index, pcvoid data){
VectorHeader *tmp = getHeader(*v);
memcpy(pVoid(tmp->buf + index * tmp->size), data, tmp->size);
}
/************** add/del element on the back ***************/
-int ctl_vector_addBackX(ppvoid v, pcvoid entry){
+int ctl_array_addBackX(ppvoid v, pcvoid entry){
VectorHeader *tmp = getHeader(*v);
if(tmp->use_count + 1 > tmp->mem_count){
@@ -90,7 +90,7 @@ int ctl_vector_addBackX(ppvoid v, pcvoid entry){
tmp->use_count++;
return tmp->use_count;
}
-int ctl_vector_delBackX(ppvoid v){
+int ctl_array_delBackX(ppvoid v){
VectorHeader *tmp = getHeader(*v);
if((tmp->use_count - 1) * 2 < tmp->mem_count){
@@ -102,31 +102,31 @@ int ctl_vector_delBackX(ppvoid v){
tmp->use_count--;
return tmp->use_count;
}
-//int ctl_vector_addFrontX(ppvoid v, pcvoid entry);
-//int ctl_vector_delFrontX(ppvoid v);
+//int ctl_array_addFrontX(ppvoid v, pcvoid entry);
+//int ctl_array_delFrontX(ppvoid v);
-int ctl_vector_catX(ppvoid v, ppcvoid v2){
+int ctl_array_catX(ppvoid v, ppcvoid v2){
int count0 = getHeader(*v)->use_count;
int count2 = getHeader(*v2)->use_count;
- ctl_vector_setSize(v, count0 + count2);
+ ctl_array_setSize(v, count0 + count2);
int i;
for(i = 0; i < count2; i++)
- ctl_vector_setEntry(v, count0 + i, ctl_vector_getEntry(v2, i));
+ ctl_array_setEntry(v, count0 + i, ctl_array_getEntry(v2, i));
return count0 + count2;
}
-pvoid ctl_vector_copyX(ppvoid v, ppcvoid v2){
+pvoid ctl_array_copyX(ppvoid v, ppcvoid v2){
VectorHeader* tmp = getHeader(*v2);
VectorHeader* p = (VectorHeader*)malloc(getTotal(tmp));
memcpy(pVoid(p), pVoid(tmp), getTotal(tmp));
if(v != NULL){
if(*v != NULL){
- ctl_vector_free(v);
+ ctl_array_free(v);
}
*v = p->buf;
}
return p->buf;
}
-int ctl_vector_replaceX( ppvoid v , uint start1, uint length1,
+int ctl_array_replaceX( ppvoid v , uint start1, uint length1,
ppcvoid v2, uint start2, int length2){
int end1 = (int)start1 + length1 - 1;
int end2 = (int)start2 + abs(length2) - 1, step2 = 1;
@@ -136,23 +136,23 @@ int ctl_vector_replaceX( ppvoid v , uint start1, uint length1,
ctl_swap(int, start2, end2);
}
if (length1 < length2){ // need increase size
- int sz0 = ctl_vector_getSize(v);
+ int sz0 = ctl_array_getSize(v);
int delta = length2 - length1;
- ctl_vector_setSize(v, sz0 + delta);
+ ctl_array_setSize(v, sz0 + delta);
int i;
for(i = sz0 + delta - 1; i - delta > end1; i--){
- ctl_vector_setEntry(v, i, ctl_vector_getEntry(v, i - delta));
+ ctl_array_setEntry(v, i, ctl_array_getEntry(v, i - delta));
}
}else if(length1 > length2){ // need decrease size
- int sz0 = ctl_vector_getSize(v);
+ int sz0 = ctl_array_getSize(v);
int delta = length1 - length2;
int i;
for(i = end1 - delta + 1; i + delta < sz0; i++){
- ctl_vector_setEntry(v, i, ctl_vector_getEntry(v, i + delta));
+ ctl_array_setEntry(v, i, ctl_array_getEntry(v, i + delta));
}
- ctl_vector_setSize(v, sz0 - delta);
+ ctl_array_setSize(v, sz0 - delta);
}
for(end2 += step2; start2 != end2; start2 += step2, start1 += 1){
- ctl_vector_setEntry(v, start1, ctl_vector_getEntry(v2, start2));
+ ctl_array_setEntry(v, start1, ctl_array_getEntry(v2, start2));
}
}