diff --git a/include/list/list_expand.h b/include/chain/chain.h similarity index 74% rename from include/list/list_expand.h rename to include/chain/chain.h index 0578247..540707f 100644 --- a/include/list/list_expand.h +++ b/include/chain/chain.h @@ -1,8 +1,8 @@ -#ifndef list_expand_h -#define list_expand_h - -#include +#ifndef chain_h +#define chain_h +#include +#include /************************************************ *节点的快速初始化: 为新节点分配内存空间, @@ -13,37 +13,37 @@ *为新节点获取内存空间, 并使用整型值初始化新节点 *参数if_sid指示函数是否为节点获取ID *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithInt(int, _Bool if_sid); +extern CNode *nodeWithInt(int, _Bool if_sid); /* *为新节点获取内存空间, 并使用无符号整型值初始化新节点 *参数if_sid指示函数是否为节点获取ID *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithUInt(unsigned int, _Bool if_sid); +extern CNode *nodeWithUInt(unsigned int, _Bool if_sid); /* *为新节点获取内存空间, 并使用无符号长整型值初始化新节点 *参数if_sid指示函数是否为节点获取ID *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithULLInt(unsigned long long, _Bool if_sid); +extern CNode *nodeWithULLInt(unsigned long long, _Bool if_sid); /* *为新节点获取内存空间, 并使用浮点值初始化新节点 *参数if_sid指示函数是否为节点获取ID *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithDouble(double, _Bool if_sid); +extern CNode *nodeWithDouble(double, _Bool if_sid); /* *为新节点获取内存空间, 并使用字符串值初始化新节点 *参数if_sid指示函数是否为节点获取ID *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithString(const char *, _Bool if_sid); +extern CNode *nodeWithString(const char *, _Bool if_sid); /* *为新节点获取内存空间, 并使用指针值初始化新节点 *参数if_sid指示函数是否为节点获取ID *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithPointer(const void *, _Bool if_sid); +extern CNode *nodeWithPointer(const void *, _Bool if_sid); @@ -56,33 +56,33 @@ extern Node *nodeWithPointer(const void *, _Bool if_sid); /* *为新嵌套节点获取内存空间 *返回: 若成功指向新嵌套节点的指针,若失败函数返回NULL.*/ -extern Node *nodeWithComplex(void); +extern CNode *nodeWithComplex(void); /* *用输入的值初始化嵌套节点 *参数: type指明所输入值的类型,value为指向所输入值的内存空间的指针 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int addValueForComplex(Node *, int type, void *value); +extern int addValueForComplex(CNode *, int type, void *value); /* *用输入的整型值初始化嵌套节点 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int addIntForComplex(Node *, int); +extern int addIntForComplex(CNode *, int); /* *用输入的浮点值初始化嵌套节点 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int addDoubleForComplex(Node *, double); +extern int addDoubleForComplex(CNode *, double); /* *用输入的字符串初始化嵌套节点 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int addStringForComplex(Node *, char *); +extern int addStringForComplex(CNode *, char *); /* *用输入的指针值初始化嵌套节点 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int addPointerForComplex(Node *, void *); +extern int addPointerForComplex(CNode *, void *); @@ -94,27 +94,27 @@ extern int addPointerForComplex(Node *, void *); /* *用输入的整型值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithIntForNode(Node *,int); +extern int updateValueWithIntForNode(CNode *,int); /* *用输入的无符号长整型值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithULLIntForNode(Node *, uint64_t); +extern int updateValueWithULLIntForNode(CNode *, uint64_t); /* *用输入的浮点值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithDoubleForNode(Node *,double); +extern int updateValueWithDoubleForNode(CNode *,double); /* *用输入的字符串值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithStringForNode(Node *,char *); +extern int updateValueWithStringForNode(CNode *,char *); /* *用输入的指针值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithPointerForNode(Node *,void *); +extern int updateValueWithPointerForNode(CNode *,void *); @@ -126,22 +126,22 @@ extern int updateValueWithPointerForNode(Node *,void *); /* *通过输入的整型值,查找链表中多个含有该值的节点 *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ -List *mply_findByIntForNode(List*, int); +Chain *mply_findByIntForNode(Chain*, int); /* *通过输入的浮点值,查找链表中多个含有该值的节点 *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ -List *mply_findByDoubleForNode(List*, double); +Chain *mply_findByDoubleForNode(Chain*, double); /* *通过输入的字符串值,查找链表中多个含有该值的节点 *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ -List *mply_findByStringForNode(List*, char *); +Chain *mply_findByStringForNode(Chain*, char *); /* *通过输入的指针值,查找链表中多个含有该值的节点 *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ -List *mply_findByPointerForNode(List*, void *); +Chain *mply_findByPointerForNode(Chain*, void *); @@ -155,25 +155,25 @@ List *mply_findByPointerForNode(List*, void *); /* *链表的遍历 *参数: p_func为一个函数指针, 指向的回调函数的职能在于接受每个节点的类型(type)/值指针(value)/传入参数链表(args), - 然后进行相关操作,并返回一个链表,其中包含返回状态,若有,也可以包含想要传递给母函数的值 - expand_resources为一个链表,储存母函数想要传递给回调函数的值 + 然后进行相关操作,并返回一个链表,其中包含返回状态,若有,也可以包含想要传递给母函数的值 + expand_resources为一个链表,储存母函数想要传递给回调函数的值 *返回: 如果回调函数有需要返回给母函数的值,则返回包含这些值的链表,否则返回NULL.*/ -extern List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *args), List *expand_resources); +extern Chain *listThrough(Chain *p_list, Chain *(*p_func)(unsigned int type, void *value, Chain *args), Chain *expand_resources); /* *回调函数相关宏操作的辅助函数,用于给回调函数给母函数返回值提供便利 */ -extern List *newReturn(int if_status ,int status, char *argc, ...); +extern Chain *newReturn(int if_status ,int status, char *argc, ...); /* *回调函数相关宏操作的辅助函数,用于回调函数返回空值提供便利 */ -List *newCReturn(void); +Chain *newCReturn(void); /* *回调函数相关宏操作的辅助函数,用于给回调函数获取母函数传入的参数返提供便利 */ -uint64_t getInfoForListThrough(List *expand_resources, int type); +uint64_t getInfoForListThrough(Chain *expand_resources, int type); @@ -186,7 +186,7 @@ uint64_t getInfoForListThrough(List *expand_resources, int type); /* *以字节为单位计算链表的大小 */ -uint64_t calListMemory(List *); +uint64_t calListMemory(Chain *); @@ -197,47 +197,47 @@ uint64_t calListMemory(List *); /* *返回链表长度*/ -extern uint64_t len(List *p_list); +extern uint64_t len(Chain *p_list); /* *查询链表是否为空 *返回: 如果链表为空返回1,如果链表不为空则返回0.*/ -extern int isListEmpty(List *p_list); +extern int isListEmpty(Chain *p_list); /* *直接获得节点中的整型值 *返回: 返回该节点储存的整型值*/ -extern int getByIntForNode(Node *); +extern int getByIntForNode(CNode *); /* *直接获得节点中的无符号整型值 *返回: 返回该节点储存的无符号整型值*/ -extern unsigned int getByUIntForNode(Node *); +extern unsigned int getByUIntForNode(CNode *); /* *直接获得节点中的浮点值 *返回: 返回该节点储存的浮点值*/ -extern double getByDoubleForNode(Node *); +extern double getByDoubleForNode(CNode *); /* *直接获得节点中的字符串值 *返回: 返回该节点储存的字符串值*/ -extern char *getByStringForNode(Node *); +extern char *getByStringForNode(CNode *); /* *直接获得节点中的指针值 *返回: 返回该节点储存的指针值*/ -extern void *getByPointerForNode(Node *); +extern void *getByPointerForNode(CNode *); /* *直接获得节点的序号 *返回: 返回该节点在链表中的序号*/ -extern unsigned long long getIndexForNode(List *p_list,Node *p_node); +extern unsigned long long getIndexForNode(Chain *p_list,CNode *p_node); /* *通过节点的序号找到节点中相关的值,并更新其中的储存的值的指针. *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL*/ -extern Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long index); +extern CNode *updateNodeByIndex(Chain *p_list, void *new_value, unsigned long long index); @@ -250,38 +250,39 @@ extern Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long *节点的复制,复制将会为新节点重新分配内存,并将源节点的所有值拷贝入新节点. *注意: 源节点与新节点ID相同. *返回: 若成功函数返回指向新节点的指针,若失败则返回NULL*/ -extern Node *copyNode(Node *); +extern CNode *copyNode(CNode *); /* *链表的复制,复制将会为新链表重新分配内存,并将源链表的所有节点复制. *注意: 源链表与新链表ID相同. *返回: 若成功函数返回指向新链表的指针,若失败则返回NULL*/ -List *copyList(List *p_list); +Chain *copyList(Chain *p_list); /* *通过序号查找相关的单个节点 *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByIndexForNode(List *, unsigned long long); +extern CNode *findByIndexForNode(Chain *, unsigned long long); /* *通过整型值查找储存该值的单个节点 *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByIntForNode(List *, int); +extern CNode *findByIntForNode(Chain *, int); /* *通过浮点值查找储存该值的单个节点 *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByDoubleForNode(List *, double); +extern CNode *findByDoubleForNode(Chain *, double); /* *通过字符串中查找储存该值的单个节点. *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByStringForNode(List *, char *); +extern CNode *findByStringForNode(Chain *, char *); /* *通过指针值查找储存该值的单个节点. *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByPointerForNode(List *, void *); +extern CNode *findByPointerForNode(Chain *, void *); -#endif + +#endif /* chain_h */ diff --git a/include/list/list_print.h b/include/chain/chain_print.h similarity index 74% rename from include/list/list_print.h rename to include/chain/chain_print.h index f23adbc..a353241 100644 --- a/include/list/list_print.h +++ b/include/chain/chain_print.h @@ -1,8 +1,8 @@ #ifndef list_print_h #define list_print_h -#include -#include +#include +#include /************************************************ *链表或节点的输出: 格式化输出链表或节点的属性 @@ -11,22 +11,22 @@ /* *输出链表及其中节点的相关信息 *参数: priority为每行输出信息前的空格数除以4*/ -void printListInfo(List *p_list,int priority); +void printListInfo(Chain *p_list,int priority); /* *输出节点中的相关信息 *参数: priority为每行输出信息前的空格数乘以4*/ -void printNodeInfo(Node *p_node,int priority); +void printNodeInfo(CNode *p_node,int priority); /* *输出链表及其中节点的相关信息 */ -void printList(List *); +void printList(Chain *); /* *自定义输出链表及其中节点的相关信息 *参数: func为一个函数指针, 指向函数的职能在于输出节点中的用户自定义结构的相关信息*/ -void printListForCustom(List *p_list,void (*func)(void *value)); +void printListForCustom(Chain *p_list,void (*func)(void *value)); /* *printListForCustom函数的回调函数 @@ -36,7 +36,7 @@ __CALLBACK_STATE(printListForCustom); /* *输出节点中的相关信息 */ -void printNode(Node *p_node); +void printNode(CNode *p_node); #endif /* list_print_h */ diff --git a/include/chain/chain_type.h b/include/chain/chain_type.h new file mode 100644 index 0000000..51acbb7 --- /dev/null +++ b/include/chain/chain_type.h @@ -0,0 +1,16 @@ +#ifndef chain_type_h +#define chain_type_h + +#include + +/* + *节点的管理及操作的结构 + */ +typedef struct Node CNode; + +/* + *链表的管理及操作的结构 + */ +typedef struct List Chain; + +#endif /* chain_type_h */ diff --git a/include/communicate/communicate_file.h b/include/communicate/communicate_file.h index 55514bd..0646f59 100644 --- a/include/communicate/communicate_file.h +++ b/include/communicate/communicate_file.h @@ -144,13 +144,13 @@ extern int releaseDFile(D_FILE *p_file); *将链表转化为标准数据结构 *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. */ -extern STD_DATA *listToSTD(List *); +extern STD_DATA *listToSTD(Chain *); /* *将标准数据结构转换成链表 *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. */ -extern List *standardDataToList(STD_DATA *); +extern Chain *standardDataToList(STD_DATA *); //STD_DATA *stackToSTD(Stack *); diff --git a/include/communicate/communicate_type.h b/include/communicate/communicate_type.h index 37697ca..b6372bb 100644 --- a/include/communicate/communicate_type.h +++ b/include/communicate/communicate_type.h @@ -17,7 +17,7 @@ typedef struct file_head{ typedef struct data_file{ FILE *fp;//数据文件 F_HEAD *pf_head;//数据文件头 - List *pf_stdlst;//数据文件的标志数据结构的储存链表 + Chain *pf_stdlst;//数据文件的标志数据结构的储存链表 }D_FILE; /* @@ -59,8 +59,8 @@ typedef struct standard_data{ uint32_t size;//标准数据结构在数据文件中的大小 uint32_t location;//标准数据结构的头在数据文件中的定位 _Bool lock;//标准数据文件是否被锁住 - List *pd_blocklst;//数据块储存链表 - List *pd_ctnlst;//数据块连接关系结构的储存链表 + Chain *pd_blocklst;//数据块储存链表 + Chain *pd_ctnlst;//数据块连接关系结构的储存链表 }STD_DATA; /* diff --git a/include/list/list_expand_1.h b/include/event/event.h similarity index 99% rename from include/list/list_expand_1.h rename to include/event/event.h index ea4d002..f2c00ed 100644 --- a/include/list/list_expand_1.h +++ b/include/event/event.h @@ -1,7 +1,7 @@ #ifndef list_expand_1_h #define list_expand_1_h -#include +#include /************************************************ *节点快速初始化相关宏,提供函数名较为简单的调用方式 diff --git a/include/list/list_quick.h b/include/list/list_quick.h deleted file mode 100644 index 02a1206..0000000 --- a/include/list/list_quick.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef list_quick_h -#define list_quick_h - -#include - -/* - *长链表模式下链表缓存块的记录结构 - */ -struct lst_std_id{ - unsigned long long start_idx; - unsigned long long end_idx; -#ifdef id_enable - SID *sid; -#endif -}; - -struct list_quick; - -/* - *长链表模式下链表改动偏移量的记录结构 - */ -struct index_change{ - unsigned long long c_index;//偏移量,有正负之分 - int f_count;//偏移量所对应的数组的节点 -}; - -/* - *长链表模式的管理及操作的结构 - */ -struct list_quick{ - Node **fn_node;//指向链表各个节点的映射数组 - unsigned long long fn_len;//映射数组的总长度 - unsigned long long rlst_len;//在映射数组实际被占用的长度 - _Bool if_sort;//链表是否有序 - unsigned int idxc_count;//链的删减增的操作次数 - struct index_change *idxc_lst[INDEX_CHANGE_MAX];//储存链表的删减增操作的记录 - FILE *fp;//链表缓存文件 - List *stdid_lst; -}; - -/*********************************************** - *长链表模式:当链表长度很长时,链表查找的代价将会很大. - * 该模式用于优化长链表的查找过程.降低时间复杂度. - ***********************************************/ -/* - *打开长链表模式 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int enableListQuick(List *p_list); - -/* - *关闭长链表模式 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int disableListQuick(List *p_list); - -extern Node *getNodeByFnNode(List *p_list, unsigned long long index); - -extern void digHole(List *p_list, Node *p_node); - -extern Node *findFnNode(List *p_list, Node *p_node); - -extern int indexChange(List *p_list, unsigned long long c_index, int move); - -//Node *getListTail(List *); - -#endif /* list_quick_h */ diff --git a/include/list/list_type.h b/include/list/list_type.h index b0a8786..fcd1188 100644 --- a/include/list/list_type.h +++ b/include/list/list_type.h @@ -9,9 +9,6 @@ *节点的管理及操作的结构 */ typedef struct Node{ -#ifdef list_quick_enable - unsigned long long f_number;//长链表模式下,分派的数组节点编号 -#endif unsigned int type;//类型 void *value;//值指针 struct Node *next;//指向下一个节点 @@ -21,29 +18,13 @@ typedef struct Node{ #endif } Node; -/* - *单向节点的管理及操作的结构 - */ -typedef struct simple_Node{ - void *value;//值指针 - struct simple_Node *next;//指向下一个节点 -}s_Node; - /* *链表的管理及操作的结构 */ typedef struct List{ Node *head;//指向第一个节点 Node *tail;//指向最后一个节点 -#ifdef list_simple_h - s_Node *s_head;//指向第一个单向节点 - s_Node *s_tail;//指向最后一个单向节点 -#endif -#ifdef list_quick_enable - /*如果长链表模式开启则指向对应的长链表模式的管理结构,如果未开启则为NULL*/ - struct list_quick *p_lq; - unsigned long long length;//链表的长度 -#endif + uint64_t length; #ifdef id_enable SID *s_id; #endif diff --git a/src/communicate/communicate.c b/src/communicate/communicate.c index d97bf39..7939d7d 100644 --- a/src/communicate/communicate.c +++ b/src/communicate/communicate.c @@ -1,10 +1,7 @@ #include #include -#include -#include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/dfile/dfile_in.c b/src/communicate/dfile/dfile_in.c index 5a37eb8..ffee14e 100644 --- a/src/communicate/dfile/dfile_in.c +++ b/src/communicate/dfile/dfile_in.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/dfile/dfile_info.c b/src/communicate/dfile/dfile_info.c index 6947f67..ea92cba 100644 --- a/src/communicate/dfile/dfile_info.c +++ b/src/communicate/dfile/dfile_info.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int checkIfDataFile(D_FILE *p_dfile){ diff --git a/src/communicate/dfile/dfile_init.c b/src/communicate/dfile/dfile_init.c index 48b2de3..60481e8 100644 --- a/src/communicate/dfile/dfile_init.c +++ b/src/communicate/dfile/dfile_init.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include D_FILE *initDataFileForWrite(char *route){ diff --git a/src/communicate/dfile/dfile_insert.c b/src/communicate/dfile/dfile_insert.c index 9e7752d..87f0f60 100644 --- a/src/communicate/dfile/dfile_insert.c +++ b/src/communicate/dfile/dfile_insert.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ diff --git a/src/communicate/dfile/dfile_out.c b/src/communicate/dfile/dfile_out.c index 4816511..64e1bcd 100644 --- a/src/communicate/dfile/dfile_out.c +++ b/src/communicate/dfile/dfile_out.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int dataFileWriteIn(D_FILE *p_dfile){ diff --git a/src/communicate/dfile/dfile_release.c b/src/communicate/dfile/dfile_release.c index 5e0ecf6..096e2db 100644 --- a/src/communicate/dfile/dfile_release.c +++ b/src/communicate/dfile/dfile_release.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int releaseDFile(D_FILE *p_dfile){ diff --git a/src/communicate/std/std_find.c b/src/communicate/std/std_find.c index 60493fe..8a1c8cd 100644 --- a/src/communicate/std/std_find.c +++ b/src/communicate/std/std_find.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include __CALLBACK_DEFINE(findStandardDataBySid){ diff --git a/src/communicate/std/std_in.c b/src/communicate/std/std_in.c index e903d61..caaa887 100644 --- a/src/communicate/std/std_in.c +++ b/src/communicate/std/std_in.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){ diff --git a/src/communicate/std/std_info.c b/src/communicate/std/std_info.c index 39bde49..d98d6d1 100644 --- a/src/communicate/std/std_info.c +++ b/src/communicate/std/std_info.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include uint32_t calStandardData(STD_DATA *p_std){ diff --git a/src/communicate/std/std_init.c b/src/communicate/std/std_init.c index 3f44756..6314a25 100644 --- a/src/communicate/std/std_init.c +++ b/src/communicate/std/std_init.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){ diff --git a/src/communicate/std/std_insert.c b/src/communicate/std/std_insert.c index 52d318a..e210ed7 100644 --- a/src/communicate/std/std_insert.c +++ b/src/communicate/std/std_insert.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){ diff --git a/src/communicate/std/std_out.c b/src/communicate/std/std_out.c index 88550a8..9fd7023 100644 --- a/src/communicate/std/std_out.c +++ b/src/communicate/std/std_out.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/std/std_relaese.c b/src/communicate/std/std_relaese.c index 2fba775..6b4adcf 100644 --- a/src/communicate/std/std_relaese.c +++ b/src/communicate/std/std_relaese.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int releaseStandardData(STD_DATA *p_std){ diff --git a/src/communicate/stdb/stdb_in.c b/src/communicate/stdb/stdb_in.c index a7f3bdb..f7a2ab4 100644 --- a/src/communicate/stdb/stdb_in.c +++ b/src/communicate/stdb/stdb_in.c @@ -1,6 +1,6 @@ +#include #include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/stdb/stdb_init.c b/src/communicate/stdb/stdb_init.c index f30f165..7e18371 100644 --- a/src/communicate/stdb/stdb_init.c +++ b/src/communicate/stdb/stdb_init.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){ diff --git a/src/communicate/stdb/stdb_out.c b/src/communicate/stdb/stdb_out.c index 98d9df7..f0504e1 100644 --- a/src/communicate/stdb/stdb_out.c +++ b/src/communicate/stdb/stdb_out.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include __CALLBACK_DEFINE(StandardDBlockWrite){ diff --git a/src/communicate/stdb/stdb_release.c b/src/communicate/stdb/stdb_release.c index 8072439..d63092c 100644 --- a/src/communicate/stdb/stdb_release.c +++ b/src/communicate/stdb/stdb_release.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int releaseSTDBlocks(STD_BLOCKS *p_stdb){ diff --git a/src/communicate/stdc/stdc_in.c b/src/communicate/stdc/stdc_in.c index d7183ca..d2457c8 100644 --- a/src/communicate/stdc/stdc_in.c +++ b/src/communicate/stdc/stdc_in.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/stdc/stdc_info.c b/src/communicate/stdc/stdc_info.c index 46fbe3a..4dce30f 100644 --- a/src/communicate/stdc/stdc_info.c +++ b/src/communicate/stdc/stdc_info.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include __CALLBACK_DEFINE(calStandardDataCTN){ diff --git a/src/communicate/stdc/stdc_init.c b/src/communicate/stdc/stdc_init.c index a7f3bdb..f7a2ab4 100644 --- a/src/communicate/stdc/stdc_init.c +++ b/src/communicate/stdc/stdc_init.c @@ -1,6 +1,6 @@ +#include #include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/stdc/stdc_out.c b/src/communicate/stdc/stdc_out.c index a7f3bdb..f7a2ab4 100644 --- a/src/communicate/stdc/stdc_out.c +++ b/src/communicate/stdc/stdc_out.c @@ -1,6 +1,6 @@ +#include #include -#include -#include -#include +#include +#include #include diff --git a/src/communicate/stdc/stdc_release.c b/src/communicate/stdc/stdc_release.c index e743ef5..5f81d2c 100644 --- a/src/communicate/stdc/stdc_release.c +++ b/src/communicate/stdc/stdc_release.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include int releaseSTDConnection(STD_CTN *p_stdc){ diff --git a/src/communicate/stdcvt/stcvt_in.c b/src/communicate/stdcvt/stcvt_in.c index 26d7699..2e65d1c 100644 --- a/src/communicate/stdcvt/stcvt_in.c +++ b/src/communicate/stdcvt/stcvt_in.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include STD_DATA *listToSTD(List *p_list){ diff --git a/src/communicate/stdcvt/stdcvt_out.c b/src/communicate/stdcvt/stdcvt_out.c index 7d6276b..e22ea8a 100644 --- a/src/communicate/stdcvt/stdcvt_out.c +++ b/src/communicate/stdcvt/stdcvt_out.c @@ -1,7 +1,7 @@ +#include #include -#include -#include -#include +#include +#include #include List *standardDataToList(STD_DATA *p_std){ diff --git a/src/list/list_expand_calculate.c b/src/datastruct/chain/chain_calculate.c similarity index 86% rename from src/list/list_expand_calculate.c rename to src/datastruct/chain/chain_calculate.c index 8f93edf..00e9466 100644 --- a/src/list/list_expand_calculate.c +++ b/src/datastruct/chain/chain_calculate.c @@ -1,5 +1,6 @@ #include -#include +#include + /** 计算链表占用的内存空间大小,以字节为单位输出。 @@ -7,7 +8,7 @@ @param p_list 指向目标链表的指针 @return 以字节为单位返回链表及链表内包含的节点所占的内存空间 */ -uint64_t calListMemory(List * p_list){ +uint64_t calListMemory(Chain * p_list){ Node *p_node = p_list->head; uint64_t nodes_size = 0LL; uint64_t list_size = sizeof(p_list); diff --git a/src/list/list_expand_complex.c b/src/datastruct/chain/chain_complex.c similarity index 86% rename from src/list/list_expand_complex.c rename to src/datastruct/chain/chain_complex.c index 62fb00e..cf490aa 100644 --- a/src/list/list_expand_complex.c +++ b/src/datastruct/chain/chain_complex.c @@ -1,14 +1,14 @@ #include -#include -#include +#include + /** 创建一个新的且内容为链表的节点 @return 返回指向新节点的指针 */ -Node *nodeWithComplex(void) { - Node *p_node = initNode(0); +CNode *nodeWithComplex(void) { + CNode *p_node = initNode(0); p_node->type = LIST; p_node->value = initList(0); return p_node; @@ -23,9 +23,9 @@ Node *nodeWithComplex(void) { @param value 指向该内容所在内存的指针 @return 操作成功则返回一个非负整数 */ -int addValueForComplex(Node * p_node, int type, void *value) { +int addValueForComplex(CNode * p_node, int type, void *value) { List *c_list; - Node *c_node; + CNode *c_node; if (p_node->type == LIST) { c_list = (List *)p_node->value; c_node = initNode(0); @@ -44,7 +44,7 @@ int addValueForComplex(Node * p_node, int type, void *value) { @param temp 相应的整型值 @return 操作成功则返回非负整数 */ -int addIntForComplex(Node *p_node, int temp) { +int addIntForComplex(CNode *p_node, int temp) { if (p_node->type == LIST) { int *p_temp = (int *)malloc(sizeof(int)); if(p_temp == NULL){ @@ -65,7 +65,7 @@ int addIntForComplex(Node *p_node, int temp) { @param temp 相应的双精度浮点值 @return 操作成功则返回非负整数 */ -int addDoubleForComplex(Node *p_node, double temp) { +int addDoubleForComplex(CNode *p_node, double temp) { if (p_node->type == LIST) { double *p_temp = (double *)malloc(sizeof(double)); if(p_temp == NULL){ @@ -86,7 +86,7 @@ int addDoubleForComplex(Node *p_node, double temp) { @param temp 相应的字符数组 @return 操作成功则返回非负整数 */ -int addStringForComplex(Node *p_node, char *temp) { +int addStringForComplex(CNode *p_node, char *temp) { if (p_node->type == LIST) { char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); if(p_temp == NULL){ @@ -107,7 +107,7 @@ int addStringForComplex(Node *p_node, char *temp) { @param temp 相应的指针 @return 操作成功则返回非负整数 */ -int addPointerForComplex(Node *p_node, void *temp) { +int addPointerForComplex(CNode *p_node, void *temp) { if (p_node->type == LIST) { addValueForComplex(p_node, POINTER, temp); return 0; diff --git a/src/list/list_expand_find.c b/src/datastruct/chain/chain_find.c similarity index 76% rename from src/list/list_expand_find.c rename to src/datastruct/chain/chain_find.c index 5329de9..2af4a58 100644 --- a/src/list/list_expand_find.c +++ b/src/datastruct/chain/chain_find.c @@ -1,10 +1,5 @@ #include -#include -#include -//长链表模式可能启用则包含以下头文件 -#ifdef list_quick_enable -#include -#endif +#include /** @@ -14,8 +9,8 @@ @param target 目标节点中储存的整型值 @return 返回指向目标节点的指针 */ -Node *findByIntForNode(List *p_list, int target) { - Node *t_node; +CNode *findByIntForNode(Chain *p_list, int target) { + CNode *t_node; int *p_target = (int *)malloc(sizeof(int)); *p_target = target; t_node = findByValue(p_list, INT, p_target); @@ -30,8 +25,8 @@ Node *findByIntForNode(List *p_list, int target) { @param target 目标节点中储存的双精度浮点值 @return 返回指向目标节点的指针 */ -Node *findByDoubleForNode(List *p_list, double target) { - Node *t_node; +CNode *findByDoubleForNode(Chain *p_list, double target) { + CNode *t_node; double *p_target = (double *)malloc(sizeof(double)); *p_target = target; t_node = findByValue(p_list, DOUBLE, p_target); @@ -46,8 +41,8 @@ Node *findByDoubleForNode(List *p_list, double target) { @param target 目标节点中储存的字符数组值 @return 返回指向目标节点的指针 */ -Node *findByStringForNode(List *p_list, char *target) { - Node *t_node; +CNode *findByStringForNode(Chain *p_list, char *target) { + CNode *t_node; char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); strcpy(p_temp, target); t_node = findByValue(p_list, STRING, p_temp); @@ -63,8 +58,8 @@ Node *findByStringForNode(List *p_list, char *target) { @param target 目标节点中储存的字符指针值 @return 返回指向目标节点的指针 */ -Node *findByPointerForNode(List *p_list, void *target) { - Node *t_node = findByValue(p_list, POINTER, target); +CNode *findByPointerForNode(Chain *p_list, void *target) { + CNode *t_node = findByValue(p_list, POINTER, target); return t_node; } @@ -76,12 +71,12 @@ Node *findByPointerForNode(List *p_list, void *target) { @param temp 目标节点中储存的整型值 @return 返回包含所有符合条件的节点的新的重组链表 */ -List *mply_findByInt(List* p_list, int temp) { +Chain *mply_findByInt(Chain* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); if(p_temp == NULL){ return NULL; } - List *t_list; + Chain *t_list; *p_temp = temp; t_list = mply_findByValue(p_list, INT, (void *)p_temp); free(p_temp); @@ -95,8 +90,8 @@ List *mply_findByInt(List* p_list, int temp) { @param temp 目标节点中储存的双精度浮点值 @return 返回包含所有符合条件的节点的新的重组链表 */ -List *mply_findByDouble(List* p_list, double temp) { - List *t_list; +Chain *mply_findByDouble(Chain* p_list, double temp) { + Chain *t_list; double *p_temp = (double *)malloc(sizeof(double)); if(p_temp == NULL){ return NULL; @@ -114,8 +109,8 @@ List *mply_findByDouble(List* p_list, double temp) { @param temp 目标节点中储存的字符串值 @return 返回包含所有符合条件的节点的新的重组链表 */ -List *mply_findByString(List* p_list, char *temp) { - List *t_list; +Chain *mply_findByString(Chain* p_list, char *temp) { + Chain *t_list; char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); if(p_temp == NULL){ return NULL; @@ -134,8 +129,8 @@ List *mply_findByString(List* p_list, char *temp) { @param temp 目标节点中储存的指针值 @return 返回包含所有符合条件的节点的新的重组链表 */ -List *mply_findByPointer(List* p_list, void *temp) { - List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); +Chain *mply_findByPointer(Chain* p_list, void *temp) { + Chain *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); return t_list; } @@ -147,7 +142,7 @@ List *mply_findByPointer(List* p_list, void *temp) { @param temp 目标节点中储存的整型值 @return 返回包含所有符合条件的节点的新的重组链表 */ -inline List *mply_findByIntForNode(List* p_list, int temp) { +inline Chain *mply_findByIntForNode(Chain* p_list, int temp) { return mply_findByInt(p_list, temp); } @@ -158,7 +153,7 @@ inline List *mply_findByIntForNode(List* p_list, int temp) { @param temp 目标节点中储存的双精度浮点值 @return 返回包含所有符合条件的节点的新的重组链表 */ -inline List *mply_findByDoubleForNode(List* p_list, double temp) { +inline Chain *mply_findByDoubleForNode(Chain* p_list, double temp) { return mply_findByDouble(p_list, temp); } @@ -169,7 +164,7 @@ inline List *mply_findByDoubleForNode(List* p_list, double temp) { @param temp 目标节点中储存的字符串值 @return 返回包含所有符合条件的节点的新的重组链表 */ -inline List *mply_findByStringForNode(List* p_list, char *temp) { +inline Chain *mply_findByStringForNode(Chain* p_list, char *temp) { return mply_findByString(p_list, temp); } @@ -180,7 +175,7 @@ inline List *mply_findByStringForNode(List* p_list, char *temp) { @param temp 目标节点中储存的指针值 @return 返回包含所有符合条件的节点的新的重组链表 */ -inline List *mply_findByPointerForNode(List* p_list, void *temp) { +inline Chain *mply_findByPointerForNode(Chain* p_list, void *temp) { return mply_findByPointer(p_list, temp); } @@ -192,16 +187,9 @@ inline List *mply_findByPointerForNode(List* p_list, void *temp) { @param m_index 序号位置 @return 返回指向符合条件的链表的指针 */ -Node *findByIndexForNode(List *p_list, unsigned long long m_index) { +CNode *findByIndexForNode(Chain *p_list, unsigned long long m_index) { if(p_list == NULL) return NULL; -//当长链表模式可能启用时编译以下语句 -#ifdef list_quick_enable - if(p_list->p_lq != NULL){ - register struct list_quick *p_lq = p_list->p_lq; - if(p_lq->fn_node != NULL) return getNodeByFnNode(p_list, m_index); - } -#endif - Node *p_node = p_list->head; + CNode *p_node = p_list->head; unsigned long long i; for (i = 0; i < m_index; i++) { p_node = p_node->next; diff --git a/src/list/list_expand_get.c b/src/datastruct/chain/chain_get.c similarity index 67% rename from src/list/list_expand_get.c rename to src/datastruct/chain/chain_get.c index 892491b..440bf29 100644 --- a/src/list/list_expand_get.c +++ b/src/datastruct/chain/chain_get.c @@ -1,10 +1,6 @@ #include -#include -#include -//长链表模式可能启用则包含以下头文件 -#ifdef list_quick_enable -#include -#endif +#include + /** 直接获取储存整型数据的节点的值 @@ -12,7 +8,7 @@ @param p_node 指向目标节点的指针 @return 成功则返回对应整型值,失败返回0 */ -int getByIntForNode(Node *p_node) { +int getByIntForNode(CNode *p_node) { if (p_node->type == INT) return *(int *)(p_node->value); else return 0; } @@ -24,7 +20,7 @@ int getByIntForNode(Node *p_node) { @param p_node 指向目标节点的指针 @return 成功则返回对应无符号整型值,失败返回0 */ -unsigned int getByUIntForNode(Node *p_node){ +unsigned int getByUIntForNode(CNode *p_node){ if (p_node->type == UINT) return *(unsigned int *)(p_node->value); else return 0; } @@ -35,7 +31,7 @@ unsigned int getByUIntForNode(Node *p_node){ @param p_node 指向目标节点的指针 @return 返回节点中储存的字符串 */ -char *getByStringForNode(Node *p_node) { +char *getByStringForNode(CNode *p_node) { if (p_node->type == STRING) return (char *)(p_node->value); else return NULL; } @@ -46,7 +42,7 @@ char *getByStringForNode(Node *p_node) { @param p_node 指向目标节点的指针 @return 返回节点中储存的双精度浮点值 */ -double getByDoubleForNode(Node *p_node) { +double getByDoubleForNode(CNode *p_node) { if (p_node->type == DOUBLE) return *(double *)(p_node->value); else return -1.0; } @@ -57,7 +53,7 @@ double getByDoubleForNode(Node *p_node) { @param p_node 指向目标节点的指针 @return 返回节点中储存的指针值 */ -void *getByPointerForNode(Node *p_node) { +void *getByPointerForNode(CNode *p_node) { return (void *)(p_node->value); } @@ -69,16 +65,8 @@ void *getByPointerForNode(Node *p_node) { @param p_node 指向目标节点的指针 @return 成功返回相应排列序号,失败则会返回0 */ -unsigned long long getIndexByNode(List *p_list, Node *p_node) { -// 长链表模式可能启用则编译以下代码 -#ifdef list_quick_enable - if (p_list->p_lq != NULL){ - register Node **p_fn_node = p_list->p_lq->fn_node; - register Node *rp_node = p_node; - for (register int i = 0; i < p_list->length; i++) if (p_fn_node[i] == rp_node) return i; - } -#endif - register Node *t_node = p_list->head; +unsigned long long getIndexByNode(Chain *p_list, CNode *p_node) { + register CNode *t_node = p_list->head; register unsigned long long index = 0; while (t_node != NULL) { // id模块可能启用的时候则编译以下代码 diff --git a/src/list/list_expand_node.c b/src/datastruct/chain/chain_node.c similarity index 98% rename from src/list/list_expand_node.c rename to src/datastruct/chain/chain_node.c index b30777e..25e501e 100644 --- a/src/list/list_expand_node.c +++ b/src/datastruct/chain/chain_node.c @@ -1,6 +1,5 @@ #include -#include -#include +#include /** diff --git a/src/datastruct/chain/chain_print.c b/src/datastruct/chain/chain_print.c new file mode 100644 index 0000000..98c508a --- /dev/null +++ b/src/datastruct/chain/chain_print.c @@ -0,0 +1,179 @@ +#include +#include +#include + + +/** + 打印链表及链表中节点的相关数据 + + @param p_list 指向目标链表的指针 + @param priority 行缩进次数 + */ +void printListInfo(Chain *p_list, int priority) { + int i = 0; + CNode *p_node; + for (i = 0; i < priority; i++) printf(" "); + printf("###LIST(location:%p",p_list); +// 如果可能使用到ID模块则编译以下代码 +#ifdef id_enable + printf(",id:%s",s_idToASCIIString(p_list->s_id)); +#endif + printf("){\n"); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length); + p_node = p_list->head; + while (p_node != NULL) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("%d.... \n", i); + printNodeInfo(p_node, priority + 1); + p_node = p_node->next; + i++; + } + for (i = 0; i < priority; i++) printf(" "); + printf("}\n"); + +} + + +/** + 打印链表及其节点写详细信息 + + @param p_list 指向目标链表的指针 + */ +void printList(Chain *p_list) { + int if_nearLast = 0; + CNode *p_node = p_list->head; + printf("["); + while (p_node != NULL) { + if (!if_nearLast && p_node->next == NULL) if_nearLast = 1; + if (p_node->type == INT) { + printf("%d", *(int *)(p_node->value)); + } + else if (p_node->type == DOUBLE) { + printf("%a", *(double *)(p_node->value)); + } + else if (p_node->type == STRING) { + printf("%s", (char *)(p_node->value)); + } + else if (p_node->type == POINTER) { + printf("%p", (char *)(p_node->value)); + } + else if (p_node->type == LIST) { + printList((Chain *)p_node->value); + } + if (!if_nearLast) { + printf(", "); + } + p_node = p_node->next; + } + printf("]"); +} + + +/** + 打印节点的信息 + + @param p_node 指向目标节点的指针 + @param priority 行缩进次数 + */ +void printNodeInfo(CNode *p_node, int priority) { + int i; + for (i = 0; i < priority; i++) printf(" "); + printf("#NODE(location:%p",p_node); +#ifdef id_enable + printf(", id:%s", s_idToASCIIString(p_node->s_id)); +#endif + printf("){\n"); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); + if (p_node->type == INT) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("VALUE(int):%d\n", *(int *)(p_node->value)); + } + else if (p_node->type == DOUBLE) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("VALUE(double):%a\n", *(double *)(p_node->value)); + } + else if (p_node->type == STRING) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("VALUE(string):%s\n", (char *)(p_node->value)); + } + else if (p_node->type == POINTER) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("VALUE(pointer):%s\n", (char *)(p_node->value)); + } + else if (p_node->type == LIST) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("VALUE(Chain):\n"); + printListInfo((Chain *)p_node->value, priority + 2); + } + for (i = 0; i < priority; i++) printf(" "); + printf("}\n"); +} + +/** + 打印节点的详细信息 + + @param p_node 指向目标节点的指针 + */ +void printNode(CNode *p_node) { + int i; + printf("#NODE(location:%p",p_node); +#ifdef id_enable + printf(", id:%s",s_idToASCIIString(p_node->s_id)); +#endif + printf("){\n"); + printf(" "); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last); + for (i = 0; i < 1; i++) printf(" "); + printf("ifMalloc: "); + if (p_node->value != NULL) { + printf("YES\n"); + for (i = 0; i < 1; i++) printf(" "); + printf("Value(type: %d): ", p_node->type); + if (p_node->type == INT) { + printf("%d", *(int *)(p_node->value)); + } + else if (p_node->type == DOUBLE) { + printf("%a\n", *(double *)(p_node->value)); + } + else if (p_node->type == STRING) { + printf("%s\n", (char *)(p_node->value)); + } + else if (p_node->type == POINTER) { + printf("%p\n", (char *)(p_node->value)); + } + else if (p_node->type == LIST) { + printList((Chain *)p_node->value); + } + } + else printf("NO\n"); + + printf("}\n"); +} + + +/** + 遍历链表并自定义打印节点信息 + + @param p_list 指向目标链表的指针 + @param func 指向自定义打印函数的指针,函数接受指向目标节点的指针 + */ +void printListForCustom(Chain *p_list,void (*func)(void *value)){ + printf("###LIST (LEN:%llu ",p_list->length); +#ifdef id_enable + if(p_list->s_id != NULL) printf("SID:%s",p_list->s_id->decrypt_str); +#endif + printf(")\n"); + listThrough(p_list, __CALLBACK_CALL(printListForCustom), __SEND_ARG("%p", func)); +} + + +__CALLBACK_DEFINE(printListForCustom){ + void (*func)(void *) = __ARGS_P(0, void); + printf("NODE (IDX:%llu ",__NOW_INDEX); + printf(")\n"); + func(__VALUE(void *)); + printf("\n"); + return __CRETURN__; +} diff --git a/src/list/list_sort.c b/src/datastruct/chain/chain_sort.c similarity index 65% rename from src/list/list_sort.c rename to src/datastruct/chain/chain_sort.c index 7b82d60..2a49ac3 100644 --- a/src/list/list_sort.c +++ b/src/datastruct/chain/chain_sort.c @@ -1,15 +1,11 @@ #include -#include -#include -#ifdef list_quick_enable -#include -#endif +#include /* *内部函数: 通过节点中的值查找相关多个节点. *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. *返回: 如果成功返回0,如果失败则返回-1.*/ -static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node *f_node, Node *s_node)); +static int sortList(Chain *p_list, uint64_t begin, uint64_t end, int(*func)(CNode *f_node, CNode *s_node)); /** 链表排序函数,该函数不直接对用户开放。采用快速排序的算法。 @@ -20,10 +16,10 @@ static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node @param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。 @return 成功进行操作则返回0 */ -static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node *f_node, Node *s_node)){ +static int sortList(Chain *p_list, uint64_t begin, uint64_t end, int(*func)(CNode *f_node, CNode *s_node)){ unsigned long long target_index = begin; - register Node *t_node = findByIndexForNode(p_list, target_index); - register Node *i_node = NULL, *j_node = NULL; + register CNode *t_node = findByIndexForNode(p_list, target_index); + register CNode *i_node = NULL, *j_node = NULL; register unsigned long long i = end,j = begin; for(; i >= begin; i--){ @@ -42,10 +38,10 @@ static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node } } if(end - begin > 3){ - if(t_node->f_number - begin > 2) - sortList(p_list, begin, t_node->f_number, func); - if(end - t_node->f_number > 2) - sortList(p_list, t_node->f_number, end, func); + if(getIndexForNode(p_list, t_node) - begin > 2) + sortList(p_list, begin, getIndexForNode(p_list, t_node), func); + if(end - getIndexForNode(p_list, t_node) > 2) + sortList(p_list, getIndexForNode(p_list, t_node), end, func); } return 0; } @@ -59,10 +55,7 @@ static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node @param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。 @return 成功进行操作则返回0 */ -int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)){ -#ifdef list_quick_enable - if(p_list->p_lq != NULL && !p_list->p_lq->if_sort) p_list->p_lq->if_sort = 1; -#endif +int sortListForCustom(Chain *p_list, int(*func)(CNode *f_node, CNode *s_node)){ sortList(p_list, 0, p_list->length-1, func); return 0; } diff --git a/src/list/list_expand_update.c b/src/datastruct/chain/chain_update.c similarity index 82% rename from src/list/list_expand_update.c rename to src/datastruct/chain/chain_update.c index 9a2772a..f12a808 100644 --- a/src/list/list_expand_update.c +++ b/src/datastruct/chain/chain_update.c @@ -1,6 +1,5 @@ #include -#include -#include +#include /** @@ -10,7 +9,7 @@ @param value 整型值 @return 操作成功则返回0 */ -int updateValueWithIntForNode(Node *p_node,int value){ +int updateValueWithIntForNode(CNode *p_node,int value){ int *p_value = (int *)malloc(sizeof(int)); if(p_value == NULL){ return -1; @@ -29,7 +28,7 @@ int updateValueWithIntForNode(Node *p_node,int value){ @param value 无符号长整型值 @return 操作成功则返回0 */ -int updateValueWithULLIntForNode(Node *p_node, uint64_t value){ +int updateValueWithULLIntForNode(CNode *p_node, uint64_t value){ uint64_t *p_value = (uint64_t *)malloc(sizeof(uint64_t)); if(p_value == NULL){ return -1; @@ -48,7 +47,7 @@ int updateValueWithULLIntForNode(Node *p_node, uint64_t value){ @param value 双精度浮点值 @return 操作成功则返回0 */ -int updateValueWithDoubleForNode(Node *p_node, double value){ +int updateValueWithDoubleForNode(CNode *p_node, double value){ double *p_value = (double *)malloc(sizeof(double)); if(p_value == NULL){ return -1; @@ -67,7 +66,7 @@ int updateValueWithDoubleForNode(Node *p_node, double value){ @param string 字符串值 @return 操作成功则返回0 */ -int updateValueWithStringForNode(Node *p_node, char *string){ +int updateValueWithStringForNode(CNode *p_node, char *string){ char *p_value = (char *)malloc(sizeof(strlen(string)) + 1); if(p_value == NULL){ return -1; @@ -86,7 +85,7 @@ int updateValueWithStringForNode(Node *p_node, char *string){ @param pointer 指针值 @return 操作成功则返回0 */ -int updateValueWithPointerForNode(Node *p_node, void *pointer){ +int updateValueWithPointerForNode(CNode *p_node, void *pointer){ free(p_node->value); p_node->value = pointer; return 0; diff --git a/src/graph/graph.c b/src/datastruct/graph/graph.c similarity index 100% rename from src/graph/graph.c rename to src/datastruct/graph/graph.c diff --git a/src/graph/graph.h b/src/datastruct/graph/graph.h similarity index 100% rename from src/graph/graph.h rename to src/datastruct/graph/graph.h diff --git a/src/tree/tree.c b/src/datastruct/tree/tree.c similarity index 100% rename from src/tree/tree.c rename to src/datastruct/tree/tree.c diff --git a/src/tree/tree_expand.c b/src/datastruct/tree/tree_expand.c similarity index 100% rename from src/tree/tree_expand.c rename to src/datastruct/tree/tree_expand.c diff --git a/src/tree/tree_expand.h b/src/datastruct/tree/tree_expand.h similarity index 100% rename from src/tree/tree_expand.h rename to src/datastruct/tree/tree_expand.h diff --git a/src/list/list_expand_callback.c b/src/event/event_callback.c similarity index 92% rename from src/list/list_expand_callback.c rename to src/event/event_callback.c index 8d3e93e..24ba9ad 100644 --- a/src/list/list_expand_callback.c +++ b/src/event/event_callback.c @@ -1,7 +1,6 @@ #include -#include -#include -#include +#include +#include /** @@ -12,7 +11,7 @@ @param p_func 指向回调函数的指针 @return 返回参数链表 */ -List *listThrough(List *p_list, List *(*p_func)(uint32_t, void *, List *), List *expand_resources) { +Chain *listThrough(Chain *p_list, Chain *(*p_func)(uint32_t, void *, Chain *), Chain *expand_resources) { Node *p_node = p_list->head; List *m_rtnlst = NULL; uint64_t index = 0; @@ -51,7 +50,7 @@ List *listThrough(List *p_list, List *(*p_func)(uint32_t, void *, List *), List @param type 模式 @return 返回需要获取的数据 */ -uint64_t getInfoForListThrough(List *expand_resources, int type){ +uint64_t getInfoForListThrough(Chain *expand_resources, int type){ Node *p_node = NULL; if (type == 0) { p_node = findByIndexForNode(expand_resources, expand_resources->length-1); @@ -70,7 +69,7 @@ uint64_t getInfoForListThrough(List *expand_resources, int type){ @param ... 参数 @return 指向构造的参数列表的指针 */ -List *newReturn(int if_status ,int status, char *argc, ...){ +Chain *newReturn(int if_status ,int status, char *argc, ...){ List *p_list = initList(0); if(if_status){ lisrti(p_list, status); @@ -130,6 +129,6 @@ List *newReturn(int if_status ,int status, char *argc, ...){ @return 指向构造的参数列表的指针 */ -List *newCReturn(void){ +Chain *newCReturn(void){ return newReturn(1, 0, NULL); } diff --git a/src/list/list_insert.c b/src/list/list_insert.c deleted file mode 100644 index 521d8c8..0000000 --- a/src/list/list_insert.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#ifdef list_quick_enable -#include -#endif - - -/** - 在链表的头部插入节点 - - @param p_list 指向目标链表的指针 - @param p_node 指向目标节点的指针 - @return 函数执行成功返回0 - */ -int insertInHead(List *p_list, Node *p_node) { -// 如果可能需要使用长链表模块则编译以下代码 -#ifdef list_quick_enable - if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1; - if(p_list->p_lq != NULL){ - if(p_list->head->type == HOLE){ - Node *t_node = p_list->head; - while(t_node->type == HOLE) t_node = t_node->next; - replaceNode(p_list, t_node->last, p_node); - p_list->p_lq->fn_node[t_node->last->f_number] = p_node; - indexChange(p_list, t_node->last->f_number, 1); - releaseNode(t_node->last); - return 0; - } - indexChange(p_list, 0, 1); - } -#endif - if (isListEmpty(p_list)) { - p_list->head = p_node; - p_list->tail = p_node; - } - else { - p_list->head->last = p_node; - p_node->last = NULL; - p_node->next = p_list->head; - p_list->head = p_node; - } - p_list->length += 1; - return 0; -} - -/** - 在链表的尾部插入节点 - - @param p_list 指向目标链表的指针 - @param p_node 指向目标节点的指针 - @return 函数执行成功返回0 - */ -int insertInTail(List *p_list, Node *p_node) { -// 如果可能需要使用长链表模块则编译以下代码 -#ifdef list_quick_enable - if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1; -#endif - if (isListEmpty(p_list)) { - p_list->head = p_node; - p_list->tail = p_node; - } - else { - p_list->tail->next = p_node; - p_node->next = NULL; - p_node->last = p_list->tail; - p_list->tail = p_node; - } -// 如果可能需要使用长链表模块则编译以下代码 -#ifdef list_quick_enable - if(p_list->p_lq != NULL){ - p_node->f_number = p_list->p_lq->rlst_len; - if(p_list->p_lq->rlst_len >= p_list->p_lq->fn_len){ - p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(Node *) * (p_list->p_lq->fn_len + FN_NODE_SPARE)); - p_list->p_lq->fn_len += FN_NODE_SPARE; - } - p_list->p_lq->fn_node[p_list->p_lq->rlst_len] = p_node; - p_list->p_lq->rlst_len++; - } -#endif - p_list->length += 1; - return 0; -} diff --git a/src/list/list_quick.c b/src/list/list_quick.c deleted file mode 100644 index a31aaae..0000000 --- a/src/list/list_quick.c +++ /dev/null @@ -1,237 +0,0 @@ -#include -#include -#include -#include - -static int refreshFnNode(List *p_list); - -static int indexTransfromer(List *p_list, unsigned long long m_index); - -static void initIdxcList(List *p_list); - -int enableListQuick(List *p_list){ - if(p_list->length > ENABLE_LIST_QUICK){ - p_list->p_lq = malloc(sizeof(struct list_quick)); - register struct list_quick *p_lq = p_list->p_lq; - p_lq->rlst_len = p_list->length; - p_lq->fn_node = NULL; - p_lq->if_sort = 0; - p_lq->idxc_count = 0; - p_lq->stdid_lst = initList(0); - for(int i = 0; i < INDEX_CHANGE_MAX; i++) p_lq->idxc_lst[i] = NULL; - refreshFnNode(p_list); - //sortListById(p_list, 0, p_list->length); - } - return 0; -} - -int refreshFnNode(List *p_list){ - if(p_list->p_lq != NULL){ - struct list_quick *blk_plq = p_list->p_lq; - initIdxcList(p_list); - if(p_list->p_lq->fn_node != NULL) free(p_list->p_lq->fn_node); - p_list->p_lq->fn_node = malloc(sizeof(Node *) * (p_list->length + FN_NODE_SPARE)); - p_list->p_lq->fn_len = p_list->length + FN_NODE_SPARE; - p_list->p_lq->rlst_len = p_list->length; - register Node *p_node = p_list->head; - unsigned long long i = 0; - p_list->p_lq = NULL; - while (p_node != NULL) { - if(p_node->type == HOLE){ - removeByNode(p_list, p_node); - releaseNode(p_node); - p_node = p_node->next; - continue; - } - p_node->f_number = i; - blk_plq->fn_node[i] = p_node; - p_node = p_node->next; - i++; - } - p_list->p_lq = blk_plq; - return 0; - } - return -1; -} - -int indexChange(List *p_list, unsigned long long c_index, int move){ - if(p_list->p_lq != NULL){ - struct index_change *t_idxc; - struct list_quick *p_lq = p_list->p_lq; - if(p_lq->idxc_count >= INDEX_CHANGE_MAX){ - refreshFnNode(p_list); - for(int i = 0; i < INDEX_CHANGE_MAX; i++){ - free(p_lq->idxc_lst[i]); - p_lq->idxc_lst[i] = NULL; - } - return 0; - } - for(int i = 0; p_lq->idxc_lst[i] != NULL; i++){ - if(p_lq->idxc_lst[i]->c_index == c_index){ - p_lq->idxc_lst[i]->f_count += move; - return 0; - } - } - if(p_lq->idxc_count == 0) { - p_lq->idxc_lst[0] = malloc(sizeof(struct index_change)); - t_idxc = p_lq->idxc_lst[0]; - } - else { - p_lq->idxc_lst[p_lq->idxc_count] = malloc(sizeof(struct index_change)); - t_idxc = p_lq->idxc_lst[p_lq->idxc_count]; - } - t_idxc->c_index = c_index; - t_idxc->f_count = move; - p_lq->idxc_count++; - } - return 0; -} - -int indexTransfromer(List *p_list, unsigned long long m_index){ - int total_move = 0; - struct list_quick *p_lq = p_list->p_lq; - struct index_change **p_idxclst = p_lq->idxc_lst; - if(p_lq->idxc_lst[0] != NULL){ - for (int i = 0; p_idxclst[i] != NULL && i < INDEX_CHANGE_MAX; i++) { - if(p_idxclst[i]->c_index <= m_index) total_move += p_idxclst[i]->f_count; - if(total_move >= 65535){ - refreshFnNode(p_list); - return 0; - } - } - } - return total_move; -} - -Node *getNodeByFnNode(List *p_list, unsigned long long index){ - if(p_list->p_lq != NULL){ - struct list_quick *p_lq = p_list->p_lq; - Node *p_node = NULL; - if(p_lq->rlst_len > index) p_node = p_lq->fn_node[index]; - else p_node = p_lq->fn_node[p_lq->rlst_len - 1]; - if(p_lq->idxc_count > 0){ - int total_move = indexTransfromer(p_list, index); - int temp = ABS(total_move); - if(p_lq->rlst_len > index){ - if(total_move >=0){ - for(int i = 0; i < temp; ){ - p_node = p_node->last; - if(p_node->type != HOLE) i++; - } - } - else{ - for(int i = 0; i < temp; ){ - p_node = p_node->next; - if(p_node->type != HOLE) i--; - } - } - } - else{ - unsigned long long jump = index - temp; - for(int i = 0; i < jump; i++) p_node = p_node->next; - } - return p_node; - } - else{ - return p_lq->fn_node[index]; - } - - } - return NULL; -} - -int insertAfterNode(List *p_list, Node *t_node, Node *p_node){ - if(t_node == p_list->tail){ - insertInTail(p_list, p_node); - return 0; - } - if(p_list->p_lq != NULL){ - if(t_node->next->type == HOLE){ - Node *temp_node = t_node->next; - replaceNode(p_list, t_node->next, p_node); - p_node->f_number = temp_node->f_number; - releaseNode(temp_node); - p_list->p_lq->fn_node[p_node->f_number] = p_node; - indexChange(p_list, p_node->f_number, 1); - } - } - p_node->next = t_node->next; - p_node->last = t_node; - if(p_list->tail != t_node) - t_node->next->last = p_node; - else - p_list->tail = p_node; - - t_node->next = p_node; - - if(p_list->p_lq != NULL){ - Node *fn_node = findFnNode(p_list, p_node); - indexChange(p_list, fn_node->f_number, 1); - } - p_list->length += 1; - return 0; -} - -int insertBeforeNode(List *p_list, Node*t_node, Node *p_node){ - if(t_node == p_list->head){ - insertInHead(p_list, p_node); - return 0; - } - if(p_list->p_lq != NULL){ - if(t_node->last->type == HOLE){ - Node *temp_node = t_node->last; - replaceNode(p_list, t_node->last, p_node); - p_node->f_number = temp_node->f_number; - releaseNode(temp_node); - p_list->p_lq->fn_node[p_node->f_number] = p_node; - indexChange(p_list, p_node->f_number, 1); - return 0; - } - } - p_node->last = t_node->last; - p_node->next = t_node; - if(p_list->head != t_node) - t_node->last->next = p_node; - else - p_list->head = p_node; - t_node->last = p_node; - if(p_list->p_lq != NULL){ - Node *fn_node = findFnNode(p_list, p_node); - indexChange(p_list, fn_node->f_number, 1); - } - p_list->length += 1; - return 0; -} - -Node *findFnNode(List *p_list, Node *p_node){ - Node *fn_node = p_node; - while(fn_node->f_number == 0) fn_node = fn_node->next; - return fn_node; -} - -static void initIdxcList(List *p_list){ - struct list_quick *p_lq = p_list->p_lq; - for(int i = 0; i < INDEX_CHANGE_MAX; i++){ - if(p_lq->idxc_lst[i] != NULL) free(p_lq->idxc_lst[i]); - p_lq->idxc_lst[i] = NULL; - } - p_lq->idxc_count = 0; -} - -void digHole(List *p_list, Node *p_node){ - Node *c_node = copyNode(p_node); -#ifdef id_enable - freeS_id(c_node->s_id); -#endif - replaceNode(p_list, p_node, c_node); - c_node->value = NULL; - c_node->type = HOLE; - indexChange(p_list, p_node->f_number, -1); -} - -int disableListQuick(List *p_list){ - free(p_list->p_lq->fn_node); - initIdxcList(p_list); - free(p_list->p_lq); - return 0; -} diff --git a/src/list/list_simple.c b/src/list/list_simple.c deleted file mode 100644 index 4971fe7..0000000 --- a/src/list/list_simple.c +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include - -inline s_Node *s_initNode(void){ - s_Node *s_p_node = (s_Node *)malloc(sizeof(s_Node)); - s_p_node->next = NULL; - return s_p_node; -} - -inline int s_insertInHead(List *p_list, s_Node *s_p_node){ - if(p_list->s_head == NULL && p_list->s_tail == NULL){ - p_list->s_head = s_p_node; - p_list->s_tail = s_p_node; - } - else{ - s_p_node->next = p_list->s_head; - p_list->s_head = s_p_node; - } - return 0; -} - -inline int s_insertInTail(List *p_list, s_Node *s_p_node){ - if(p_list->s_head == NULL && p_list->s_tail == NULL){ - p_list->s_head = s_p_node; - p_list->s_tail = s_p_node; - } - else{ - p_list->s_tail->next = s_p_node; - p_list->s_tail = s_p_node; - } - return 0; -} - -s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) { - s_Node *s_p_node = p_list->s_head; - unsigned long long i; - for (i = 0; i < m_index; i++) { - s_p_node = s_p_node->next; - } - return s_p_node; -} - -inline int s_releaseNode(s_Node *s_p_node){ - free(s_p_node); - return 0; -} - -inline int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)){ - func(s_p_node->value); - free(s_p_node); - return 0; -} - -int s_releaseListForCustom(List *p_list, int (*func)(void *)){ - register s_Node *s_p_node, *s_pl_node; - s_p_node = p_list->s_head; - while (s_p_node != NULL) { - s_pl_node = s_p_node; - s_p_node = s_p_node->next; - s_pl_node->next = NULL; - s_releaseNodeForCustom(s_pl_node,func); - } - free(p_list); - return 0; -} diff --git a/src/list/list_simple_node.c b/src/list/list_simple_node.c deleted file mode 100644 index 0b83d9c..0000000 --- a/src/list/list_simple_node.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include - -inline s_Node *s_nodeWithInt(int t_int){ - s_Node *s_p_node = s_initNode(); - int *pt_int = malloc(sizeof(int)); - *pt_int = t_int; - s_p_node->value = pt_int; - return s_p_node; -} - -inline s_Node *s_nodeWithUInt(unsigned int t_uint){ - s_Node *s_p_node = s_initNode(); - unsigned int *pt_uint = malloc(sizeof(unsigned int)); - *pt_uint = t_uint; - s_p_node->value = pt_uint; - return s_p_node; -} - -inline s_Node *s_nodeWithDouble(double t_double){ - s_Node *s_p_node = s_initNode(); - unsigned int *pt_double = malloc(sizeof(double)); - *pt_double = t_double; - s_p_node->value = pt_double; - return s_p_node; -} - -inline s_Node *s_nodeWithString(const char *t_string){ - s_Node *s_p_node = s_initNode(); - char *pt_string = malloc(strlen(t_string) + 1); - strcpy(pt_string, t_string); - s_p_node->value = pt_string; - return s_p_node; -} - -inline s_Node *s_nodeWithPointer(const void *t_pointer){ - s_Node *s_p_node = s_initNode(); - s_p_node->value = (void *) t_pointer; - return s_p_node; -} diff --git a/src/block/block.c b/src/memory/block/block.c similarity index 100% rename from src/block/block.c rename to src/memory/block/block.c diff --git a/src/block/block_expand.c b/src/memory/block/block_expand.c similarity index 100% rename from src/block/block_expand.c rename to src/memory/block/block_expand.c diff --git a/src/list/list_copy.c b/src/memory/list/list_copy.c similarity index 86% rename from src/list/list_copy.c rename to src/memory/list/list_copy.c index 4cf7549..4588fd3 100644 --- a/src/list/list_copy.c +++ b/src/memory/list/list_copy.c @@ -20,9 +20,6 @@ Node *copyNode(Node *p_node) { t_node->next = p_node->next; t_node->type = p_node->type; t_node->value = p_node->value; -#ifdef list_quick_enable - t_node->f_number = p_node->f_number; -#endif return t_node; } @@ -43,11 +40,6 @@ List *copyList(List *p_list) { #endif t_list->head = p_list->head; t_list->tail = p_list->tail; -#ifdef list_simple_h - t_list->s_id = p_list->s_id; - t_list->s_head = p_list->s_head; - t_list->s_tail = p_list->s_tail; -#endif t_list->length = p_list->length; if(p_list->head != NULL && p_list->tail != NULL){ p_node = p_list->head; diff --git a/src/list/list_find.c b/src/memory/list/list_find.c similarity index 99% rename from src/list/list_find.c rename to src/memory/list/list_find.c index c159265..34c7a90 100644 --- a/src/list/list_find.c +++ b/src/memory/list/list_find.c @@ -3,7 +3,6 @@ //如果ID模块可能启用则编译以下代码 #ifdef id_enable - /** 通过ID查找链表中符合条件的第一个节点 diff --git a/src/list/list_info.c b/src/memory/list/list_info.c similarity index 100% rename from src/list/list_info.c rename to src/memory/list/list_info.c diff --git a/src/list/list_init.c b/src/memory/list/list_init.c similarity index 91% rename from src/list/list_init.c rename to src/memory/list/list_init.c index cf7ecef..0747e4d 100644 --- a/src/list/list_init.c +++ b/src/memory/list/list_init.c @@ -27,7 +27,6 @@ Node *initNode(void) p_node->next = NULL; p_node->last = NULL; p_node->type = VOID; - p_node->f_number = 0; // 链表内存安全模式相关操作 if (if_safeModeForNode) { if_safeModeForNode = 0; @@ -63,12 +62,6 @@ List *initList(void) #endif p_list->head = NULL; p_list->tail = NULL; - p_list->length = 0; - p_list->p_lq = NULL; -// 如果简单链表模式启用则编译以下代码 -#ifdef list_simple_h - p_list->s_head = NULL; -#endif if (if_safeModeForNode) { if_safeModeForNode = 0; p_node = initNode(0); diff --git a/src/memory/list/list_insert.c b/src/memory/list/list_insert.c new file mode 100644 index 0000000..72c76a4 --- /dev/null +++ b/src/memory/list/list_insert.c @@ -0,0 +1,52 @@ +#include +#include + +/** + 在链表的头部插入节点 + + @param p_list 指向目标链表的指针 + @param p_node 指向目标节点的指针 + @return 函数执行成功返回0 + */ +int insertInHead(List *p_list, Node *p_node) { + if (isListEmpty(p_list)) { + p_list->head = p_node; + p_list->tail = p_node; + } + else { + p_list->head->last = p_node; + p_node->last = NULL; + p_node->next = p_list->head; + p_list->head = p_node; + } + p_list->length += 1; + return 0; +} + +/** + 在链表的尾部插入节点 + + @param p_list 指向目标链表的指针 + @param p_node 指向目标节点的指针 + @return 函数执行成功返回0 + */ +int insertInTail(List *p_list, Node *p_node) { +// 如果可能需要使用长链表模块则编译以下代码 +/* +#ifdef list_quick_enable + if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1; +#endif +*/ + if (isListEmpty(p_list)) { + p_list->head = p_node; + p_list->tail = p_node; + } + else { + p_list->tail->next = p_node; + p_node->next = NULL; + p_node->last = p_list->tail; + p_list->tail = p_node; + } + p_list->length += 1; + return 0; +} diff --git a/src/list/list_print.c b/src/memory/list/list_print.c similarity index 98% rename from src/list/list_print.c rename to src/memory/list/list_print.c index 82d4c50..877f207 100644 --- a/src/list/list_print.c +++ b/src/memory/list/list_print.c @@ -1,8 +1,6 @@ #include #include -#include #include -#include #ifdef id_enable #include diff --git a/src/list/list_release.c b/src/memory/list/list_release.c similarity index 88% rename from src/list/list_release.c rename to src/memory/list/list_release.c index 6ef0124..70d6586 100644 --- a/src/list/list_release.c +++ b/src/memory/list/list_release.c @@ -1,8 +1,5 @@ #include #include -#ifdef list_quick_enable -#include -#endif int releaseNode(Node *p_node) { if (if_safeModeForNode == 1) { @@ -19,7 +16,6 @@ int releaseNode(Node *p_node) { } p_node->value = NULL; } - p_node->f_number = 0; p_node->last = NULL; p_node->next = NULL; p_node->type = VOID; @@ -60,12 +56,6 @@ int releaseList(List *p_list) { p_list->head = NULL; p_list->tail = NULL; p_list->length = 0; -#ifdef list_simple_h - p_list->s_head = NULL; - p_list->s_tail = NULL; - if (p_list->s_id != NULL) freeS_id(p_list->s_id); - if(p_list->p_lq != NULL) disableListQuick(p_list); -#endif free(p_list); return 0; } @@ -113,9 +103,6 @@ int releaseListForCustom(List *p_list, int (*func)(void *)){ p_list->length = 0; #ifdef id_enable if (p_list->s_id != NULL) freeS_id(p_list->s_id); -#endif -#ifdef list_quick_enable - if(p_list->p_lq != NULL) disableListQuick(p_list); #endif free(p_list); return 0; diff --git a/src/list/list_remove.c b/src/memory/list/list_remove.c similarity index 52% rename from src/list/list_remove.c rename to src/memory/list/list_remove.c index 575eb79..e83522b 100644 --- a/src/list/list_remove.c +++ b/src/memory/list/list_remove.c @@ -1,8 +1,5 @@ #include #include -#ifdef list_quick_enable -#include -#endif #ifdef id_enable int removeById(List *p_list, SID *s_id) { @@ -48,23 +45,8 @@ int removeByNode(List *p_list, Node *p_node) { popFromTail(p_list); return 0; } - if(p_list->p_lq == NULL){ - p_node->last->next = p_node->next; - p_node->next->last = p_node->last; - } - else{ -#ifdef list_quick_enable - if(p_node->f_number == 0){ - Node *fn_node = findFnNode(p_list, p_node); - indexChange(p_list, fn_node->f_number, -1); - p_node->last->next = p_node->next; - p_node->next->last = p_node->last; - } - else{ - digHole(p_list, p_node); - } -#endif - } + p_node->last->next = p_node->next; + p_node->next->last = p_node->last; p_list->length -= 1; return 0;//not find } @@ -73,27 +55,6 @@ Node *popFromHead(List *p_list) { if (isListEmpty(p_list)) return NULL; Node *p_node = p_list->head; -#ifdef list_quick_enable - if(p_list->p_lq != NULL){ - if(p_list->head->type == HOLE){ - Node *t_node = p_list->head; - while(t_node->type == HOLE) t_node = t_node->next; - if(t_node->f_number != 0){ - Node *r_node = t_node; - digHole(p_list, t_node); - return r_node; - } - p_node = t_node; - } - else{ - if(p_list->p_lq->fn_node[0] == p_list->head){ - Node *r_node = p_list->head; - digHole(p_list, p_list->head); - return r_node; - } - } - } -#endif //Node *tmp = p_list->head; p_list->head->next->last = NULL; p_list->head = p_list->head->next; @@ -111,18 +72,6 @@ Node *popFromTail(List *p_list) { if (isListEmpty(p_list)) return NULL; else { -#ifdef list_quick_enable - if(p_list->p_lq != NULL){ - if(p_list->p_lq->fn_node[p_list->p_lq->rlst_len - 1] == p_list->tail){ - p_list->p_lq->fn_node[p_list->p_lq->rlst_len - 1] = NULL; - p_list->p_lq->rlst_len--; - if(p_list->p_lq->fn_len - p_list->p_lq->rlst_len > FN_NODE_SPARE * 2){ - p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(p_list->p_lq->fn_len - FN_NODE_SPARE)); - p_list->p_lq->fn_len -= FN_NODE_SPARE; - } - } - } -#endif //Node *tmp = p_list->tail; p_list->tail->last->next = NULL; p_list->tail = p_list->tail->last; diff --git a/src/list/list_replace.c b/src/memory/list/list_replace.c similarity index 58% rename from src/list/list_replace.c rename to src/memory/list/list_replace.c index ae08d2a..42e4e91 100644 --- a/src/list/list_replace.c +++ b/src/memory/list/list_replace.c @@ -1,8 +1,5 @@ #include #include -#ifdef list_quick_enable -#include -#endif int replaceNode(List *p_list, Node *pt_node, Node *p_node){ p_node->next = pt_node->next; @@ -11,17 +8,6 @@ int replaceNode(List *p_list, Node *pt_node, Node *p_node){ else p_list->head = p_node; if(p_list->tail != pt_node) pt_node->next->last = p_node; else p_list->tail = p_node; -#ifdef list_quick_enable - if(p_list->p_lq != NULL){ - if(pt_node->f_number == 0 && p_list->p_lq->fn_node[0] != pt_node){ - p_node->f_number = pt_node->f_number; - } - else{ - p_list->p_lq->fn_node[pt_node->f_number] = p_node; - p_node->f_number = pt_node->f_number; - } - } -#endif return 0; } @@ -40,14 +26,5 @@ int exchangeNode(List *p_list, Node *f_node, Node *s_node){ f_node->last = s_node->last; s_node->next = fn_node; s_node->last = fl_node; -#ifdef list_quick_enable - if(p_list->p_lq != NULL){ - p_list->p_lq->fn_node[f_node->f_number] = s_node; - p_list->p_lq->fn_node[s_node->f_number] = f_node; - unsigned long long temp = f_node->f_number; - f_node->f_number = s_node->f_number; - s_node->f_number = temp; - } -#endif return 0; } diff --git a/src/list/safe_mode.c b/src/memory/list/safe_mode.c similarity index 98% rename from src/list/safe_mode.c rename to src/memory/list/safe_mode.c index 69a1564..a682699 100644 --- a/src/list/safe_mode.c +++ b/src/memory/list/safe_mode.c @@ -1,6 +1,6 @@ #include #include -#include +#include static int if_safeModeForNode = 0; static List *node_list = NULL; diff --git a/test/test.c b/test/test.c index cacba84..33f2bb7 100644 --- a/test/test.c +++ b/test/test.c @@ -47,44 +47,8 @@ int list(void) { return 0; }*/ -int time_avg(void){ - List *t_list = initList(0); - int64_t time_all = 0; - for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); - for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); - for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); - for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); - for(int i = 0; i < 65535; i++) insertInTail(t_list,nodeWithInt(i, 0)); - enableListQuick(t_list); - for (int i = 0; i < 100; i++){ - struct timeval start,stop; - gettimeofday(&start,0); - findByIndexForNode(t_list, 200000); - gettimeofday(&stop,0); - time_all += (int64_t)(stop.tv_usec-start.tv_usec); - - } - double avg_time = (double) (time_all/(int64_t)100); - printf("TIME: %fus\n",avg_time); - releaseList(t_list); - return 0; -} int main(int argc, char **argv) { - //time_avg(); - /*List *t_list = initList(0); - for(int i = 0; i < 65535; i++) lisrti(t_list, i); - for(int i = 0; i < 65535; i++) lisrti(t_list, i); - for(int i = 0; i < 65535; i++) lisrti(t_list, i); - for(int i = 0; i < 65535; i++) lisrti(t_list, i); - for(int i = 0; i < 65535; i++) lisrti(t_list, i); - enableListQuick(t_list); - findByIndexForNode(t_list, 300000); - lisrhi(t_list, -1); - insertBeforeNode(t_list, findByIndexForNode(t_list, 5), lni(6)); - popFromHead(t_list); - Node *p_node = findByIndexForNode(t_list, 7); - releaseList(t_list);*/ while(1){ List *p_list = initList(0); for(int i = 0; i < 65535; i++){ diff --git a/test/test.h b/test/test.h index 7f9e36b..0d51055 100644 --- a/test/test.h +++ b/test/test.h @@ -5,15 +5,12 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include int stack(void); int list(void); int tree(void); -int time_avg(void); #endif // TEST_H