From 6beea0ecdcee6728651e7342e5d3c8e261168caf Mon Sep 17 00:00:00 2001 From: Saturneic Date: Wed, 22 Aug 2018 23:38:03 +0800 Subject: [PATCH 01/18] utf-8 --- ZE-Standard-Libraries.xcodeproj/project.pbxproj | 14 +++++++------- communicate/communicate.h | 8 -------- type/type.h | 13 ++++++++++++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index a485e40..e9882e2 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -33,8 +33,8 @@ /* Begin PBXFileReference section */ 9233C30E212292B000FB2485 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = md5.h; path = id/md5.h; sourceTree = ""; }; 9233C30F212292B000FB2485 /* md5.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = md5.c; path = id/md5.c; sourceTree = ""; }; - 9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list.c; sourceTree = ""; }; - 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand.h; sourceTree = ""; }; + 9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list.c; sourceTree = ""; }; + 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_expand.h; sourceTree = ""; }; 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list.h; sourceTree = ""; }; 9246995820CE52A700B4E894 /* stack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = ""; }; 9246995920CE52A700B4E894 /* stack.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stack.c; sourceTree = ""; }; @@ -42,10 +42,10 @@ 9246995D20CE655900B4E894 /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = ""; }; 9246995E20CE655900B4E894 /* tree.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = ""; }; 9269D4E7210F1B3D00161557 /* stack_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_expand.c; sourceTree = ""; }; - 9269D4E9210F1B4B00161557 /* list_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = list_expand.c; sourceTree = ""; }; - 9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = test.c; sourceTree = ""; }; - 9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test.h; sourceTree = ""; }; - 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = type.h; path = type/type.h; sourceTree = ""; }; + 9269D4E9210F1B4B00161557 /* list_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_expand.c; sourceTree = ""; }; + 9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = test.c; sourceTree = ""; }; + 9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = test.h; sourceTree = ""; }; + 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = type.h; path = type/type.h; sourceTree = ""; }; 9269D4F2210F1BB000161557 /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = id/id.c; sourceTree = ""; }; 9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = id.h; path = id/id.h; sourceTree = ""; }; 9269D4F7210F1D0B00161557 /* tree_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree_expand.c; sourceTree = ""; }; @@ -54,7 +54,7 @@ 9286EB79211400C900752977 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = error/error.c; sourceTree = ""; }; 9286EB7B211400D000752977 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = error.h; path = error/error.h; sourceTree = ""; }; 9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; name = communicate.c; path = communicate/communicate.c; sourceTree = ""; }; - 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = communicate.h; path = communicate/communicate.h; sourceTree = ""; }; + 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = communicate.h; path = communicate/communicate.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ diff --git a/communicate/communicate.h b/communicate/communicate.h index 991bf3b..5ebe1d0 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -4,14 +4,6 @@ #include "../type/type.h" #include "../list/list_expand.h" -typedef struct message{ - SID *p_sid; - time_t time; - char titile[16]; - unsigned long size; - char content[0]; -}MSG; - D_FILE *initDataFileForWrite(char *route); D_FILE *initDataFileForRead(char *route); STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size); diff --git a/type/type.h b/type/type.h index 9cc4887..50b810e 100644 --- a/type/type.h +++ b/type/type.h @@ -89,7 +89,7 @@ /************************************************ - *库相关结构的定义 + *库相关结构体的定义 ************************************************/ /* @@ -337,4 +337,15 @@ typedef struct standard_data{ List *pd_ctnlst;//数据块连接关系结构的储存链表 }STD_DATA; +/* + *消息的管理及操作的结构 + */ +typedef struct message{ + SID *p_sid;//消息的ID + time_t time;//消息的产生时间 + char titile[16];//消息标题 + unsigned long size;//消息的大小 + char content[0];//消息的正文 +}MSG; + #endif /* type_h */ From 09d1560a3074086b66ec61c6b00c58519ff1ab38 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Thu, 23 Aug 2018 15:24:59 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- communicate/communicate.h | 299 ++++++++++++++++++++++++++++++++++---- list/list.h | 16 +- list/list_expand.h | 4 +- type/type.h | 2 +- 4 files changed, 279 insertions(+), 42 deletions(-) diff --git a/communicate/communicate.h b/communicate/communicate.h index 5ebe1d0..a9ff9e6 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -4,48 +4,285 @@ #include "../type/type.h" #include "../list/list_expand.h" -D_FILE *initDataFileForWrite(char *route); -D_FILE *initDataFileForRead(char *route); -STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size); -STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid); -STD_DATA *initStandardData(unsigned int type, SID *s_id); -int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data); -int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); -int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *data, unsigned long long data_size); -int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); -int dataFileWriteIn(D_FILE *p_dfile); -int dataFileReadOut(D_FILE *p_dfile); -__CALLBACK_STATE(dataFileReadOut); -int releaseSTDBlocks(STD_BLOCKS *p_stdb); -int releaseStandardData(STD_DATA *p_std); -int releaseSTDConnection(STD_CTN *p_stdc); -int releaseDFile(D_FILE *p_file); -unsigned long long calStandardData(STD_DATA *p_std); -__CALLBACK_STATE(calStandardDataCTN); -__CALLBACK_STATE(calStandardDataBLK); + +/************************************************ + 相关结构体初始化: 初始化相关结构体有关函数 + ************************************************/ + +/* + *以写的方式初始化数据文件管理结构 + *参数: route指示数据文件路径 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern D_FILE *initDataFileForWrite(char *route); + +/* + *以读的方式初始化数据文件管理结构 + *参数: route指示数据文件路径 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern D_FILE *initDataFileForRead(char *route); + +/* + *初始化数据块管理结构 + *参数: type指示数据块储存数据的数据类型,data_size指示数据块储存数据的大小 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size); + +/* + *初始化数据块链接关系管理结构 + *参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID. + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid); + +/* + *初始化标准数据结构管理结构 + *参数: type指示标准数据结构所储存的数据结构的数据类型, s_id指示所储存的数据结构的ID, + 若s_id为NULL,则另外分配一个ID.为了方便管理,标准数据结构必须有ID. + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_DATA *initStandardData(unsigned int type, SID *s_id); + + + + + +/************************************************ + 相关结构体的组织: 组织相关结构体有关函数 + ************************************************/ + +/* + *为数据块添加数据 + *参数: data为指向所添加数据所在内存空间的指针 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data); + +/* + *为数据文件添加标准数据结构 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); + +/* + *为标准数据结构添加数据块 + *参数: type指示所添加数据的数据类型, data为指向所添加数据所在内存空间的指针, data_size指示所添加数据的大小 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *data, unsigned long long data_size); + +/* + *为标准数据结构添加数据块链接关系结构体 + *参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); + + + + + +/************************************************ + 数据文件管理结构的整体写入与读出: 对数据文件管理结构的操作 + ************************************************/ + +/* + *将数据文件管理结构写入到相关数据文件中,以储存. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataFileWriteIn(D_FILE *p_dfile); + +/* + *数据文件管理结构中标准数据结构管理结构的简略信息的写入函数 + */ __CALLBACK_STATE(StandardDataInfoWrite); + +/* + *数据文件管理结构中标准数据结构管理结构的内容的写入函数 + */ __CALLBACK_STATE(StandardDataWrite); + +/* + *标准数据结构管理结构中的数据块链接关系管理结构的写入函数 + */ __CALLBACK_STATE(StandardDConnectionWrite); + +/* + *标准数据结构管理结构中的数据块管理结构的写入函数 + */ __CALLBACK_STATE(StandardDBlockWrite); -STD_DATA *listToSTD(List *); -List *standardDataToList(STD_DATA *); +/* + *将相关数据文件中的内容,读出到数据文件管理结构中,等待操作. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataFileReadOut(D_FILE *p_dfile); + +/* + *数据文件管理结构的读出函数的回调函数声明 + */ +__CALLBACK_STATE(dataFileReadOut); + + + + + +/************************************************ + 相关结构的释放操作: 释放相关结构体所占内存空间的相关函数 + ************************************************/ + +/* + *释放数据块所占内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseSTDBlocks(STD_BLOCKS *p_stdb); + +/* + *释放标准数据结构管理结构所占的内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseStandardData(STD_DATA *p_std); + +/* + *释放数据块链接关系管理结构所占的内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseSTDConnection(STD_CTN *p_stdc); + +/* + *释放数据文件管理结构所占的内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseDFile(D_FILE *p_file); + +/* + *计算标准数据结构在文件中占用的空间,以字节为单位. + */ +static unsigned long long calStandardData(STD_DATA *p_std); + +/* + *计算数据块链接关系在文件中的大小 + */ +__CALLBACK_STATE(calStandardDataCTN); + +/* + *计算数据块在文件中的大小 + */ +__CALLBACK_STATE(calStandardDataBLK); + + + + + +/************************************************ + 结构类型的转换: 其他数据结构与标准数据结构的转换相关函数 + ************************************************/ + +/* + *将链表转化为标准数据结构 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_DATA *listToSTD(List *); + +/* + *将标准数据结构转换成链表 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern List *standardDataToList(STD_DATA *); + +/* + *将标准数据结构转换成链表的回调函数 + */ __CALLBACK_STATE(StandardDataToList); -int readDataFileInfo(D_FILE *p_dfile); -int readStandardData(D_FILE *p_dfile, STD_DATA *p_std); -int readSTDBlocks(STD_BLOCKS *p_stdb); -int checkIfDataFile(D_FILE *p_dfile); -int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); -__CALLBACK_STATE(findStandardDataBySid); - -MSG *createMessage(char *title, void *data, unsigned long data_size); -int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port); -void printStandardData(void *value); //STD_DATA *stackToSTD(Stack *); + //STD_DATA *treeToSTD(Tree *); + + + + +/************************************************ + 标准数据结构的随机存取: 标准数据结构的随机存取相关函数 + ************************************************/ + +/* + *读取数据文件的简略信息,为随机存取准备必要信息 + *说明: 该函数只会在数据文件管理结构中建立一个框架,不会读入实际的数据块以及数据块链接关系. + *返回: 处理成功则返回0,不成功则返回-1. + */ +int readDataFileInfo(D_FILE *p_dfile); + +/* + *读取数据文件中的特定标准数据结构 + *参数: p_std为指向框架中的相关标准数据所在内存空间的指针 + *返回: 处理成功则返回0,不成功则返回-1. + */ +int readStandardData(D_FILE *p_dfile, STD_DATA *p_std); + +/* + *读取数据文件中的特定标准数据结构中的数据块 + *返回: 处理成功则返回0,不成功则返回-1. + */ +int readSTDBlocks(STD_BLOCKS *p_stdb); + +/* + *读取文件头,检验文件是否为数据文件 + *返回: 处理成功则返回0,不成功则返回-1. + */ +int checkIfDataFile(D_FILE *p_dfile); + +/* + *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构 + *返回: 处理成功则返回0,不成功则返回-1. + */ +int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); + +/* + *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数 + */ +__CALLBACK_STATE(findStandardDataBySid); + + + + + +/************************************************ + 标准数据结构信息: 获取标准数据结构信息相关函数 + ************************************************/ + +/* + *打印标准数据结构信息 + */ +void printStandardData(void *value); + + + + + +/************************************************ + 消息的操作: 消息的操作相关函数 + ************************************************/ + +/* + *创建消息 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +MSG *createMessage(char *title, void *data, unsigned long data_size); + +/* + *通过ipv4地址发送消息 + *返回: 处理成功则返回0,不成功则返回-1. + */ +int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port); + + + + #endif /* communicate_h */ diff --git a/list/list.h b/list/list.h index c9265f1..61dd983 100644 --- a/list/list.h +++ b/list/list.h @@ -309,42 +309,42 @@ extern unsigned long long len(List *p_list); /* *查询链表是否为空 *返回: 如果链表为空返回1,如果链表不为空则返回0.*/ -int isListEmpty(List *p_list); +extern int isListEmpty(List *p_list); /* *直接获得节点中的整型值 *返回: 返回该节点储存的整型值*/ -int getByIntForNode(Node *); +extern int getByIntForNode(Node *); /* *直接获得节点中的无符号整型值 *返回: 返回该节点储存的无符号整型值*/ -unsigned int getByUIntForNode(Node *); +extern unsigned int getByUIntForNode(Node *); /* *直接获得节点中的浮点值 *返回: 返回该节点储存的浮点值*/ -double getByDoubleForNode(Node *); +extern double getByDoubleForNode(Node *); /* *直接获得节点中的字符串值 *返回: 返回该节点储存的字符串值*/ -char *getByStringForNode(Node *); +extern char *getByStringForNode(Node *); /* *直接获得节点中的指针值 *返回: 返回该节点储存的指针值*/ -void *getByPointerForNode(Node *); +extern void *getByPointerForNode(Node *); /* *直接获得节点的序号 *返回: 返回该节点在链表中的序号*/ -unsigned long long getIndexForNode(List *p_list,Node *p_node); +extern unsigned long long getIndexForNode(List *p_list,Node *p_node); /* *通过节点的序号找到节点中相关的值,并更新其中的储存的值的指针. *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL*/ -Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long index); +extern Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long index); diff --git a/list/list_expand.h b/list/list_expand.h index 0ceb7e7..9703f1c 100644 --- a/list/list_expand.h +++ b/list/list_expand.h @@ -22,12 +22,12 @@ /* *若快速声明回调函数则使用该宏 *参数: name为回调函数名.*/ -#define __CALLBACK_STATE(name) List *_do##name(unsigned int, void *, List *) +#define __CALLBACK_STATE(name) static List *_do##name(unsigned int, void *, List *) /* *若快速定义回调函数则使用该宏 *参数: name为回调函数名.*/ -#define __CALLBACK_DEFINE(name) List *_do##name(unsigned int type, void *value, List *expand_resources) +#define __CALLBACK_DEFINE(name) static List *_do##name(unsigned int type, void *value, List *expand_resources) /* *若传递回调函数指针则使用该宏 diff --git a/type/type.h b/type/type.h index 50b810e..4f8f429 100644 --- a/type/type.h +++ b/type/type.h @@ -173,7 +173,7 @@ typedef struct List{ */ struct index_change{ unsigned long long c_index;//偏移量,有正负之分 - int f_count;//偏移量所对应的数组对的节点 + int f_count;//偏移量所对应的数组的节点 }; /* From ad16089d671bd3e06a4214af2bae33d50e5cbf2a Mon Sep 17 00:00:00 2001 From: Saturneic Date: Thu, 23 Aug 2018 15:49:02 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- communicate/communicate.h | 16 ++-- id/id.h | 159 ++++++++++++++++++++++++++++++++++---- 2 files changed, 151 insertions(+), 24 deletions(-) diff --git a/communicate/communicate.h b/communicate/communicate.h index a9ff9e6..a81de43 100644 --- a/communicate/communicate.h +++ b/communicate/communicate.h @@ -217,32 +217,32 @@ __CALLBACK_STATE(StandardDataToList); *说明: 该函数只会在数据文件管理结构中建立一个框架,不会读入实际的数据块以及数据块链接关系. *返回: 处理成功则返回0,不成功则返回-1. */ -int readDataFileInfo(D_FILE *p_dfile); +extern int readDataFileInfo(D_FILE *p_dfile); /* *读取数据文件中的特定标准数据结构 *参数: p_std为指向框架中的相关标准数据所在内存空间的指针 *返回: 处理成功则返回0,不成功则返回-1. */ -int readStandardData(D_FILE *p_dfile, STD_DATA *p_std); +extern int readStandardData(D_FILE *p_dfile, STD_DATA *p_std); /* *读取数据文件中的特定标准数据结构中的数据块 *返回: 处理成功则返回0,不成功则返回-1. */ -int readSTDBlocks(STD_BLOCKS *p_stdb); +extern int readSTDBlocks(STD_BLOCKS *p_stdb); /* *读取文件头,检验文件是否为数据文件 *返回: 处理成功则返回0,不成功则返回-1. */ -int checkIfDataFile(D_FILE *p_dfile); +extern int checkIfDataFile(D_FILE *p_dfile); /* *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构 *返回: 处理成功则返回0,不成功则返回-1. */ -int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); +extern int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); /* *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数 @@ -260,7 +260,7 @@ __CALLBACK_STATE(findStandardDataBySid); /* *打印标准数据结构信息 */ -void printStandardData(void *value); +extern void printStandardData(void *value); @@ -274,13 +274,13 @@ void printStandardData(void *value); *创建消息 *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. */ -MSG *createMessage(char *title, void *data, unsigned long data_size); +extern MSG *createMessage(char *title, void *data, unsigned long data_size); /* *通过ipv4地址发送消息 *返回: 处理成功则返回0,不成功则返回-1. */ -int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port); +extern int sendMessageIPv4(MSG *p_msg, char *ip, unsigned int port); diff --git a/id/id.h b/id/id.h index fdda689..130386e 100644 --- a/id/id.h +++ b/id/id.h @@ -8,27 +8,154 @@ #include "../type/type.h" #include "md5.h" -void init_rand(void); -unsigned long long getId(void); -SID *getS_id(unsigned int type, unsigned int deep_level); -int fitS_id(SID * const fs_id, SID * const ss_id); -int simFitS_id(SID * fs_id, SID * ss_id); -char *s_idToASCIIString(SID * const s_id); -void setSidToASCIIString(SID * const s_id); -SID *asciiRawStringToS_id(char * const string); -SID *setS_idWithString(char *); -void s_idToMD5(SID *s_id); -char hexToChar(unsigned int); -SID *copyS_id(SID *f_sid); -void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level); +/************************************************ + 伪随机数初始化: 伪随机数初始化有关函数 + ************************************************/ -SID *initS_id(unsigned int deep_level); -int freeSidRaw(SID *s_id); -int freeS_id(SID *s_id); +/* + *用当前时间初始化伪随机数发生器 + */ +static void init_rand(void); + + + + + +/************************************************ + 初始化: 初始化有关函数 + ************************************************/ + +/* + *为一个新的SID管理结构分配内存空间 + *参数: deep_level指示原始ID的复杂度 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +static SID *initS_id(unsigned int deep_level); + +/* + *获得一个新的SID + *参数: deep_level指示原始ID的复杂度,type指示SID所绑定的数据结构的数据类型 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern SID *getS_id(unsigned int type, unsigned int deep_level); + +/* + *通过SID原始数据转换而成的字符串形式的MD5获得一个新的SID + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern SID *setS_idWithString(char *); + +/* + *获得一个新的SID原始数据 + */ +static void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level); + +/* + *获得一个新的ID + */ +extern unsigned long long getId(void); + + + + + +/************************************************ + 比较: ID的比较函数 + ************************************************/ + +/* + *比较两个SID + *返回: 返回strcmp风格的返回值 + */ +extern int fitS_id(SID * const fs_id, SID * const ss_id);\ + +/* + *比较两个SID + *返回: 相同返回1,不相同返回0 + */ +extern int simFitS_id(SID * fs_id, SID * ss_id); + + + + + +/************************************************ + 比较: ID的转换函数 + ************************************************/ + +/* + *将原始SID数据转化成字符串 + *返回: 执行成功相关字符串,不成功则返回NULL + */ +static char *s_idToASCIIRawString(SID * const s_id); + +/* + *将SID中的Hex形式的MD5数据转化成字符串形式的MD5 + */ +extern void setSidToASCIIString(SID * const s_id); + +/* + *将原始SID数据转换成的SID转化回原始SID数据 + *返回: 执行成功相关指向数据结构内存空间的指针,不成功则返回NULL + */ +static SID *asciiRawStringToS_id(char * const string); + +/* + *将原始SID数据转化成MD5的Hex形式的数据 + */ +static void s_idToMD5(SID *s_id); + +/* + *将10进制数字,转化成字符型的16位进制数字 + */ +static char hexToChar(unsigned int); + + + + + +/************************************************ + 复制: 复制ID的函数 + ************************************************/ + +/* + *复制一个既有的SID,得到一个相同的崭新的SID + */ +extern SID *copyS_id(SID *f_sid); + + + + + +/************************************************ + 释放: 释放ID的函数 + ************************************************/ + +/* + *释放SID原始数据所占的内存空间 + */ +extern int freeSidRaw(SID *s_id); + +/* + *释放SID所有已占用的内存空间 + */ +extern int freeS_id(SID *s_id); + + + + + +/************************************************ + 相关全局变量 + ************************************************/ static _Bool if_rand; + + + + #endif /* id_h */ From c00bd6c3fc7ef0ad6fd0061ca615c3583375ddcb Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 24 Aug 2018 00:57:38 +0800 Subject: [PATCH 04/18] Lots of Changes! --- .../project.pbxproj | 218 +++- .../xcdebugger/Breakpoints_v2.xcbkptlist | 676 ++++++------ communicate/communicate.c | 61 +- error/error.c | 114 +- error/error_file.c | 83 ++ id/id.c | 51 +- .../communicate}/communicate.h | 121 ++- include/error/error.h | 54 + error/error.h => include/error/error_file.h | 14 +- {id => include/id}/id.h | 80 +- {id => include/id}/md5.h | 11 +- include/list/list.h | 201 ++++ {list => include/list}/list_expand.h | 252 ++--- include/list/list_expand_1.h | 228 ++++ include/list/list_print.h | 42 + include/list/list_quick.h | 65 ++ include/list/list_simple.h | 79 ++ include/list/list_type.h | 50 + include/list/safe_mode.h | 17 + include/stack/stack.h | 19 + {stack => include/stack}/stack_expand.h | 2 - include/stack/stack_type.h | 31 + {tree => include/tree}/tree.h | 35 +- include/type.h | 91 ++ list/list.c | 985 ------------------ list/list.h | 553 ---------- list/list_copy.c | 44 + list/list_expand.c | 650 ------------ list/list_expand_calculate.c | 13 + list/list_expand_callback.c | 113 ++ list/list_expand_complex.c | 70 ++ list/list_expand_find.c | 126 +++ list/list_expand_get.c | 40 + list/list_expand_node.c | 70 ++ list/list_expand_update.c | 53 + list/list_find.c | 105 ++ list/list_info.c | 12 + list/list_init.c | 59 ++ list/list_insert.c | 65 ++ list/list_print.c | 151 +++ list/list_quick.c | 237 +++++ list/list_release.c | 122 +++ list/list_remove.c | 137 +++ list/list_replace.c | 53 + list/list_simple.c | 67 ++ list/list_simple_node.c | 41 + list/list_sort.c | 50 + list/safe_mode.c | 101 ++ stack/stack.c | 19 +- stack/stack.h | 16 - stack/stack_expand.c | 7 +- test.h | 11 +- type/type.h | 351 ------- 53 files changed, 3610 insertions(+), 3306 deletions(-) create mode 100644 error/error_file.c rename {communicate => include/communicate}/communicate.h (76%) create mode 100644 include/error/error.h rename error/error.h => include/error/error_file.h (53%) rename {id => include/id}/id.h (57%) rename {id => include/id}/md5.h (85%) create mode 100644 include/list/list.h rename {list => include/list}/list_expand.h (59%) create mode 100644 include/list/list_expand_1.h create mode 100644 include/list/list_print.h create mode 100644 include/list/list_quick.h create mode 100644 include/list/list_simple.h create mode 100644 include/list/list_type.h create mode 100644 include/list/safe_mode.h create mode 100644 include/stack/stack.h rename {stack => include/stack}/stack_expand.h (94%) create mode 100644 include/stack/stack_type.h rename {tree => include/tree}/tree.h (69%) create mode 100644 include/type.h delete mode 100644 list/list.c delete mode 100644 list/list.h create mode 100644 list/list_copy.c delete mode 100644 list/list_expand.c create mode 100644 list/list_expand_calculate.c create mode 100644 list/list_expand_callback.c create mode 100644 list/list_expand_complex.c create mode 100644 list/list_expand_find.c create mode 100644 list/list_expand_get.c create mode 100644 list/list_expand_node.c create mode 100644 list/list_expand_update.c create mode 100644 list/list_find.c create mode 100644 list/list_info.c create mode 100644 list/list_init.c create mode 100644 list/list_insert.c create mode 100644 list/list_print.c create mode 100644 list/list_quick.c create mode 100644 list/list_release.c create mode 100644 list/list_remove.c create mode 100644 list/list_replace.c create mode 100644 list/list_simple.c create mode 100644 list/list_simple_node.c create mode 100644 list/list_sort.c create mode 100644 list/safe_mode.c delete mode 100644 stack/stack.h delete mode 100644 type/type.h diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index e9882e2..d7447cc 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -9,13 +9,33 @@ /* Begin PBXBuildFile section */ 9233C310212292B000FB2485 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 9233C30F212292B000FB2485 /* md5.c */; }; 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E7210F1B3D00161557 /* stack_expand.c */; }; - 9269D4EA210F1B4B00161557 /* list_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E9210F1B4B00161557 /* list_expand.c */; }; + 9269D4EA210F1B4B00161557 /* list_expand_get.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E9210F1B4B00161557 /* list_expand_get.c */; }; 9269D4ED210F1B5E00161557 /* test.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4EB210F1B5E00161557 /* test.c */; }; 9269D4F4210F1BB000161557 /* id.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4F2210F1BB000161557 /* id.c */; }; - 9269D4F5210F1BCE00161557 /* list.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246994F20CD000300B4E894 /* list.c */; }; + 9269D4F5210F1BCE00161557 /* list_info.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246994F20CD000300B4E894 /* list_info.c */; }; 9269D4F6210F1CD900161557 /* stack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246995920CE52A700B4E894 /* stack.c */; }; - 9286EB7A211400C900752977 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB79211400C900752977 /* error.c */; }; + 9286EB7A211400C900752977 /* error_file.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB79211400C900752977 /* error_file.c */; }; 9286EB7E2114022A00752977 /* communicate.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB7D2114022A00752977 /* communicate.c */; }; + 92CC992E212EF3E50060EFA5 /* list_quick.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC992D212EF3E50060EFA5 /* list_quick.c */; }; + 92CC9931212EF4BF0060EFA5 /* list_sort.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9930212EF4BF0060EFA5 /* list_sort.c */; }; + 92CC9934212EF5330060EFA5 /* safe_mode.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9933212EF5330060EFA5 /* safe_mode.c */; }; + 92CC9937212EF60A0060EFA5 /* list_print.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9936212EF60A0060EFA5 /* list_print.c */; }; + 92CC993A212EF62A0060EFA5 /* list_simple.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9939212EF62A0060EFA5 /* list_simple.c */; }; + 92CC9943212EFE7E0060EFA5 /* list_expand_find.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */; }; + 92CC9946212EFEF70060EFA5 /* list_expand_callback.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */; }; + 92CC9949212EFF6F0060EFA5 /* list_expand_complex.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */; }; + 92CC994C212F00030060EFA5 /* list_expand_node.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC994B212F00030060EFA5 /* list_expand_node.c */; }; + 92CC994E212F003F0060EFA5 /* list_expand_update.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC994D212F003F0060EFA5 /* list_expand_update.c */; }; + 92CC9950212F014A0060EFA5 /* list_simple_node.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC994F212F014A0060EFA5 /* list_simple_node.c */; }; + 92CC9952212F02200060EFA5 /* list_expand_calculate.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9951212F02200060EFA5 /* list_expand_calculate.c */; }; + 92CC9954212F03190060EFA5 /* list_find.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9953212F03190060EFA5 /* list_find.c */; }; + 92CC9956212F037F0060EFA5 /* list_init.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9955212F037F0060EFA5 /* list_init.c */; }; + 92CC9959212F03CB0060EFA5 /* list_release.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9958212F03CB0060EFA5 /* list_release.c */; }; + 92CC995B212F042E0060EFA5 /* list_remove.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995A212F042E0060EFA5 /* list_remove.c */; }; + 92CC995D212F048B0060EFA5 /* list_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995C212F048B0060EFA5 /* list_copy.c */; }; + 92CC995F212F04EE0060EFA5 /* list_insert.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995E212F04EE0060EFA5 /* list_insert.c */; }; + 92CC9961212F05330060EFA5 /* list_replace.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9960212F05330060EFA5 /* list_replace.c */; }; + 92CC9969212F1DEB0060EFA5 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9968212F1DEB0060EFA5 /* error.c */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -31,9 +51,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 9233C30E212292B000FB2485 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = md5.h; path = id/md5.h; sourceTree = ""; }; + 9233C30E212292B000FB2485 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; 9233C30F212292B000FB2485 /* md5.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = md5.c; path = id/md5.c; sourceTree = ""; }; - 9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list.c; sourceTree = ""; }; + 9246994F20CD000300B4E894 /* list_info.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_info.c; sourceTree = ""; }; 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_expand.h; sourceTree = ""; }; 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list.h; sourceTree = ""; }; 9246995820CE52A700B4E894 /* stack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = ""; }; @@ -42,19 +62,47 @@ 9246995D20CE655900B4E894 /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = ""; }; 9246995E20CE655900B4E894 /* tree.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = ""; }; 9269D4E7210F1B3D00161557 /* stack_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_expand.c; sourceTree = ""; }; - 9269D4E9210F1B4B00161557 /* list_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_expand.c; sourceTree = ""; }; + 9269D4E9210F1B4B00161557 /* list_expand_get.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_expand_get.c; sourceTree = ""; }; 9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = test.c; sourceTree = ""; }; 9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = test.h; sourceTree = ""; }; - 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = type.h; path = type/type.h; sourceTree = ""; }; + 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = type.h; sourceTree = ""; }; 9269D4F2210F1BB000161557 /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = id/id.c; sourceTree = ""; }; - 9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = id.h; path = id/id.h; sourceTree = ""; }; + 9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = id.h; sourceTree = ""; }; 9269D4F7210F1D0B00161557 /* tree_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree_expand.c; sourceTree = ""; }; 9269D4F9210F1D0F00161557 /* tree_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree_expand.h; sourceTree = ""; }; 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ZE-Standard-Libraries"; sourceTree = BUILT_PRODUCTS_DIR; }; - 9286EB79211400C900752977 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = error/error.c; sourceTree = ""; }; - 9286EB7B211400D000752977 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = error.h; path = error/error.h; sourceTree = ""; }; + 9286EB79211400C900752977 /* error_file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error_file.c; path = error/error_file.c; sourceTree = ""; }; 9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; name = communicate.c; path = communicate/communicate.c; sourceTree = ""; }; - 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = communicate.h; path = communicate/communicate.h; sourceTree = ""; }; + 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = communicate.h; sourceTree = ""; }; + 92CC992D212EF3E50060EFA5 /* list_quick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_quick.c; sourceTree = ""; }; + 92CC992F212EF4340060EFA5 /* list_quick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_quick.h; sourceTree = ""; }; + 92CC9930212EF4BF0060EFA5 /* list_sort.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_sort.c; sourceTree = ""; }; + 92CC9932212EF5330060EFA5 /* safe_mode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = safe_mode.h; sourceTree = ""; }; + 92CC9933212EF5330060EFA5 /* safe_mode.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = safe_mode.c; sourceTree = ""; }; + 92CC9935212EF60A0060EFA5 /* list_print.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_print.h; sourceTree = ""; }; + 92CC9936212EF60A0060EFA5 /* list_print.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_print.c; sourceTree = ""; }; + 92CC9938212EF62A0060EFA5 /* list_simple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = list_simple.h; sourceTree = ""; }; + 92CC9939212EF62A0060EFA5 /* list_simple.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_simple.c; sourceTree = ""; }; + 92CC993E212EFB050060EFA5 /* list_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_type.h; sourceTree = ""; }; + 92CC993F212EFD590060EFA5 /* list_expand_1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand_1.h; sourceTree = ""; }; + 92CC9941212EFE050060EFA5 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = error.h; sourceTree = ""; }; + 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_find.c; sourceTree = ""; }; + 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_callback.c; sourceTree = ""; }; + 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_complex.c; sourceTree = ""; }; + 92CC994B212F00030060EFA5 /* list_expand_node.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_node.c; sourceTree = ""; }; + 92CC994D212F003F0060EFA5 /* list_expand_update.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_update.c; sourceTree = ""; }; + 92CC994F212F014A0060EFA5 /* list_simple_node.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_simple_node.c; sourceTree = ""; }; + 92CC9951212F02200060EFA5 /* list_expand_calculate.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_calculate.c; sourceTree = ""; }; + 92CC9953212F03190060EFA5 /* list_find.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_find.c; sourceTree = ""; }; + 92CC9955212F037F0060EFA5 /* list_init.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_init.c; sourceTree = ""; }; + 92CC9958212F03CB0060EFA5 /* list_release.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_release.c; sourceTree = ""; }; + 92CC995A212F042E0060EFA5 /* list_remove.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_remove.c; sourceTree = ""; }; + 92CC995C212F048B0060EFA5 /* list_copy.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_copy.c; sourceTree = ""; }; + 92CC995E212F04EE0060EFA5 /* list_insert.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_insert.c; sourceTree = ""; }; + 92CC9960212F05330060EFA5 /* list_replace.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_replace.c; sourceTree = ""; }; + 92CC9966212F11920060EFA5 /* stack_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_type.h; sourceTree = ""; }; + 92CC9967212F17C70060EFA5 /* error_file.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = error_file.h; sourceTree = ""; }; + 92CC9968212F1DEB0060EFA5 /* error.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = error.c; path = error/error.c; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -71,10 +119,27 @@ 9246994E20CD000300B4E894 /* list */ = { isa = PBXGroup; children = ( - 9246995120CD000300B4E894 /* list.h */, - 9246994F20CD000300B4E894 /* list.c */, - 9246995020CD000300B4E894 /* list_expand.h */, - 9269D4E9210F1B4B00161557 /* list_expand.c */, + 9246994F20CD000300B4E894 /* list_info.c */, + 9269D4E9210F1B4B00161557 /* list_expand_get.c */, + 92CC992D212EF3E50060EFA5 /* list_quick.c */, + 92CC9930212EF4BF0060EFA5 /* list_sort.c */, + 92CC9933212EF5330060EFA5 /* safe_mode.c */, + 92CC9936212EF60A0060EFA5 /* list_print.c */, + 92CC9939212EF62A0060EFA5 /* list_simple.c */, + 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */, + 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */, + 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */, + 92CC994B212F00030060EFA5 /* list_expand_node.c */, + 92CC994D212F003F0060EFA5 /* list_expand_update.c */, + 92CC994F212F014A0060EFA5 /* list_simple_node.c */, + 92CC9951212F02200060EFA5 /* list_expand_calculate.c */, + 92CC9953212F03190060EFA5 /* list_find.c */, + 92CC9955212F037F0060EFA5 /* list_init.c */, + 92CC9958212F03CB0060EFA5 /* list_release.c */, + 92CC995A212F042E0060EFA5 /* list_remove.c */, + 92CC995C212F048B0060EFA5 /* list_copy.c */, + 92CC995E212F04EE0060EFA5 /* list_insert.c */, + 92CC9960212F05330060EFA5 /* list_replace.c */, ); path = list; sourceTree = ""; @@ -82,10 +147,8 @@ 9246995720CE507900B4E894 /* stack */ = { isa = PBXGroup; children = ( - 9246995820CE52A700B4E894 /* stack.h */, 9246995920CE52A700B4E894 /* stack.c */, 9269D4E7210F1B3D00161557 /* stack_expand.c */, - 9246995B20CE5C8900B4E894 /* stack_expand.h */, ); path = stack; sourceTree = ""; @@ -93,7 +156,6 @@ 9246995C20CE654600B4E894 /* tree */ = { isa = PBXGroup; children = ( - 9246995D20CE655900B4E894 /* tree.h */, 9246995E20CE655900B4E894 /* tree.c */, 9269D4F9210F1D0F00161557 /* tree_expand.h */, 9269D4F7210F1D0B00161557 /* tree_expand.c */, @@ -101,20 +163,10 @@ path = tree; sourceTree = ""; }; - 9269D4EF210F1B7800161557 /* type */ = { - isa = PBXGroup; - children = ( - 9269D4F0210F1B8000161557 /* type.h */, - ); - name = type; - sourceTree = ""; - }; 9269D4F1210F1B9E00161557 /* id */ = { isa = PBXGroup; children = ( - 9269D4F3210F1BB000161557 /* id.h */, 9269D4F2210F1BB000161557 /* id.c */, - 9233C30E212292B000FB2485 /* md5.h */, 9233C30F212292B000FB2485 /* md5.c */, ); name = id; @@ -123,11 +175,11 @@ 927993B420CB87D6008CE3A9 = { isa = PBXGroup; children = ( + 92CC993B212EF7400060EFA5 /* include */, 92A15CFC211442C700826FB8 /* graph */, 9286EB7C2114021E00752977 /* communicate */, 9286EB78211400BD00752977 /* error */, 9269D4F1210F1B9E00161557 /* id */, - 9269D4EF210F1B7800161557 /* type */, 9246995C20CE654600B4E894 /* tree */, 9246995720CE507900B4E894 /* stack */, 9246994E20CD000300B4E894 /* list */, @@ -148,8 +200,8 @@ 9286EB78211400BD00752977 /* error */ = { isa = PBXGroup; children = ( - 9286EB79211400C900752977 /* error.c */, - 9286EB7B211400D000752977 /* error.h */, + 9286EB79211400C900752977 /* error_file.c */, + 92CC9968212F1DEB0060EFA5 /* error.c */, ); name = error; sourceTree = ""; @@ -157,7 +209,6 @@ 9286EB7C2114021E00752977 /* communicate */ = { isa = PBXGroup; children = ( - 9286EB7F2114022F00752977 /* communicate.h */, 9286EB7D2114022A00752977 /* communicate.c */, ); name = communicate; @@ -170,6 +221,79 @@ name = graph; sourceTree = ""; }; + 92CC993B212EF7400060EFA5 /* include */ = { + isa = PBXGroup; + children = ( + 92CC9964212F06C10060EFA5 /* communicate */, + 92CC9963212F06650060EFA5 /* tree */, + 92CC9962212F06190060EFA5 /* stack */, + 92CC9940212EFDF50060EFA5 /* error */, + 92CC993D212EF7DE0060EFA5 /* id */, + 92CC993C212EF75C0060EFA5 /* list */, + 9269D4F0210F1B8000161557 /* type.h */, + ); + path = include; + sourceTree = ""; + }; + 92CC993C212EF75C0060EFA5 /* list */ = { + isa = PBXGroup; + children = ( + 9246995120CD000300B4E894 /* list.h */, + 9246995020CD000300B4E894 /* list_expand.h */, + 92CC992F212EF4340060EFA5 /* list_quick.h */, + 92CC9932212EF5330060EFA5 /* safe_mode.h */, + 92CC9935212EF60A0060EFA5 /* list_print.h */, + 92CC9938212EF62A0060EFA5 /* list_simple.h */, + 92CC993E212EFB050060EFA5 /* list_type.h */, + 92CC993F212EFD590060EFA5 /* list_expand_1.h */, + ); + path = list; + sourceTree = ""; + }; + 92CC993D212EF7DE0060EFA5 /* id */ = { + isa = PBXGroup; + children = ( + 9269D4F3210F1BB000161557 /* id.h */, + 9233C30E212292B000FB2485 /* md5.h */, + ); + path = id; + sourceTree = ""; + }; + 92CC9940212EFDF50060EFA5 /* error */ = { + isa = PBXGroup; + children = ( + 92CC9941212EFE050060EFA5 /* error.h */, + 92CC9967212F17C70060EFA5 /* error_file.h */, + ); + path = error; + sourceTree = ""; + }; + 92CC9962212F06190060EFA5 /* stack */ = { + isa = PBXGroup; + children = ( + 9246995B20CE5C8900B4E894 /* stack_expand.h */, + 9246995820CE52A700B4E894 /* stack.h */, + 92CC9966212F11920060EFA5 /* stack_type.h */, + ); + path = stack; + sourceTree = ""; + }; + 92CC9963212F06650060EFA5 /* tree */ = { + isa = PBXGroup; + children = ( + 9246995D20CE655900B4E894 /* tree.h */, + ); + path = tree; + sourceTree = ""; + }; + 92CC9964212F06C10060EFA5 /* communicate */ = { + isa = PBXGroup; + children = ( + 9286EB7F2114022F00752977 /* communicate.h */, + ); + path = communicate; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -226,15 +350,35 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 92CC9931212EF4BF0060EFA5 /* list_sort.c in Sources */, 9233C310212292B000FB2485 /* md5.c in Sources */, + 92CC9961212F05330060EFA5 /* list_replace.c in Sources */, 9269D4F6210F1CD900161557 /* stack.c in Sources */, - 9286EB7A211400C900752977 /* error.c in Sources */, + 92CC9959212F03CB0060EFA5 /* list_release.c in Sources */, + 92CC993A212EF62A0060EFA5 /* list_simple.c in Sources */, + 9286EB7A211400C900752977 /* error_file.c in Sources */, + 92CC992E212EF3E50060EFA5 /* list_quick.c in Sources */, + 92CC9943212EFE7E0060EFA5 /* list_expand_find.c in Sources */, 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */, + 92CC9937212EF60A0060EFA5 /* list_print.c in Sources */, + 92CC994C212F00030060EFA5 /* list_expand_node.c in Sources */, + 92CC9956212F037F0060EFA5 /* list_init.c in Sources */, + 92CC9954212F03190060EFA5 /* list_find.c in Sources */, + 92CC9949212EFF6F0060EFA5 /* list_expand_complex.c in Sources */, + 92CC995D212F048B0060EFA5 /* list_copy.c in Sources */, 9286EB7E2114022A00752977 /* communicate.c in Sources */, - 9269D4EA210F1B4B00161557 /* list_expand.c in Sources */, + 9269D4EA210F1B4B00161557 /* list_expand_get.c in Sources */, 9269D4F4210F1BB000161557 /* id.c in Sources */, 9269D4ED210F1B5E00161557 /* test.c in Sources */, - 9269D4F5210F1BCE00161557 /* list.c in Sources */, + 9269D4F5210F1BCE00161557 /* list_info.c in Sources */, + 92CC9952212F02200060EFA5 /* list_expand_calculate.c in Sources */, + 92CC9946212EFEF70060EFA5 /* list_expand_callback.c in Sources */, + 92CC9950212F014A0060EFA5 /* list_simple_node.c in Sources */, + 92CC9934212EF5330060EFA5 /* safe_mode.c in Sources */, + 92CC9969212F1DEB0060EFA5 /* error.c in Sources */, + 92CC995B212F042E0060EFA5 /* list_remove.c in Sources */, + 92CC994E212F003F0060EFA5 /* list_expand_update.c in Sources */, + 92CC995F212F04EE0060EFA5 /* list_insert.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -354,6 +498,8 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + COPY_HEADERS_RUN_UNIFDEF = NO; + HEADER_SEARCH_PATHS = "\"$(SRCROOT)/include\"/**"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -362,6 +508,8 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + COPY_HEADERS_RUN_UNIFDEF = NO; + HEADER_SEARCH_PATHS = "\"$(SRCROOT)/include\"/**"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 9781d19..7d471f5 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -154,7 +154,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556628194.418951" + timestampString = "556735822.7032" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "45" @@ -186,11 +186,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.086658" + timestampString = "556736003.0999579" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "19" - endingLineNumber = "19" + startingLineNumber = "61" + endingLineNumber = "61" landmarkName = "unknown" landmarkType = "0"> @@ -202,11 +202,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.08676" + timestampString = "556736003.100052" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "114" - endingLineNumber = "114" + startingLineNumber = "156" + endingLineNumber = "156" landmarkName = "s_idToASCIIString" landmarkType = "9"> @@ -218,11 +218,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.086839" + timestampString = "556736003.100122" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "117" - endingLineNumber = "117" + startingLineNumber = "159" + endingLineNumber = "159" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -234,11 +234,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.0869139" + timestampString = "556736003.100186" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "137" - endingLineNumber = "137" + startingLineNumber = "179" + endingLineNumber = "179" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -250,11 +250,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.08699" + timestampString = "556736003.100248" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "151" - endingLineNumber = "151" + startingLineNumber = "193" + endingLineNumber = "193" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -267,11 +267,11 @@ condition = "buff_count == 26" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087065" + timestampString = "556736003.100322" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "143" - endingLineNumber = "143" + startingLineNumber = "185" + endingLineNumber = "185" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -284,11 +284,11 @@ condition = "string_len != 25" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087142" + timestampString = "556736003.100385" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "206" - endingLineNumber = "206" + startingLineNumber = "249" + endingLineNumber = "249" landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -300,11 +300,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087216" + timestampString = "556736003.1004519" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "148" - endingLineNumber = "148" + startingLineNumber = "190" + endingLineNumber = "190" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -317,11 +317,11 @@ condition = "buff_count == 26" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087289" + timestampString = "556736003.100516" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "154" - endingLineNumber = "154" + startingLineNumber = "196" + endingLineNumber = "196" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -333,11 +333,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087364" + timestampString = "556736003.100578" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "158" - endingLineNumber = "158" + startingLineNumber = "200" + endingLineNumber = "200" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -349,11 +349,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087438" + timestampString = "556736003.100642" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "162" - endingLineNumber = "162" + startingLineNumber = "204" + endingLineNumber = "204" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -365,11 +365,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.08751" + timestampString = "556736003.100713" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "212" - endingLineNumber = "212" + startingLineNumber = "255" + endingLineNumber = "255" landmarkName = "asciiRawStringToS_id" landmarkType = "9"> @@ -381,11 +381,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087581" + timestampString = "556736003.100777" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "255" - endingLineNumber = "255" + startingLineNumber = "298" + endingLineNumber = "298" landmarkName = "unknown" landmarkType = "0"> @@ -397,11 +397,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087653" + timestampString = "556736003.100841" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "199" - endingLineNumber = "199" + startingLineNumber = "241" + endingLineNumber = "241" landmarkName = "s_idToASCIIRawString" landmarkType = "9"> @@ -413,11 +413,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087724" + timestampString = "556736003.100904" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "26" - endingLineNumber = "26" + startingLineNumber = "68" + endingLineNumber = "68" landmarkName = "initS_id" landmarkType = "9"> @@ -429,71 +429,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.087793" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "211" - endingLineNumber = "211" - landmarkName = "asciiRawStringToS_id" - landmarkType = "9"> - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -525,7 +525,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556615437.3113" + timestampString = "556724762.552367" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "84" @@ -541,11 +541,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.419407" + timestampString = "556736003.101464" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "111" - endingLineNumber = "111" + startingLineNumber = "169" + endingLineNumber = "169" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -557,11 +557,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.419521" + timestampString = "556736003.101581" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "107" - endingLineNumber = "107" + startingLineNumber = "165" + endingLineNumber = "165" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -573,11 +573,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.41959" + timestampString = "556736003.1016541" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "224" - endingLineNumber = "224" + startingLineNumber = "281" + endingLineNumber = "281" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -589,11 +589,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.419654" + timestampString = "556736003.101725" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "216" - endingLineNumber = "216" + startingLineNumber = "273" + endingLineNumber = "273" landmarkName = "releaseDFile" landmarkType = "9"> @@ -605,11 +605,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.419724" + timestampString = "556736003.101802" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "170" - endingLineNumber = "170" + startingLineNumber = "228" + endingLineNumber = "228" landmarkName = "listToSTD" landmarkType = "9"> @@ -621,11 +621,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4197839" + timestampString = "556736003.101868" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "38" - endingLineNumber = "38" + startingLineNumber = "96" + endingLineNumber = "96" landmarkName = "initStandardData" landmarkType = "9"> @@ -637,11 +637,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.419843" + timestampString = "556736003.101934" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "109" - endingLineNumber = "109" + startingLineNumber = "167" + endingLineNumber = "167" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -653,11 +653,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.089959" + timestampString = "556736003.101999" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "270" - endingLineNumber = "270" + startingLineNumber = "313" + endingLineNumber = "313" landmarkName = "freeSidRaw" landmarkType = "9"> @@ -669,11 +669,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4199179" + timestampString = "556736003.102102" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "7" - endingLineNumber = "7" + startingLineNumber = "65" + endingLineNumber = "65" landmarkName = "initStandardDBlocks" landmarkType = "9"> @@ -685,11 +685,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.419981" + timestampString = "556736003.10221" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "46" - endingLineNumber = "46" + startingLineNumber = "104" + endingLineNumber = "104" landmarkName = "initStandardData" landmarkType = "9"> @@ -701,11 +701,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.420041" + timestampString = "556736003.102289" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "150" - endingLineNumber = "150" + startingLineNumber = "208" + endingLineNumber = "208" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -717,11 +717,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.420101" + timestampString = "556736003.102362" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "131" - endingLineNumber = "131" + startingLineNumber = "189" + endingLineNumber = "189" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -733,11 +733,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4201601" + timestampString = "556736003.102428" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "133" - endingLineNumber = "133" + startingLineNumber = "191" + endingLineNumber = "191" landmarkName = "unknown" landmarkType = "0"> @@ -749,12 +749,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556615437.311588" + timestampString = "556724762.5526021" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "104" endingLineNumber = "104" - landmarkName = "listThrough" + landmarkName = "s_findByIndexForNode" landmarkType = "9"> @@ -765,11 +765,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.42024" + timestampString = "556736003.102544" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "253" - endingLineNumber = "253" + startingLineNumber = "310" + endingLineNumber = "310" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -781,11 +781,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.420329" + timestampString = "556736003.102614" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "257" - endingLineNumber = "257" + startingLineNumber = "314" + endingLineNumber = "314" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -797,11 +797,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.420463" + timestampString = "556736003.10268" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "254" - endingLineNumber = "254" + startingLineNumber = "311" + endingLineNumber = "311" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -813,13 +813,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list.c" - timestampString = "556628194.4205739" + timestampString = "556725129.068965" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "527" - endingLineNumber = "527" - landmarkName = "copyNode" - landmarkType = "9"> + startingLineNumber = "541" + endingLineNumber = "541"> @@ -845,11 +843,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.091946" + timestampString = "556736003.102844" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "107" - endingLineNumber = "107" + startingLineNumber = "149" + endingLineNumber = "149" landmarkName = "s_idToASCIIString" landmarkType = "9"> @@ -861,7 +859,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "test.c" - timestampString = "556628194.421555" + timestampString = "556735822.705568" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "104" @@ -875,11 +873,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.421712" + timestampString = "556736003.102957" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "151" - endingLineNumber = "151" + startingLineNumber = "209" + endingLineNumber = "209" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -891,11 +889,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.421832" + timestampString = "556736003.103039" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "298" - endingLineNumber = "298" + startingLineNumber = "355" + endingLineNumber = "355" landmarkName = "unknown" landmarkType = "0"> @@ -907,11 +905,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.421981" + timestampString = "556736003.103106" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "310" - endingLineNumber = "310" + startingLineNumber = "367" + endingLineNumber = "367" landmarkName = "unknown" landmarkType = "0"> @@ -923,11 +921,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422099" + timestampString = "556736003.1031719" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "320" - endingLineNumber = "320" + startingLineNumber = "377" + endingLineNumber = "377" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -939,11 +937,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422244" + timestampString = "556736003.103237" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "302" - endingLineNumber = "302" + startingLineNumber = "359" + endingLineNumber = "359" landmarkName = "unknown" landmarkType = "0"> @@ -955,11 +953,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422321" + timestampString = "556736003.103299" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "329" - endingLineNumber = "329" + startingLineNumber = "386" + endingLineNumber = "386" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -971,7 +969,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556615437.312217" + timestampString = "556724762.553207" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "113" @@ -987,11 +985,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422406" + timestampString = "556736003.103398" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "101" - endingLineNumber = "101" + startingLineNumber = "159" + endingLineNumber = "159" landmarkName = "dataFileWriteIn" landmarkType = "9"> @@ -1003,11 +1001,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422477" + timestampString = "556736003.103465" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "304" - endingLineNumber = "304" + startingLineNumber = "361" + endingLineNumber = "361" landmarkName = "unknown" landmarkType = "0"> @@ -1019,11 +1017,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4225399" + timestampString = "556736003.10353" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "314" - endingLineNumber = "314" + startingLineNumber = "371" + endingLineNumber = "371" landmarkName = "unknown" landmarkType = "0"> @@ -1035,11 +1033,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422606" + timestampString = "556736003.103595" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "312" - endingLineNumber = "312" + startingLineNumber = "369" + endingLineNumber = "369" landmarkName = "unknown" landmarkType = "0"> @@ -1051,11 +1049,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422668" + timestampString = "556736003.103659" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "326" - endingLineNumber = "326" + startingLineNumber = "383" + endingLineNumber = "383" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1067,11 +1065,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4227279" + timestampString = "556736003.103724" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "327" - endingLineNumber = "327" + startingLineNumber = "384" + endingLineNumber = "384" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1083,11 +1081,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422786" + timestampString = "556736003.1037869" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "305" - endingLineNumber = "305" + startingLineNumber = "362" + endingLineNumber = "362" landmarkName = "unknown" landmarkType = "0"> @@ -1099,11 +1097,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422851" + timestampString = "556736003.103852" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "301" - endingLineNumber = "301" + startingLineNumber = "358" + endingLineNumber = "358" landmarkName = "unknown" landmarkType = "0"> @@ -1115,11 +1113,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.422912" + timestampString = "556736003.103917" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "324" - endingLineNumber = "324" + startingLineNumber = "381" + endingLineNumber = "381" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1131,11 +1129,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "id/id.c" - timestampString = "556538937.095067" + timestampString = "556736003.1039799" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "336" - endingLineNumber = "336" + startingLineNumber = "379" + endingLineNumber = "379" landmarkName = "setS_idWithString" landmarkType = "9"> @@ -1147,11 +1145,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4229929" + timestampString = "556736003.1040421" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "359" - endingLineNumber = "359" + startingLineNumber = "416" + endingLineNumber = "416" landmarkName = "readStandardData" landmarkType = "9"> @@ -1163,11 +1161,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423056" + timestampString = "556736003.104105" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "328" - endingLineNumber = "328" + startingLineNumber = "385" + endingLineNumber = "385" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1179,11 +1177,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423116" + timestampString = "556736003.1041681" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "80" - endingLineNumber = "80" + startingLineNumber = "138" + endingLineNumber = "138" landmarkName = "initDataFileForRead" landmarkType = "9"> @@ -1195,11 +1193,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423192" + timestampString = "556736003.10423" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "334" - endingLineNumber = "334" + startingLineNumber = "391" + endingLineNumber = "391" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1211,11 +1209,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4232531" + timestampString = "556736003.104292" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "87" - endingLineNumber = "87" + startingLineNumber = "145" + endingLineNumber = "145" landmarkName = "dataFileAddStandardData" landmarkType = "9"> @@ -1227,11 +1225,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423311" + timestampString = "556736003.104354" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "88" - endingLineNumber = "88" + startingLineNumber = "146" + endingLineNumber = "146" landmarkName = "dataFileAddStandardData" landmarkType = "9"> @@ -1243,11 +1241,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.42337" + timestampString = "556736003.104417" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "89" - endingLineNumber = "89" + startingLineNumber = "147" + endingLineNumber = "147" landmarkName = "dataFileAddStandardData" landmarkType = "9"> @@ -1259,13 +1257,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556615437.312484" + timestampString = "556724762.5534379" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "638" - endingLineNumber = "638" - landmarkName = "printListForCustom" - landmarkType = "9"> + endingLineNumber = "638"> @@ -1291,11 +1287,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423503" + timestampString = "556736003.104582" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "403" - endingLineNumber = "403" + startingLineNumber = "460" + endingLineNumber = "460" landmarkName = "printStandardData" landmarkType = "9"> @@ -1307,11 +1303,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.42356" + timestampString = "556736003.104646" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "349" - endingLineNumber = "349" + startingLineNumber = "406" + endingLineNumber = "406" landmarkName = "readStandardData" landmarkType = "9"> @@ -1323,11 +1319,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423618" + timestampString = "556736003.10471" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "355" - endingLineNumber = "355" + startingLineNumber = "412" + endingLineNumber = "412" landmarkName = "readStandardData" landmarkType = "9"> @@ -1339,11 +1335,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4236749" + timestampString = "556736003.104777" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "230" - endingLineNumber = "230" + startingLineNumber = "287" + endingLineNumber = "287" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1355,11 +1351,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423736" + timestampString = "556736003.104844" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "220" - endingLineNumber = "220" + startingLineNumber = "277" + endingLineNumber = "277" landmarkName = "standardDataToList" landmarkType = "9"> @@ -1371,11 +1367,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4238009" + timestampString = "556736003.104982" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "370" - endingLineNumber = "370" + startingLineNumber = "427" + endingLineNumber = "427" landmarkName = "readStandardData" landmarkType = "9"> @@ -1387,11 +1383,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423861" + timestampString = "556736003.105054" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "369" - endingLineNumber = "369" + startingLineNumber = "426" + endingLineNumber = "426" landmarkName = "readStandardData" landmarkType = "9"> @@ -1403,11 +1399,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.423918" + timestampString = "556736003.1051199" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "149" - endingLineNumber = "149" + startingLineNumber = "207" + endingLineNumber = "207" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1419,11 +1415,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.4239759" + timestampString = "556736003.105185" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "385" - endingLineNumber = "385" + startingLineNumber = "442" + endingLineNumber = "442" landmarkName = "readStandardData" landmarkType = "9"> @@ -1435,11 +1431,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.424034" + timestampString = "556736003.105251" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "228" - endingLineNumber = "228" + startingLineNumber = "285" + endingLineNumber = "285" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1451,7 +1447,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556615437.312681" + timestampString = "556724762.553586" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "131" @@ -1467,7 +1463,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "list/list_expand.c" - timestampString = "556615437.312759" + timestampString = "556724762.553628" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "112" @@ -1483,11 +1479,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556628194.424129" + timestampString = "556736003.10543" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "271" - endingLineNumber = "271" + startingLineNumber = "328" + endingLineNumber = "328" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1498,24 +1494,8 @@ shouldBeEnabled = "No" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "list/list.c" - timestampString = "556628194.424193" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "203" - endingLineNumber = "203" - landmarkName = "insertInTail" - landmarkType = "9"> - - - - - - - - - - - - + startingLineNumber = "162" + endingLineNumber = "162"> + + + + + + + + diff --git a/communicate/communicate.c b/communicate/communicate.c index 72a05ce..71bcd9d 100644 --- a/communicate/communicate.c +++ b/communicate/communicate.c @@ -1,4 +1,62 @@ -#include "communicate.h" +#include +#include +#include +#include +#include +#include +#include + +/* + *计算标准数据结构在文件中占用的空间,以字节为单位. + */ +static unsigned long long calStandardData(STD_DATA *p_std); + +/* + *数据文件管理结构中标准数据结构管理结构的简略信息的写入函数 + */ +__CALLBACK_STATE(StandardDataInfoWrite); + +/* + *数据文件管理结构中标准数据结构管理结构的内容的写入函数 + */ +__CALLBACK_STATE(StandardDataWrite); + +/* + *标准数据结构管理结构中的数据块链接关系管理结构的写入函数 + */ +__CALLBACK_STATE(StandardDConnectionWrite); + +/* + *标准数据结构管理结构中的数据块管理结构的写入函数 + */ +__CALLBACK_STATE(StandardDBlockWrite); + +/* + *数据文件管理结构的读出函数的回调函数声明 + */ +__CALLBACK_STATE(dataFileReadOut); + +/* + *计算数据块链接关系在文件中的大小 + */ +__CALLBACK_STATE(calStandardDataCTN); + +/* + *计算数据块在文件中的大小 + */ +__CALLBACK_STATE(calStandardDataBLK); + +/* + *将标准数据结构转换成链表的回调函数 + */ +__CALLBACK_STATE(StandardDataToList); + +/* + *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数 + */ +__CALLBACK_STATE(findStandardDataBySid); + + STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size){ STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); @@ -175,7 +233,6 @@ int dataFileReadOut(D_FILE *p_dfile){ listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(dataFileReadOut), __SEND_ARG("%p", p_dfile)); } - showError(pushError(DATA_FILE, STANDARD, initInfo("dataFileReadOut()", "Datafile not complete."))); return -1; } diff --git a/error/error.c b/error/error.c index 9756a3c..0d059b5 100644 --- a/error/error.c +++ b/error/error.c @@ -1,81 +1,53 @@ -#include "error.h" +#include +#include -int initErrorSystem(void) { - error_list = initList(0); - notice_list = initList(0); - if_error = 1; - return 1; -} - -int setLogDirectory(const char *path) { - logfile.id = getId(); - unsigned long memory_space = strlen(path) + 256; - char *file_path = (char *)malloc(sizeof(char)*memory_space); - - strcat(file_path, path); - strcat(file_path, "log"); - sprintf(file_path, "%lu", logfile.id); - - if ((logfile.fp = fopen(file_path, "w")) == NULL) { - printf("Cannot set logfile!"); - return 0; - } - logfile.if_enable = 1; - - free(file_path); - return 1; -} - -int closeLogDirectory(void) { - Node *p = error_list->head; - while (p != NULL) { - saveError(p->value); - p = p->next; - } - - p = notice_list->head; - while (p != NULL) { - saveNotice(p->value); - p = p->next; - } - - releaseList(error_list); - releaseList(notice_list); - if_error = 0; - fclose(logfile.fp); - logfile.if_enable = 0; +int pushInfo(Info *p_info, const char *head, const char *body) { + strcpy(p_info->head, head); + strcpy(p_info->body, body); return 0; } -int loadFromFile(FILE *fp,char* number) { - - return 1; +Error *pushError(unsigned int type, int pri, Info *p_info) { + Error *p_error = (Error *)malloc(sizeof(Error)); + p_error->type = type; + p_error->priority = pri; + p_error->info = *p_info; + p_error->time = time(NULL); + free(p_info); + return p_error; } -int saveError(Error *p_error) { - fprintf(logfile.fp, - "--------------------\n\ - ERROR\n\ - Type : %ud\n\ - Priority : %d\n\ - Time : %s\n\ - Info : \n\ - %s\n\ - %s\n\ - ---------------------\n", - p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->info.head, p_error->info.body); +Notice *pushNotice(unsigned int type, Info *p_info) { + Notice *p_notice = (Notice *)malloc(sizeof(Notice)); + p_notice->type = type; + p_notice->info = *p_info; + p_notice->time = time(NULL); + free(p_info); + return p_notice; +} + +Info *initInfo(const char *head, const char *body){ + Info *p_info = (Info *)malloc(sizeof(Info)); + pushInfo(p_info, head, body); + return p_info; +} + +int showError(Error *p_error){ + printf("\n"); + for (int i = 0; i < p_error->priority; i++) { + printf("!"); + } + + printf("(Error) %s\n",asctime(localtime(&p_error->time))); + printf("%s: %s.\n",p_error->info.head,p_error->info.body); + free(p_error); return 0; } -int saveNotice(Notice *p_notice) { - fprintf(logfile.fp, - "--------------------\n\ - NOTICE\n\ - Type : %ud\n\ - Time : %s\n\ - Info : \n\ - %s\n\ - %s\n\ - ----------------------\n", - p_notice->type, ctime( &(p_notice->time) ), p_notice->info.head, p_notice->info.body); + +int showWarning(Notice *p_notice){ + printf("\n@"); + printf("(Warning) %s\n",asctime(localtime(&p_notice->time))); + printf("%s: %s.\n",p_notice->info.head,p_notice->info.body); + free(p_notice); return 0; } diff --git a/error/error_file.c b/error/error_file.c new file mode 100644 index 0000000..fb035ec --- /dev/null +++ b/error/error_file.c @@ -0,0 +1,83 @@ +#include + +int initErrorSystem(void) { + error_list = initList(0); + notice_list = initList(0); + if_error = 1; + return 1; +} + +int setLogDirectory(const char *path) { +#ifdef id_enable + logfile.id = getId(); +#endif + unsigned long memory_space = strlen(path) + 256; + char *file_path = (char *)malloc(sizeof(char)*memory_space); + + strcat(file_path, path); + strcat(file_path, "log"); + sprintf(file_path, "%lu", logfile.id); + + if ((logfile.fp = fopen(file_path, "w")) == NULL) { + printf("Cannot set logfile!"); + return 0; + } + logfile.if_enable = 1; + + free(file_path); + return 1; +} + +int closeLogDirectory(void) { + Node *p = error_list->head; + while (p != NULL) { + saveError(p->value); + p = p->next; + } + + p = notice_list->head; + while (p != NULL) { + saveNotice(p->value); + p = p->next; + } + + releaseList(error_list); + releaseList(notice_list); + if_error = 0; + fclose(logfile.fp); + logfile.if_enable = 0; + return 0; +} + +int loadFromFile(FILE *fp,char* number) { + + return 1; +} + +int saveError(Error *p_error) { + fprintf(logfile.fp, + "--------------------\n\ + ERROR\n\ + Type : %ud\n\ + Priority : %d\n\ + Time : %s\n\ + Info : \n\ + %s\n\ + %s\n\ + ---------------------\n", + p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->info.head, p_error->info.body); + return 0; +} +int saveNotice(Notice *p_notice) { + fprintf(logfile.fp, + "--------------------\n\ + NOTICE\n\ + Type : %ud\n\ + Time : %s\n\ + Info : \n\ + %s\n\ + %s\n\ + ----------------------\n", + p_notice->type, ctime( &(p_notice->time) ), p_notice->info.head, p_notice->info.body); + return 0; +} diff --git a/id/id.c b/id/id.c index a2182b0..0b2a12f 100644 --- a/id/id.c +++ b/id/id.c @@ -1,8 +1,50 @@ -#include "id.h" +#include +#include static _Bool if_rand = 0; -void init_rand(void) { +/* + *用当前时间初始化伪随机数发生器 + */ +static void init_rand(void); + +/* + *为一个新的SID管理结构分配内存空间 + *参数: deep_level指示原始ID的复杂度 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +static SID *initS_id(unsigned int deep_level); + +/* + *将原始SID数据转化成MD5的Hex形式的数据 + */ +static void s_idToMD5(SID *s_id); + + +/* + *将原始SID数据转化成字符串 + *返回: 执行成功相关字符串,不成功则返回NULL + */ +static char *s_idToASCIIRawString(SID * const s_id); + + +/* + *将10进制数字,转化成字符型的16位进制数字 + */ +static char hexToChar(unsigned int); + +/* + *将原始SID数据转换成的SID转化回原始SID数据 + *返回: 执行成功相关指向数据结构内存空间的指针,不成功则返回NULL + */ +static SID *asciiRawStringToS_id(char * const string); + +/* + *获得一个新的SID原始数据 + */ +static void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level); + +static void init_rand(void) { srand((unsigned)time(NULL)); } @@ -17,7 +59,7 @@ unsigned long long getId(void) { return id; } -SID *initS_id(unsigned int deep_level){ +static SID *initS_id(unsigned int deep_level){ if (!if_rand){ init_rand(); if_rand = 1; @@ -197,7 +239,8 @@ char *s_idToASCIIRawString(SID * const s_id){ } } -SID *asciiRawStringToS_id(char * const string){ + +static SID *asciiRawStringToS_id(char * const string){ SID *s_id = NULL; unsigned long long string_len = strlen(string); diff --git a/communicate/communicate.h b/include/communicate/communicate.h similarity index 76% rename from communicate/communicate.h rename to include/communicate/communicate.h index a81de43..33cbdd8 100644 --- a/communicate/communicate.h +++ b/include/communicate/communicate.h @@ -1,9 +1,76 @@ #ifndef communicate_h #define communicate_h -#include "../type/type.h" -#include "../list/list_expand.h" +/* + *文件头信息的管理及操作的结构 + */ +typedef struct file_head{ + char head_test[18];//数据文件头部的验证信息 + unsigned long long data_num;//数据文件中的标准数据结构的数目 +}F_HEAD; +/* + *数据文件的管理及操作的结构 + */ +typedef struct data_file{ + FILE *fp;//数据文件 + F_HEAD *pf_head;//数据文件头 + List *pf_stdlst;//数据文件的标志数据结构的储存链表 +}D_FILE; + +/* + *标准数据结构的管理及操作的结构 + */ +typedef struct standard_data_blocks{ + unsigned int type;//数据块的类型 + unsigned long long location;//数据块在数据文件中的定位 + char *sid;//数据块的ID + _Bool if_data;//数据块是否赋值 + unsigned int blocks_num;//数据块字节大小 + char *buff;//指向数据块储存值内存空间的指针 +}STD_BLOCKS; + +/* + *标准数据结构中数据块的连接关系的管理及操作的结构 + */ +typedef struct standard_data_connection{ + unsigned long long location;//数据块链接关系结构在文件中的定位 + char *f_sid;//前一个数据块的ID + char *s_sid;//后一个数据块的ID +}STD_CTN; + +/* + *标准数据结构头的管理及操作的结构 + */ +typedef struct standard_data_head{ + unsigned long long data_blk_num;//数据块的数目 + unsigned long long data_ctn_num;//数据块链接关系结构的数目 +}STD_HEAD; + +/* + *标准数据结构的管理及操作的结构 + */ +typedef struct standard_data{ + SID *s_id;//标准数据结构的ID + int read_data;//标准数据结构是否已经读取完整 + unsigned int type;//标准数据结构所对应的类型 + unsigned long long size;//标准数据结构在数据文件中的大小 + unsigned long long location;//标准数据结构的头在数据文件中的定位 + _Bool lock;//标准数据文件是否被锁住 + List *pd_blocklst;//数据块储存链表 + List *pd_ctnlst;//数据块连接关系结构的储存链表 +}STD_DATA; + +/* + *消息的管理及操作的结构 + */ +typedef struct message{ + SID *p_sid;//消息的ID + time_t time;//消息的产生时间 + char titile[16];//消息标题 + unsigned long size;//消息的大小 + char content[0];//消息的正文 +}MSG; @@ -97,36 +164,13 @@ extern int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); */ extern int dataFileWriteIn(D_FILE *p_dfile); -/* - *数据文件管理结构中标准数据结构管理结构的简略信息的写入函数 - */ -__CALLBACK_STATE(StandardDataInfoWrite); - -/* - *数据文件管理结构中标准数据结构管理结构的内容的写入函数 - */ -__CALLBACK_STATE(StandardDataWrite); - -/* - *标准数据结构管理结构中的数据块链接关系管理结构的写入函数 - */ -__CALLBACK_STATE(StandardDConnectionWrite); - -/* - *标准数据结构管理结构中的数据块管理结构的写入函数 - */ -__CALLBACK_STATE(StandardDBlockWrite); - /* *将相关数据文件中的内容,读出到数据文件管理结构中,等待操作. *返回: 处理成功则返回0,不成功则返回-1. */ extern int dataFileReadOut(D_FILE *p_dfile); -/* - *数据文件管理结构的读出函数的回调函数声明 - */ -__CALLBACK_STATE(dataFileReadOut); + @@ -160,21 +204,6 @@ extern int releaseSTDConnection(STD_CTN *p_stdc); */ extern int releaseDFile(D_FILE *p_file); -/* - *计算标准数据结构在文件中占用的空间,以字节为单位. - */ -static unsigned long long calStandardData(STD_DATA *p_std); - -/* - *计算数据块链接关系在文件中的大小 - */ -__CALLBACK_STATE(calStandardDataCTN); - -/* - *计算数据块在文件中的大小 - */ -__CALLBACK_STATE(calStandardDataBLK); - @@ -195,11 +224,6 @@ extern STD_DATA *listToSTD(List *); */ extern List *standardDataToList(STD_DATA *); -/* - *将标准数据结构转换成链表的回调函数 - */ -__CALLBACK_STATE(StandardDataToList); - //STD_DATA *stackToSTD(Stack *); //STD_DATA *treeToSTD(Tree *); @@ -244,11 +268,6 @@ extern int checkIfDataFile(D_FILE *p_dfile); */ extern int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); -/* - *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数 - */ -__CALLBACK_STATE(findStandardDataBySid); - diff --git a/include/error/error.h b/include/error/error.h new file mode 100644 index 0000000..8dbf137 --- /dev/null +++ b/include/error/error.h @@ -0,0 +1,54 @@ +#ifndef error_h +#define error_h + +#include + +/* + *错误管理中信息的管理及操作的结构 + */ +typedef struct Info{ + char head[64];//信息头 + char body[256];//信息内容 +}Info; + +/* + *错误管理中错误的管理及操作的结构 + */ +typedef struct Error{ + unsigned int type;//错误类型号 + int priority;//优先级 + time_t time;//错误产生的时间 + Info info;//信息指针 +}Error; + +/* + *错误管理中警告的管理及操作的结构 + */ +typedef struct Notice{ + unsigned int type;//警告类型号 + time_t time;//警告产生的时间 + Info info;//信息指针 +}Notice; + +/*********************************************** + *错误的提示:出现错误时,以下函数用于快捷地通报错误信息, + * 以便根据信息快速找到错误原因. + **********************************************/ + +extern int pushInfo(Info *p_info, const char *head,const char *body); + +extern Error *pushError(unsigned int type, int pri, Info *p_info); + +extern Notice *pushNotice(unsigned int type, Info *p_info); + +extern Info *initInfo(const char *head, const char *body); + +extern Error *createError(Info *info,unsigned int type,int pri); + +extern Notice *createWarning(Info *info, unsigned int type, int pri); + +extern int showError(Error *); + +extern int showWarning(Notice *); + +#endif /* error_h */ diff --git a/error/error.h b/include/error/error_file.h similarity index 53% rename from error/error.h rename to include/error/error_file.h index f1e8d41..25d2a11 100644 --- a/error/error.h +++ b/include/error/error_file.h @@ -1,8 +1,18 @@ #ifndef ERROR_H #define ERROR_H -#include "../type/type.h" -#include "../list/list_expand.h" +#include +#include +#include + +/* + *错误管理中日志信息的管理及操作的结构 + */ +typedef struct Log{ + FILE *fp;//日志文件的指针 + int if_enable;//日志文件是否启用 + unsigned long int id;//日志文件的ID +}Log; Log logfile; List *error_list = NULL; diff --git a/id/id.h b/include/id/id.h similarity index 57% rename from id/id.h rename to include/id/id.h index 130386e..63f15d2 100644 --- a/id/id.h +++ b/include/id/id.h @@ -1,26 +1,31 @@ #ifndef id_h #define id_h -#include -#include -#include -#include -#include "../type/type.h" -#include "md5.h" +#include +#include - - - -/************************************************ - 伪随机数初始化: 伪随机数初始化有关函数 - ************************************************/ - /* - *用当前时间初始化伪随机数发生器 + *SID的初始值管理及操作的结构 */ -static void init_rand(void); +struct sid_raw{ + unsigned int type; + unsigned int *value;//4 + unsigned int *value_deeper;//8 + unsigned int *value_deepest;//32 +}; +/* + *SID的管理及操作的结构 + */ +typedef struct s_id{ + struct sid_raw *sr;//指向SID初始值 + unsigned int deep;//SID初始值的复杂度 + MD5_CTX *md5;//指向MD5结构 + unsigned char *decrypt_hex;//指向MD5的Hex信息 + char *decrypt_str;//指向MD5的Hex信息转化成的字符串 + +}SID; @@ -29,13 +34,6 @@ static void init_rand(void); 初始化: 初始化有关函数 ************************************************/ -/* - *为一个新的SID管理结构分配内存空间 - *参数: deep_level指示原始ID的复杂度 - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -static SID *initS_id(unsigned int deep_level); - /* *获得一个新的SID *参数: deep_level指示原始ID的复杂度,type指示SID所绑定的数据结构的数据类型 @@ -49,11 +47,6 @@ extern SID *getS_id(unsigned int type, unsigned int deep_level); */ extern SID *setS_idWithString(char *); -/* - *获得一个新的SID原始数据 - */ -static void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level); - /* *获得一个新的ID */ @@ -87,34 +80,12 @@ extern int simFitS_id(SID * fs_id, SID * ss_id); 比较: ID的转换函数 ************************************************/ -/* - *将原始SID数据转化成字符串 - *返回: 执行成功相关字符串,不成功则返回NULL - */ -static char *s_idToASCIIRawString(SID * const s_id); - /* *将SID中的Hex形式的MD5数据转化成字符串形式的MD5 */ extern void setSidToASCIIString(SID * const s_id); -/* - *将原始SID数据转换成的SID转化回原始SID数据 - *返回: 执行成功相关指向数据结构内存空间的指针,不成功则返回NULL - */ -static SID *asciiRawStringToS_id(char * const string); - -/* - *将原始SID数据转化成MD5的Hex形式的数据 - */ -static void s_idToMD5(SID *s_id); - -/* - *将10进制数字,转化成字符型的16位进制数字 - */ -static char hexToChar(unsigned int); - - +char *s_idToASCIIString(SID * const s_id); @@ -149,13 +120,4 @@ extern int freeS_id(SID *s_id); -/************************************************ - 相关全局变量 - ************************************************/ - -static _Bool if_rand; - - - - #endif /* id_h */ diff --git a/id/md5.h b/include/id/md5.h similarity index 85% rename from id/md5.h rename to include/id/md5.h index 35a686d..a6b4e93 100644 --- a/id/md5.h +++ b/include/id/md5.h @@ -1,7 +1,7 @@ #ifndef md5_h #define md5_h -#include "../type/type.h" +#include #define F(x,y,z) ((x & y) | (~x & z)) #define G(x,y,z) ((x & z) | (y & ~z)) @@ -32,6 +32,15 @@ a = ROTATE_LEFT(a, s); \ a += b; \ } +/* + *MD5的管理及操作的结构 + */ +typedef struct md5_ctx{ + unsigned int count[2]; + unsigned int state[4]; + unsigned char buffer[64]; +}MD5_CTX; + void MD5Init(MD5_CTX *context); void MD5Update(MD5_CTX *context, unsigned char *input, unsigned long inputlen); diff --git a/include/list/list.h b/include/list/list.h new file mode 100644 index 0000000..534f0c5 --- /dev/null +++ b/include/list/list.h @@ -0,0 +1,201 @@ +#ifndef list_h +#define list_h + +#include + + +/************************************************ + *链表的初始化相关函数 + ************************************************/ + +/* + *初始化链表,并返回指向新链表的指针,参数if_sid指示是否为新链表分配ID号 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern List *initList(_Bool if_sid); + +/* + *初始化节点,并返回指向新链表的指针,参数if_sid指示是否为新节点分配ID号 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *initNode(_Bool if_sid); + +/*库中内部调用函数,旨在为新节点的储存值获取内存,并将相应的储存值储存在获取到的内存中,并指明储存值的类型.*/ +extern int initMallocValueForNode(Node *,unsigned int,const void *); + + + + +/************************************************* + *节点的插入: 节点的插入操作相关函数 + *************************************************/ + +/* + *在链表的头部插入一个节点* + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertInHead(List *p_list, Node *p_node); + +/* + *在链表的尾部插入一个节点 + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertInTail(List *p_list, Node *p_node); + +/* + *在一个节点的后面插入一个节点 + *参数说明: t_node为指向目标节点的指针;p_node为指向新节点的指针; + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertAfterNode(List *p_list, Node *t_node, Node *p_node); + +/* + *在一个节点的前面插入一个节点 + *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int insertBeforeNode(List *p_list, Node*t_node, Node *p_node); + + + + +/*********************************************** + 节点的替换与调换: 节点的替换与调换相关的函数 + ***********************************************/ + +/* + *用一个新节点,替换掉链表中已经存在的节点 + *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; + */ +extern int replaceNode(List *p_list, Node *t_node, Node *p_node); + +/* + *交换两个已经在链表中的节点的位置 + *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; + */ + +extern int exchangeNode(List *p_list, Node *f_node, Node *s_node); + + + + +/*********************************************** + *节点的删除: 节点移除相关函数 + ***********************************************/ + +#ifdef id_enable +/* + *通过ID查找链表中的特定节点并从链表中移除相关节点,但并不释放节点内存. + *若成功函数返回0,若失败函数返回-1.*/ +extern int removeById(List *p_list, SID *s_id); +#endif + +/* + *通过指向节点的指针直接从链表中移除相关节点,但不释放节点内存 + *若成功函数返回0,若失败函数返回-1.*/ +extern int removeByNode(List *p_list, Node *p_node); + +/* + *从链表头部移除第一个节点,不释放节点内存,返回节点指向该节点的指针,方便后续操作 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *popFromHead(List *p_list); + +/* + *从链表尾部移除最后一个节点,不释放节点内存,返回节点指向该节点的指针,方便后续操作 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *popFromTail(List *p_list); + + + + +/*********************************************** + *链表查找:查找链表中的指定节点有关的函数 + **********************************************/ + +#ifdef id_enable +/* + *通过ID查找链表中相关的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByIdForNode(List *p_list, SID * s_id); +#endif + +/* + *通过节点中的值查找相关单个节点 + *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByValue(List *p_list, unsigned int type, const void *value); + +//void *findByIdForCustom(List *p_list, SID *s_id, int func(SID *)); + +/* + *通过节点中的值查找相关多个节点. + *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. + *返回: 如果成功返回一个链表,储存所有满足该值的节点的指针.如果失败则返回NULL.*/ +extern List *mply_findByValue(List *p_list, unsigned int type, const void *value); + + + + +/*********************************************** + *链表的排序: 使用快速排序算法,按照指定规则排序链表 + **********************************************/ + +/* + *自定义排序链表. + *参数: func是一个函数指针, 指向的函数接受两个指向链表中节点的指针,并对他们进行比较 + 如果前一的相关值个大于后一个得相关值则返会大于0的数, 反之则返回小于0的数. + *返回: 如果成功返回0,如果失败则返回-1.*/ +extern int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)); + + + + +/*********************************************** + *链表或节点的释放: 释放链表或节点所占内存的相关函数 + **********************************************/ + +/* + *释放链表所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseList(List *p_list); + +/* + *自定义释放链表所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用,用于释放用户自定义的结构体的所占用内存. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseListForCustom(List *p_list, int (*func)(void *)); + +/* + *释放链表所占的内存,但不释放链表中的节点所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseListForSingle(List *p_list); + +/* + *释放相关节点所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseNode(Node *p_node); + +/* + *自定义释放节点所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, + * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. + * 回调函数返回0代表释放成功,返回-1代表释放失败. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseNodeForCustom(Node *p_node, int (*func)(void *)); + +/* + *释放节点所占的内存空间,不释放节点所储存的值所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int releaseOnlyNode(Node *p_node); + + +extern int isListEmpty(List *p_list); + + + +/*********************************************** + *相关的全局变量 + ***********************************************/ + +static int if_safeModeForNode; +static List *node_list; +static List *list_list; + + + + +#endif diff --git a/list/list_expand.h b/include/list/list_expand.h similarity index 59% rename from list/list_expand.h rename to include/list/list_expand.h index 9703f1c..58926e5 100644 --- a/list/list_expand.h +++ b/include/list/list_expand.h @@ -1,89 +1,7 @@ -#ifndef LIST_EXPAND_H -#define LIST_EXPAND_H - -#include "list.h" - - - - -/************************************************ - *回调函数的便捷操作相关宏 - ************************************************/ - -/**** - *母函数相关 - */ - -/* - *若需要母函数需要向毁掉函数传递相关参数则使用该宏 - *参数: argc指示传递参数的类型格式;args为需要返回的参数.*/ -#define __SEND_ARG(argc, args...) newReturn(0, -1, argc , args) - -/* - *若快速声明回调函数则使用该宏 - *参数: name为回调函数名.*/ -#define __CALLBACK_STATE(name) static List *_do##name(unsigned int, void *, List *) - -/* - *若快速定义回调函数则使用该宏 - *参数: name为回调函数名.*/ -#define __CALLBACK_DEFINE(name) static List *_do##name(unsigned int type, void *value, List *expand_resources) - -/* - *若传递回调函数指针则使用该宏 - *参数: name为回调函数名.*/ -#define __CALLBACK_CALL(name) _do##name - -/* - *若母函数获取回调函数返回的指针则使用该宏 - *参数: x为该值的顺序号, type为获取的指针值的类型.*/ -#define __RTN_ARGS_P(list,x,type) (type *) lidxp(list, x); - -/* - *若母函数获取回调函数返回的值则使用该宏 - *参数: x为该值的顺序号, type为获取的值的类型.*/ -#define __RTN_ARGS(list,x,type) *((type *) lidxp(list, x)); - -/**** - *回调函数相关 - */ - -/* - *若回调函数获取遍历链表中的当前节点的值则使用该宏 - *参数: c_type为获取值的类型.*/ -#define __VALUE(c_type) (c_type)value - -/* - *若回调函数获取母函数传递的参数则使用该宏 - *参数: x为该值的顺序号, type为获取值的类型.*/ -#define __ARGS(x, type) *((type *) lidxp(expand_resources, x)); - -/* - *若回调函数获取母函数传递的指针参数则使用该宏 - *参数: x为该值的顺序号, type为获取的指针值的类型.*/ -#define __ARGS_P(x, type) (type *) lidxp(expand_resources, x); - -/* - *若回调函数获取遍历链表的长度则使用该宏 - */ -#define __LIST_LEN getInfoForListThrough(expand_resources,0) - -/* - *若回调函数获取遍历链表中当前节点的序号则使用该宏 - */ -#define __NOW_INDEX getInfoForListThrough(expand_resources,1) - -/* - *若需要终止遍历或终止遍历并向母函数返回相关参数则使用该宏 - *参数: argc指示返回参数的个数;args为需要返回的参数.*/ -#define __RETURN(argc, args...) newReturn(1, -1, argc , args) - -/* - *若继续遍历则使用该宏 - */ -#define __CRETURN__ newCReturn() - +#ifndef list_expand_h +#define list_expand_h +#include /************************************************ @@ -128,41 +46,6 @@ extern Node *nodeWithString(const char *, _Bool if_sid); extern Node *nodeWithPointer(const void *, _Bool if_sid); - - - -/************************************************ - *单向节点的快速初始化: 为新节点分配内存空间, - * 并使用输入值对其进行初始化. - ************************************************/ - -/* - *为新单向节点获取内存空间, 并使用整型值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithInt(int); - -/* - *为新单向节点获取内存空间, 并使用无符号整型值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithUInt(unsigned int); - -/* - *为新单向节点获取内存空间, 并使用浮点值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithDouble(double); - -/* - *为新单向节点获取内存空间, 并使用字符串值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithString(const char *); - -/* - *为新单向节点获取内存空间, 并使用指针值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithPointer(const void *); - - - /************************************************ *嵌套节点的快速初始化: 为嵌套节点节点分配内存空间, @@ -264,43 +147,6 @@ List *mply_findByPointerForNode(List*, void *); -/************************************************ - *链表或节点的输出: 格式化输出链表或节点的属性 - ************************************************/ - -/* - *输出链表及其中节点的相关信息 - *参数: priority为每行输出信息前的空格数除以4*/ -void printListInfo(List *p_list,int priority); - -/* - *输出节点中的相关信息 - *参数: priority为每行输出信息前的空格数乘以4*/ -void printNodeInfo(Node *p_node,int priority); - -/* - *输出链表及其中节点的相关信息 - */ -void printList(List *); - -/* - *自定义输出链表及其中节点的相关信息 - *参数: func为一个函数指针, 指向函数的职能在于输出节点中的用户自定义结构的相关信息*/ -void printListForCustom(List *p_list,void (*func)(void *value)); - -/* - *printListForCustom函数的回调函数 - */ -__CALLBACK_STATE(printListForCustom); - -/* - *输出节点中的相关信息 - */ -void printNode(Node *p_node); - - - - /************************************************ *链表的遍历: 遍历链表相关函数 @@ -345,5 +191,97 @@ unsigned long long calListMemory(List *); +/*********************************************** + *链表或节点的属性:获取或更新链表或节点属性有关的函数 + ***********************************************/ + +/* + *返回链表长度*/ +extern unsigned long long len(List *p_list); + +/* + *查询链表是否为空 + *返回: 如果链表为空返回1,如果链表不为空则返回0.*/ +extern int isListEmpty(List *p_list); + +/* + *直接获得节点中的整型值 + *返回: 返回该节点储存的整型值*/ +extern int getByIntForNode(Node *); + +/* + *直接获得节点中的无符号整型值 + *返回: 返回该节点储存的无符号整型值*/ +extern unsigned int getByUIntForNode(Node *); + +/* + *直接获得节点中的浮点值 + *返回: 返回该节点储存的浮点值*/ +extern double getByDoubleForNode(Node *); + +/* + *直接获得节点中的字符串值 + *返回: 返回该节点储存的字符串值*/ +extern char *getByStringForNode(Node *); + +/* + *直接获得节点中的指针值 + *返回: 返回该节点储存的指针值*/ +extern void *getByPointerForNode(Node *); + +/* + *直接获得节点的序号 + *返回: 返回该节点在链表中的序号*/ +extern unsigned long long getIndexForNode(List *p_list,Node *p_node); + +/* + *通过节点的序号找到节点中相关的值,并更新其中的储存的值的指针. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL*/ +extern Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long index); + + + + +/********************************************** + *链表或节点的复制: 链表与节点复制相关函数 + *********************************************/ + +/* + *节点的复制,复制将会为新节点重新分配内存,并将源节点的所有值拷贝入新节点. + *注意: 源节点与新节点ID相同. + *返回: 若成功函数返回指向新节点的指针,若失败则返回NULL*/ +extern Node *copyNode(Node *); + +/* + *链表的复制,复制将会为新链表重新分配内存,并将源链表的所有节点复制. + *注意: 源链表与新链表ID相同. + *返回: 若成功函数返回指向新链表的指针,若失败则返回NULL*/ +List *copyList(List *p_list); + + +/* + *通过序号查找相关的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByIndexForNode(List *, unsigned long long); + +/* + *通过整型值查找储存该值的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByIntForNode(List *, int); + +/* + *通过浮点值查找储存该值的单个节点 + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByDoubleForNode(List *, double); + +/* + *通过字符串中查找储存该值的单个节点. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByStringForNode(List *, char *); + +/* + *通过指针值查找储存该值的单个节点. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern Node *findByPointerForNode(List *, void *); #endif diff --git a/include/list/list_expand_1.h b/include/list/list_expand_1.h new file mode 100644 index 0000000..9a4193c --- /dev/null +++ b/include/list/list_expand_1.h @@ -0,0 +1,228 @@ +#ifndef list_expand_1_h +#define list_expand_1_h + +#include + +/************************************************ + *节点快速初始化相关宏 + ************************************************/ + +/**** + *不带ID相关 + */ + +/*直接获取一个以整型值初始化的节点不带ID的缩略*/ +#define lni(x) nodeWithInt(x,0) + +/*直接获取一个以无符号整型值初始化的不带ID节点的缩略*/ +#define lnu(x) nodeWithUInt(x,0) + +/*直接获取一个以无符号长整形值初始化的节点的缩略*/ +#define lnull(x) nodeWithULLInt(x,0) + +/*直接获取一个以浮点值初始化的不带ID节点的缩略*/ +#define lnd(x) nodeWithDouble(x,0) + +/*直接获取一个以字符串值初始化的不带ID节点的缩略*/ +#define lns(x) nodeWithString(x,0) + +/*直接获取一个以指针值初始化的不带ID节点的缩略*/ +#define lnp(x) nodeWithPointer(x,0) + +/**** + *带ID相关 + */ + +/*直接获取一个以整型值初始化的带ID节点的缩略*/ +#define lsni(x) nodeWithInt(x,1) + +/*直接获取一个以浮点值初始化的带ID节点的缩略*/ +#define lsnd(x) nodeWithDouble(x,1) + +/*直接获取一个以字符串值初始化的带ID节点的缩略*/ +#define lsns(x) nodeWithString(x,1) + +/*直接获取一个以指针值初始化的节点的缩略*/ +#define lsnp(x) nodeWithPointer(x,1) + + + + +/************************************************ + *链表快速插入相关宏 + ************************************************/ + +/**** + *尾部相关 + */ + +/*在链表尾部直接加入一个已经用整型值初始化的不带ID的节点*/ +#define lisrti(list, x) insertInTail(list, lni(x)); + +/*在链表尾部直接加入一个已经用浮点值初始化的不带ID的节点*/ +#define lisrtd(list, x) insertInTail(list, lnd(x)); + +/*在链表尾部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ +#define lisrtu(list, x) insertInTail(list, lnu(x)); + +/*在链表尾部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ +#define lisrtull(list, x) insertInTail(list, lnull(x)); + +/*在链表尾部直接加入一个已经用指针值初始化的不带ID的节点*/ +#define lisrtp(list, x) insertInTail(list, lnp(x)); + +/*在链表尾部直接加入一个已经用字符串值初始化的不带ID的节点*/ +#define lisrts(list, x) insertInTail(list, lns(x)); + +/**** + *头部相关 + */ + +/*在链表头部直接加入一个已经用整型值初始化的不带ID的节点*/ +#define lisrhi(list, x) insertInHead(list, lni(x)); + +/*在链表头部直接加入一个已经用浮点值初始化的不带ID的节点*/ +#define lisrhd(list, x) insertInHead(list, lnd(x)); + +/*在链表头部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ +#define lisrhu(list, x) insertInHead(list, lnu(x)); + +/*在链表头部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ +#define lisrhull(list, x) insertInHead(list, lnull(x)); + +/*在链表头部直接加入一个已经用指针值初始化的不带ID的节点*/ +#define lisrhp(list, x) insertInHead(list, lnp(x)); + +/*在链表头部直接加入一个已经用字符串值初始化的不带ID的节点*/ +#define lisrhs(list, x) insertInHead(list, lns(x)); + + + + +/************************************************ + *节点快速获得储存值相关宏 + ************************************************/ + +/*快速获得指针类型的节点所储存的值*/ +#define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x)) + +/*快速获得整型类型的节点所储存的值*/ +#define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x)) + +/*快速获得浮点类型的节点所储存的值*/ +#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x)) + +/*快速获得字符串类型的节点所储存的值*/ +#define lidxs(list, x) getByStringForNode(findByIndexForNode(list, x)) + +/*快速获得无符号长整型类型的节点所储存的值*/ +#define lupdull(list,x,value) updateValueWithULLIntForNode(findByIndexForNode(list, x),value) + + + + +/************************************************ + *其他快速操作相关宏 + ************************************************/ + +/*通过节点的序号直接得到它的值*/ +#define lidxvle(list,x) (findByIndexForNode(list, x)->value) + +/*通过节点序号直接移除节点*/ +#define lrmvidx(list,x) removeByNode(list, findByIndexForNode(list, x) + +/*从列表头移除节点的缩略*/ +#define lpoph(list) popFromHead(list) + +/*从列表尾移除节点的缩略*/ +#define lpopt(list) popFromTail(list) + +/*通过节点的ID直接获得节点的值*/ +#define lfndsid(list,sid) (findByIdForNode(list,sid)->value) + +/*创建一个不带ID的链表的缩略*/ +#define lstns() initList(0); + +/*创建一个带有ID的链表缩略*/ +#define lstn() initList(1); + +#endif /* list_expand_1_h */ + + + +/************************************************ + *回调函数的便捷操作相关宏 + ************************************************/ + +/**** + *母函数相关 + */ + +/* + *若需要母函数需要向毁掉函数传递相关参数则使用该宏 + *参数: argc指示传递参数的类型格式;args为需要返回的参数.*/ +#define __SEND_ARG(argc, args...) newReturn(0, -1, argc , args) + +/* + *若快速声明回调函数则使用该宏 + *参数: name为回调函数名.*/ +#define __CALLBACK_STATE(name) static List *_do##name(unsigned int, void *, List *) + +/* + *若快速定义回调函数则使用该宏 + *参数: name为回调函数名.*/ +#define __CALLBACK_DEFINE(name) static List *_do##name(unsigned int type, void *value, List *expand_resources) + +/* + *若传递回调函数指针则使用该宏 + *参数: name为回调函数名.*/ +#define __CALLBACK_CALL(name) _do##name + +/* + *若母函数获取回调函数返回的指针则使用该宏 + *参数: x为该值的顺序号, type为获取的指针值的类型.*/ +#define __RTN_ARGS_P(list,x,type) (type *) lidxp(list, x); + +/* + *若母函数获取回调函数返回的值则使用该宏 + *参数: x为该值的顺序号, type为获取的值的类型.*/ +#define __RTN_ARGS(list,x,type) *((type *) lidxp(list, x)); + +/**** + *回调函数相关 + */ + +/* + *若回调函数获取遍历链表中的当前节点的值则使用该宏 + *参数: c_type为获取值的类型.*/ +#define __VALUE(c_type) (c_type)value + +/* + *若回调函数获取母函数传递的参数则使用该宏 + *参数: x为该值的顺序号, type为获取值的类型.*/ +#define __ARGS(x, type) *((type *) lidxp(expand_resources, x)); + +/* + *若回调函数获取母函数传递的指针参数则使用该宏 + *参数: x为该值的顺序号, type为获取的指针值的类型.*/ +#define __ARGS_P(x, type) (type *) lidxp(expand_resources, x); + +/* + *若回调函数获取遍历链表的长度则使用该宏 + */ +#define __LIST_LEN getInfoForListThrough(expand_resources,0) + +/* + *若回调函数获取遍历链表中当前节点的序号则使用该宏 + */ +#define __NOW_INDEX getInfoForListThrough(expand_resources,1) + +/* + *若需要终止遍历或终止遍历并向母函数返回相关参数则使用该宏 + *参数: argc指示返回参数的个数;args为需要返回的参数.*/ +#define __RETURN(argc, args...) newReturn(1, -1, argc , args) + +/* + *若继续遍历则使用该宏 + */ +#define __CRETURN__ newCReturn() diff --git a/include/list/list_print.h b/include/list/list_print.h new file mode 100644 index 0000000..f23adbc --- /dev/null +++ b/include/list/list_print.h @@ -0,0 +1,42 @@ +#ifndef list_print_h +#define list_print_h + +#include +#include + +/************************************************ + *链表或节点的输出: 格式化输出链表或节点的属性 + ************************************************/ + +/* + *输出链表及其中节点的相关信息 + *参数: priority为每行输出信息前的空格数除以4*/ +void printListInfo(List *p_list,int priority); + +/* + *输出节点中的相关信息 + *参数: priority为每行输出信息前的空格数乘以4*/ +void printNodeInfo(Node *p_node,int priority); + +/* + *输出链表及其中节点的相关信息 + */ +void printList(List *); + +/* + *自定义输出链表及其中节点的相关信息 + *参数: func为一个函数指针, 指向函数的职能在于输出节点中的用户自定义结构的相关信息*/ +void printListForCustom(List *p_list,void (*func)(void *value)); + +/* + *printListForCustom函数的回调函数 + */ +__CALLBACK_STATE(printListForCustom); + +/* + *输出节点中的相关信息 + */ +void printNode(Node *p_node); + + +#endif /* list_print_h */ diff --git a/include/list/list_quick.h b/include/list/list_quick.h new file mode 100644 index 0000000..02a1206 --- /dev/null +++ b/include/list/list_quick.h @@ -0,0 +1,65 @@ +#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_simple.h b/include/list/list_simple.h new file mode 100644 index 0000000..37f250c --- /dev/null +++ b/include/list/list_simple.h @@ -0,0 +1,79 @@ +#ifndef list_simple_h +#define list_simple_h + +#include + + +/************************************************ + *单向节点的快速初始化: 为新节点分配内存空间, + * 并使用输入值对其进行初始化. + ************************************************/ + +/* + *为新单向节点获取内存空间, 并使用整型值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithInt(int); + +/* + *为新单向节点获取内存空间, 并使用无符号整型值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithUInt(unsigned int); + +/* + *为新单向节点获取内存空间, 并使用浮点值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithDouble(double); + +/* + *为新单向节点获取内存空间, 并使用字符串值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithString(const char *); + +/* + *为新单向节点获取内存空间, 并使用指针值初始化新单向节点 + *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ +extern s_Node *s_nodeWithPointer(const void *); + + +/* + *初始化单向链表节点,该种类节点可以与普通储存在List结构中. + *单向链表的引入主要在于对于简单问题提供更小开销的解决方案.但相应的操作函数较少,不如一般链表方便. + *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +extern s_Node *s_initNode(void); + +/*在单项链表的头部插入一个节点 + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int s_insertInHead(List *p_list, s_Node *s_p_node); + +/* + *在单项链表的尾部插入一个节点 + *返回: 若成功函数返回0,若失败函数返回-1.*/ +extern int s_insertInTail(List *p_list, s_Node *s_p_node); + +/* + *释放单向节点所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseNode(s_Node *s_p_node); + +/* + *释放单向链表所占的内存空间 + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseList(List *p_list); + +/* + *自定义释放单向链表所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, + * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. + * 回调函数返回0代表释放成功,返回-1代表释放失败. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseListForCustom(List *p_list, int (*func)(void *)); + +/* + *自定义释放单向节点所占的内存空间 + *参数: func是一个函数指针,它指向的函数现在每次释放单项节点时调用, + * 接收储存在单项节点中的值得指针,释放用户自定义的结构体的所占用内存. + * 回调函数返回0代表释放成功,返回-1代表释放失败. + *返回: 如果成功返回0, 失败则返回-1.*/ +extern int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)); + +#endif /* list_simple_h */ diff --git a/include/list/list_type.h b/include/list/list_type.h new file mode 100644 index 0000000..94a9881 --- /dev/null +++ b/include/list/list_type.h @@ -0,0 +1,50 @@ +#ifndef list_type_h +#define list_type_h + +#ifdef id_enable +#include +#endif + +/* + *节点的管理及操作的结构 + */ +typedef struct Node{ + unsigned long long f_number;//长链表模式下,分派的数组节点编号 + unsigned int type;//类型 + void *value;//值指针 + struct Node *next;//指向下一个节点 + struct Node *last;//指向上一个节点 +#ifdef id_enable + SID *s_id; +#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 +#ifdef id_enable + SID *s_id; +#endif +} List; + +#endif /* list_type_h */ diff --git a/include/list/safe_mode.h b/include/list/safe_mode.h new file mode 100644 index 0000000..d74cb27 --- /dev/null +++ b/include/list/safe_mode.h @@ -0,0 +1,17 @@ +#ifndef safe_mode_h +#define safe_mode_h + +#include + +/********************************************************************************************************* + *安全模式开启函数:在开启安全模式后,记录代码段区间所有用户已经分配过内存的链表和节点.在结束时,释放记录在案的还未释放的链表和节点. + *注意:在开启后,只有使用库提供的初始化函数的时候才有效.安全模式打开后,只有调用安全模式结束函数后,才可以重新打开. + *运用:可以在逻辑较为复杂的代码段使用,预防内存泄漏的情况发生.可以免去繁琐的内存泄漏检查过程. + *返回: 若成功函数返回0,若失败函数返回-1. + ********************************************************************************************************/ +extern int safeModeForNode(int ifon); + +/*安全模式结束时调用,调用后将会释放所有在安全模式区间内用户已经分配过的链表和节点,安全模式将会关闭.*/ +extern int releaseAllForNode(void); + +#endif /* safe_mode_h */ diff --git a/include/stack/stack.h b/include/stack/stack.h new file mode 100644 index 0000000..2274b40 --- /dev/null +++ b/include/stack/stack.h @@ -0,0 +1,19 @@ +#ifndef stack_h +#define stack_h + +#include + +extern Stack *initStack(void); +extern SNode *initSNode(void); + +extern int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value); + +extern SNode *popStack(Stack *p_stack); + +extern int pushStack(Stack *p_stack, SNode *p_snode); + +extern int releaseStack(Stack *p_stack); + +extern int releaseSNode(SNode *p_snode); + +#endif /* stack_h */ diff --git a/stack/stack_expand.h b/include/stack/stack_expand.h similarity index 94% rename from stack/stack_expand.h rename to include/stack/stack_expand.h index 95978c1..e16279c 100644 --- a/stack/stack_expand.h +++ b/include/stack/stack_expand.h @@ -1,8 +1,6 @@ #ifndef STACK_EXPAND_H #define STACK_EXPAND_H -#include "stack.h" - SNode *snodeWithInt(int); SNode *snodeWithDouble(double); SNode *snodeWithString(char *); diff --git a/include/stack/stack_type.h b/include/stack/stack_type.h new file mode 100644 index 0000000..05f43f8 --- /dev/null +++ b/include/stack/stack_type.h @@ -0,0 +1,31 @@ +#ifndef stack_type_h +#define stack_type_h + +#ifdef id_enable +#include +#endif + +/* + *栈节点的管理及操作的结构 + */ +typedef struct stack_node{ + unsigned int type;//栈节点的类型 + void *value;//值指针 + struct stack_node *next;//下一个栈节点 +#ifdef id_enable + SID *s_id;//栈节点的ID +#endif +} SNode; + +/* + *栈的管理及操作的结构 + */ +typedef struct stack{ + unsigned long long length;//栈的长度 + SNode *top;//指向栈顶的栈节点 +#ifdef id_enable + SID *s_id;//栈的ID +#endif +} Stack; + +#endif /* stack_type_h */ diff --git a/tree/tree.h b/include/tree/tree.h similarity index 69% rename from tree/tree.h rename to include/tree/tree.h index d4b8a3d..d7807a1 100644 --- a/tree/tree.h +++ b/include/tree/tree.h @@ -1,8 +1,39 @@ #ifndef TREE_H #define TREE_H -#include -#include "../list/list_expand.h" +#include + +/* + *超级树节点的管理及操作的结构 + */ +typedef struct tree_node +{ + SID *s_id;//超级树节点的ID + List *home;//超级树节点的子节点列表 + struct tree_node *father;//超级树节点的父节点 + Node *room;//超级树节点的父节点的子节点列表 + unsigned long long child_num;//超级树节点的子节点数量 + unsigned int type;//超级树节点的类型 + void *value;//值指针 +}TNode; + +/* + *二叉树节点的管理及操作的结构 + */ +typedef struct simple_tree_node{ + void *value;//值指针 + struct simple_tree_node *childs[2];//子节点 +}s_TNode; + +/* + *树的管理及操作的结构 + */ +typedef struct tree +{ + SID *s_id;//超级树的SID + TNode *root;//超级树根节点 + s_TNode *s_root;//二叉树的根节点 +}Tree; int safeModeForTree(int ifon); int releaseAllForTree(void); diff --git a/include/type.h b/include/type.h new file mode 100644 index 0000000..55c48eb --- /dev/null +++ b/include/type.h @@ -0,0 +1,91 @@ +#ifndef type_h +#define type_h + +#define list_quick_enable +#define id_enable + +#include +#include +#include +#include +#include +#include +#include + +/* +#include +#include +#include +#include +*/ + + + + +/************************************************ + *库相关类型的编号 + ************************************************/ + +#define VOID 0 +#define INT 1 +#define DOUBLE 2 +#define STRING 3 +#define POINTER 4 +#define LIST 5 +#define STACK 6 +#define TREE 7 +#define LIST_NODE 8 +#define TREE_NODE 9 +#define STACK_NODE 10 +#define T_SID 11 +#define UINT 12 +#define STANDARD_DATA 13 +#define DATA_FILE 14 +#define MESSAGE 15 +#define HOLE 16 +#define ULLINT 17 + + + + + +/************************************************ + *库相关参数的定义 + ************************************************/ + +#define DEEPC 1 +#define DEEPB 2 +#define DEEPA 3 +#define TYPE_LEN 5 +#define DEEPC_LEN 4 +#define DEEPB_LEN 8 +#define DEEPA_LEN 32 +#define DATA_BIT 5 +#define DEEP_LEN 25 +#define DEEPER_LEN 65 +#define DEEPEST_LEN 225 +#define SID_LEN 33 +#define FILE_TSET_LEN 18 +#define HEAD_TEST_LEN 9 +#define INFO_TEST_LEN 8 +#define ENABLE_LIST_QUICK 65535 +#define FN_NODE_SPARE 500 +#define INDEX_CHANGE_MAX 500 +#define INDEX_DISTANCE_MAX 120 +#define STD_TEXT_LEN 4 +#define HIGH 0x3 +#define STANDARD 0x2 +#define LOW 0x1 + + + + + +/************************************************ + *库相关操作宏的定义 + ************************************************/ + +#define ABS(x) ((x>0)?(x):(-x)) + + +#endif /* type_h */ diff --git a/list/list.c b/list/list.c deleted file mode 100644 index d627027..0000000 --- a/list/list.c +++ /dev/null @@ -1,985 +0,0 @@ -#include "list.h" - -static int if_safeModeForNode = 0; -static List *node_list = NULL; -static List *list_list = NULL; - -int safeModeForNode(int ifon) { - if (ifon == 1) { - if (node_list == NULL && list_list == NULL) { - node_list = (List *)malloc(sizeof(List)); - if(node_list == NULL){ - showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in getting the memory of node_list."))); - return -1; - } - list_list = (List *)malloc(sizeof(List)); - if(list_list == NULL){ - showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in getting the memory of list_list."))); - return -1; - } - list_list->head = NULL; - list_list->length = 0; - list_list->tail = NULL; - - node_list->head = NULL; - node_list->length = 0; - node_list->tail = NULL; - - if_safeModeForNode = 1; - } - else { - return -1; - } - } - - return ifon; -} - -int releaseSingleListForsafeModeForNode(List *p_list) { - Node *p_node = p_list->head; - List *plv_node = NULL; - while (p_node != NULL) { - plv_node = (List *)p_node->value; - freeS_id(plv_node->s_id); - plv_node->head = NULL; - plv_node->length = 0; - plv_node->tail = NULL; - free(plv_node); - p_node = p_node->next; - } - p_list->head = NULL; - p_list->length = 0; - p_list->tail = NULL; - freeS_id(p_list->s_id); - free(p_list); - return 0; -} - -int releaseSingleNodeForsafeModeForNode(List *p_list) { - Node *p_node = p_list->head; - Node *pnv_node = NULL; - while (p_node != NULL) { - pnv_node = (Node *)p_node->value; - freeS_id(pnv_node->s_id); - pnv_node->last = NULL; - pnv_node->next = NULL; - pnv_node->type = VOID; - pnv_node->value = NULL; - free(pnv_node); - p_node = p_node->next; - } - free(p_list->s_id); - p_list->head = NULL; - p_list->length = 0; - p_list->tail = NULL; - free(p_list); - return 0; -} - -int releaseAllForNode(void) { - if (if_safeModeForNode == 1) { - if_safeModeForNode = 0; - releaseSingleNodeForsafeModeForNode(node_list); - releaseSingleListForsafeModeForNode(list_list); - } - return 0; -} - -Node *initNode(_Bool if_sid) { - Node *p_node = (Node *)malloc(sizeof(Node)); - if(p_node == NULL){ - showError(pushError(LIST_NODE, STANDARD, initInfo("initNode()", "Error in getting the memory of node."))); - return NULL; - } - Node *prec_node = NULL; - if (if_sid)p_node->s_id = getS_id(LIST_NODE, 1); - else p_node->s_id = NULL; - p_node->next = NULL; - p_node->last = NULL; - p_node->type = VOID; - p_node->f_number = 0; - if (if_safeModeForNode) { - if_safeModeForNode = 0; - prec_node = initNode(0); - if_safeModeForNode = 1; - initMallocValueForNode(prec_node, POINTER, (void *)p_node); - insertInTail(node_list, prec_node); - } - return p_node; -} - -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; -} - -List *initList(_Bool if_sid) { - Node *p_node = NULL; - List *p_list = (List *)malloc(sizeof(List)); - if(p_list == NULL){ - showError(pushError(LIST_NODE, STANDARD, initInfo("initList()", "Error in getting the memory of list."))); - return NULL; - } - if(if_sid) p_list->s_id = getS_id(LIST, 1); - else p_list->s_id = NULL; - p_list->head = NULL; - p_list->tail = NULL; - p_list->length = 0; - p_list->p_lq = NULL; - p_list->s_head = NULL; - if (if_safeModeForNode) { - if_safeModeForNode = 0; - p_node = initNode(0); - if_safeModeForNode = 1; - initMallocValueForNode(p_node, POINTER, (void *)p_list); - insertInTail(list_list, p_node); - } - return p_list; -} - -inline int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { - p_node->type = type; - p_node->value = (void *)p_value; - return 0; -} - -int insertInHead(List *p_list, Node *p_node) { - 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); - } - 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; -} - -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; -} - -int insertInTail(List *p_list, Node *p_node) { - if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1; - 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; - } - - 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++; - } - - p_list->length += 1; - 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; -} - -int releaseNode(Node *p_node) { - if (if_safeModeForNode == 1) { - removeByNode(node_list, p_node); - } - if (p_node->value != NULL) { - if (p_node->type != POINTER && p_node->type != HOLE) { - if (p_node->type == LIST) { - releaseList((List *)p_node->value); - } - else { - free(p_node->value); - } - } - p_node->value = NULL; - } - p_node->f_number = 0; - p_node->last = NULL; - p_node->next = NULL; - p_node->type = VOID; - p_node->value = NULL; - if (p_node->s_id != NULL) freeS_id(p_node->s_id); - free(p_node); - return 0; -} - -inline int s_releaseNode(s_Node *s_p_node){ - free(s_p_node); - return 0; -} - - -int releaseList(List *p_list) { - Node *p_node, *pl_node; - p_node = p_list->head; - if (if_safeModeForNode == 1) { - Node *tar_list = findByValue(list_list, POINTER, (void *)p_list);//turn pointer in to int to compare. - removeByNode(list_list, tar_list); - } - while (p_node != NULL) { - pl_node = p_node; - p_node = p_node->next; - pl_node->next = NULL; - pl_node->last = NULL; - releaseNode(pl_node); - } - p_list->head = NULL; - p_list->tail = NULL; - p_list->length = 0; - 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); - free(p_list); - return 0; -} - -int releaseListForSingle(List *p_list) { - releaseList(p_list); - return 0; -} - -unsigned long long len(List *p_list) { - return p_list->length; -} - -int removeById(List *p_list, SID *s_id) { - Node *tmp = p_list->head; - if (isListEmpty(p_list)) - return -1; - do { - if (simFitS_id(tmp->s_id, s_id)) { - if (tmp != p_list->head) { - tmp->last->next = tmp->next; - } - else { - p_list->head = tmp->next; - } - if (tmp != p_list->tail) { - tmp->next->last = tmp->last; - } - else { - p_list->tail = tmp->last; - } - - p_list->length -= 1; - return 1;//found - } - else { - tmp = tmp->next; - } - } while (tmp != NULL); - - return 0;//not find -} - -int removeByNode(List *p_list, Node *p_node) { - if (isListEmpty(p_list)) - return -1; - if(p_node == p_list->head){ - popFromHead(p_list); - return 0; - } - else if(p_node == p_list->tail){ - 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{ - 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); - } - p_list->length -= 1; - } - return 0;//not find -} - -Node *popFromHead(List *p_list) { - if (isListEmpty(p_list)) - return NULL; - Node *p_node = p_list->head; - 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; - } - } - } - else{ - //Node *tmp = p_list->head; - p_list->head->next->last = NULL; - p_list->head = p_list->head->next; - //releaseNode(tmp); not necessary - if (isListEmpty(p_list)) { - p_list->head = NULL; - p_list->tail = NULL; - } - p_list->length -= 1; - } - return p_node; -} - -Node *popFromTail(List *p_list) { - Node *p_node = p_list->tail; - if (isListEmpty(p_list)) - return NULL; - else { - 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; - } - } - } - //Node *tmp = p_list->tail; - p_list->tail->last->next = NULL; - p_list->tail = p_list->tail->last; - //releaseNode(tmp); not necessary - } - - if (isListEmpty(p_list)) { - p_list->head = NULL; - p_list->tail = NULL; - } - p_list->length -= 1; - return p_node; -} - -Node *findByIdForNode(List *p_list, SID * s_id) { - Node *ph_node = p_list->head; - Node *pt_node = p_list->tail; - int direction = 0; - while (ph_node != pt_node) { - if (direction == 0) { - if (simFitS_id(ph_node->s_id, s_id)) { - return ph_node; - } - else { - ph_node = ph_node->next; - } - direction = 1; - } - else { - if (simFitS_id(pt_node->s_id, s_id)) { - return pt_node; - } - else { - pt_node = pt_node->last; - } - } - } - return NULL; -} - -Node *findByValue(List *p_list, unsigned int type, const void *value) { - Node *p_node = p_list->head; - while (p_node != NULL) { - if (p_node->type != type) { - p_node = p_node->next; - continue; - } - if (type == INT) { - if (*((int *)p_node->value) == *((int *)value)) { - return copyNode(p_node); - } - } - else if (type == DOUBLE) { - if (*((double *)p_node->value) == *((double *)value)) { - return copyNode(p_node); - } - } - else if (type == STRING) { - if (!strcmp((char *)p_node->value, (char *)value)) - { - return copyNode(p_node); - } - } - else if (type == POINTER) { - if (p_node->value == value) { - return copyNode(p_node); - } - } - - p_node = p_node->next; - - } - return NULL; -} - -List *mply_findByValue(List *p_list, unsigned int type, const void *value) { - List *f_list = initList(0); - Node *p_node = p_list->head; - while (p_node != NULL) { - if (p_node->type != type) { - p_node = p_node->next; - continue; - } - if (type == INT) { - if (*((int *)p_node->value) == *((int *)value)) { - Node *f_node = copyNode(p_node); - insertInTail(f_list, f_node); - } - } - else if (type == DOUBLE) { - if (*((double *)p_node->value) == *((double *)value)) { - Node *f_node = copyNode(p_node); - insertInTail(f_list, f_node); - } - } - else if (type == STRING) { - if (!strcmp((char *)p_node->value, (char *)value)) - { - Node *f_node = copyNode(p_node); - insertInTail(f_list, f_node); - } - } - else if (type == POINTER) { - if (p_node->value == value) { - Node *f_node = copyNode(p_node); - insertInTail(f_list, f_node); - } - } - - p_node = p_node->next; - - } - return f_list; -} - -int isListEmpty(List *p_list) { - if (p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty. - return 1; // But we should ensure that both of them are NULL when we - return 0; // want to make a list empty. -} - -Node *copyNode(Node *p_node) { - Node *t_node = NULL; - if (p_node->s_id == NULL) t_node = initNode(0); - else t_node = initNode(p_node->s_id->deep); - t_node->s_id = copyS_id(p_node->s_id); - t_node->last = p_node->last; - t_node->next = p_node->next; - t_node->type = p_node->type; - t_node->value = p_node->value; - t_node->f_number = p_node->f_number; - return t_node; -} - -List *copyList(List *p_list) { - Node *p_node; - Node *t_node; - List *t_list = NULL; - if (p_list->s_id == NULL) t_list = initList(0); - else t_list = initList(p_list->s_id->deep); - t_list->head = p_list->head; - t_list->tail = p_list->tail; - t_list->s_id = p_list->s_id; - t_list->s_head = p_list->s_head; - t_list->length = p_list->length; - t_list->s_tail = p_list->s_tail; - if(p_list->head != NULL && p_list->tail != NULL){ - p_node = p_list->head; - while (p_node != NULL) { - t_node = copyNode(p_node); - insertInTail(t_list, t_node); - p_node = p_node->next; - } - } - return t_list; -} - -int releaseOnlyNode(Node *p_node) { - if (p_node->s_id != NULL) freeS_id(p_node->s_id); - p_node->last = NULL; - p_node->next = NULL; - p_node->type = VOID; - p_node->value = NULL; - free(p_node); - return 0; -} - -int releaseNodeForCustom(Node *p_node, int (*func)(void *)){ - if (if_safeModeForNode) { - removeByNode(node_list, p_node); - } - if (p_node->value != NULL) { - if (func(p_node->value)) - showError(pushError(LIST_NODE, STANDARD, initInfo("releaseNodeForCustom()", "Error in using custom freeing value function."))); - p_node->value = NULL; - } - p_node->last = NULL; - p_node->next = NULL; - p_node->type = VOID; - p_node->value = NULL; - if (p_node->s_id != NULL) freeS_id(p_node->s_id); - free(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 releaseListForCustom(List *p_list, int (*func)(void *)){ - Node *p_node, *pl_node; - p_node = p_list->head; - if (if_safeModeForNode == 1) { - Node *tar_list = findByValue(list_list, POINTER, (void *)p_list); - removeByNode(list_list, tar_list); - } - while (p_node != NULL) { - pl_node = p_node; - p_node = p_node->next; - pl_node->next = NULL; - pl_node->last = NULL; - releaseNodeForCustom(pl_node,func); - } - p_list->head = NULL; - p_list->tail = NULL; - p_list->length = 0; - if (p_list->s_id != NULL) freeS_id(p_list->s_id); - if(p_list->p_lq != NULL) disableListQuick(p_list); - free(p_list); - 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; -} - -int pushInfo(Info *p_info, const char *head, const char *body) { - strcpy(p_info->head, head); - strcpy(p_info->body, body); - return 0; -} - -Error *pushError(unsigned int type, int pri, Info *p_info) { - Error *p_error = (Error *)malloc(sizeof(Error)); - p_error->type = type; - p_error->priority = pri; - p_error->info = *p_info; - p_error->time = time(NULL); - free(p_info); - return p_error; -} - -Notice *pushNotice(unsigned int type, Info *p_info) { - Notice *p_notice = (Notice *)malloc(sizeof(Notice)); - p_notice->type = type; - p_notice->info = *p_info; - p_notice->time = time(NULL); - free(p_info); - return p_notice; -} - -Info *initInfo(const char *head, const char *body){ - Info *p_info = (Info *)malloc(sizeof(Info)); - pushInfo(p_info, head, body); - return p_info; -} - -int showError(Error *p_error){ - printf("\n"); - for (int i = 0; i < p_error->priority; i++) { - printf("!"); - } - - printf("(Error) %s\n",asctime(localtime(&p_error->time))); - printf("%s: %s.\n",p_error->info.head,p_error->info.body); - free(p_error); - return 0; -} - -int showWarning(Notice *p_notice){ - printf("\n@"); - printf("(Warning) %s\n",asctime(localtime(&p_notice->time))); - printf("%s: %s.\n",p_notice->info.head,p_notice->info.body); - free(p_notice); - return 0; -} - -int replaceNode(List *p_list, Node *pt_node, Node *p_node){ - p_node->next = pt_node->next; - p_node->last = pt_node->last; - if (p_list->head != pt_node) pt_node->last->next = 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; - - 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; - } - } - return 0; -} - -int exchangeNode(List *p_list, Node *f_node, Node *s_node){ - Node *fl_node = f_node->last, *fn_node = f_node->next; - if(p_list->head != f_node) f_node->last->next = s_node; - else p_list->head = s_node; - if(p_list->tail != f_node) f_node->next->last = s_node; - else p_list->tail = s_node; - - if(p_list->head != s_node) s_node->last->next = f_node; - else p_list->head = f_node; - if(p_list->tail != s_node) s_node->next->last = f_node; - else p_list->tail = f_node; - f_node->next = s_node->next; - f_node->last = s_node->last; - s_node->next = fn_node; - s_node->last = fl_node; - 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; - } - return 0; -} - -int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *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 unsigned long long i = end,j = begin; - for(; i >= begin; i--){ - if(i <= j) break; - i_node = findByIndexForNode(p_list, i); - if(func(t_node, i_node) < 0){ - exchangeNode(p_list, t_node, i_node); - for(; j <= end; j++){ - if(j >= i) break; - j_node = findByIndexForNode(p_list, j); - if(func(t_node, j_node) > 0){ - exchangeNode(p_list, t_node, j_node); - break; - } - } - } - } - 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); - } - return 0; -} - -int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)){ - if(p_list->p_lq != NULL && !p_list->p_lq->if_sort) p_list->p_lq->if_sort = 1; - sortList(p_list, 0, p_list->length-1, func); - return 0; -} - -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; -} - -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); - freeS_id(c_node->s_id); - 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/list/list.h b/list/list.h deleted file mode 100644 index 61dd983..0000000 --- a/list/list.h +++ /dev/null @@ -1,553 +0,0 @@ -#ifndef LIST_H -#define LIST_H -#include "../type/type.h" -#include "../id/id.h" - -/************************************************ - *节点快速初始化相关宏 - ************************************************/ - -/**** - *不带ID相关 - */ - -/*直接获取一个以整型值初始化的节点不带ID的缩略*/ -#define lni(x) nodeWithInt(x,0) - -/*直接获取一个以无符号整型值初始化的不带ID节点的缩略*/ -#define lnu(x) nodeWithUInt(x,0) - -/*直接获取一个以无符号长整形值初始化的节点的缩略*/ -#define lnull(x) nodeWithULLInt(x,0) - -/*直接获取一个以浮点值初始化的不带ID节点的缩略*/ -#define lnd(x) nodeWithDouble(x,0) - -/*直接获取一个以字符串值初始化的不带ID节点的缩略*/ -#define lns(x) nodeWithString(x,0) - -/*直接获取一个以指针值初始化的不带ID节点的缩略*/ -#define lnp(x) nodeWithPointer(x,0) - -/**** - *带ID相关 - */ - -/*直接获取一个以整型值初始化的带ID节点的缩略*/ -#define lsni(x) nodeWithInt(x,1) - -/*直接获取一个以浮点值初始化的带ID节点的缩略*/ -#define lsnd(x) nodeWithDouble(x,1) - -/*直接获取一个以字符串值初始化的带ID节点的缩略*/ -#define lsns(x) nodeWithString(x,1) - -/*直接获取一个以指针值初始化的节点的缩略*/ -#define lsnp(x) nodeWithPointer(x,1) - - - - -/************************************************ - *链表快速插入相关宏 - ************************************************/ - -/**** - *尾部相关 - */ - -/*在链表尾部直接加入一个已经用整型值初始化的不带ID的节点*/ -#define lisrti(list, x) insertInTail(list, lni(x)); - -/*在链表尾部直接加入一个已经用浮点值初始化的不带ID的节点*/ -#define lisrtd(list, x) insertInTail(list, lnd(x)); - -/*在链表尾部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ -#define lisrtu(list, x) insertInTail(list, lnu(x)); - -/*在链表尾部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ -#define lisrtull(list, x) insertInTail(list, lnull(x)); - -/*在链表尾部直接加入一个已经用指针值初始化的不带ID的节点*/ -#define lisrtp(list, x) insertInTail(list, lnp(x)); - -/*在链表尾部直接加入一个已经用字符串值初始化的不带ID的节点*/ -#define lisrts(list, x) insertInTail(list, lns(x)); - -/**** - *头部相关 - */ - -/*在链表头部直接加入一个已经用整型值初始化的不带ID的节点*/ -#define lisrhi(list, x) insertInHead(list, lni(x)); - -/*在链表头部直接加入一个已经用浮点值初始化的不带ID的节点*/ -#define lisrhd(list, x) insertInHead(list, lnd(x)); - -/*在链表头部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ -#define lisrhu(list, x) insertInHead(list, lnu(x)); - -/*在链表头部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ -#define lisrhull(list, x) insertInHead(list, lnull(x)); - -/*在链表头部直接加入一个已经用指针值初始化的不带ID的节点*/ -#define lisrhp(list, x) insertInHead(list, lnp(x)); - -/*在链表头部直接加入一个已经用字符串值初始化的不带ID的节点*/ -#define lisrhs(list, x) insertInHead(list, lns(x)); - - - - -/************************************************ - *节点快速获得储存值相关宏 - ************************************************/ - -/*快速获得指针类型的节点所储存的值*/ -#define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x)) - -/*快速获得整型类型的节点所储存的值*/ -#define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x)) - -/*快速获得浮点类型的节点所储存的值*/ -#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x)) - -/*快速获得字符串类型的节点所储存的值*/ -#define lidxs(list, x) getByStringForNode(findByIndexForNode(list, x)) - -/*快速获得无符号长整型类型的节点所储存的值*/ -#define lupdull(list,x,value) updateValueWithULLIntForNode(findByIndexForNode(list, x),value) - - - - -/************************************************ - *其他快速操作相关宏 - ************************************************/ - -/*通过节点的序号直接得到它的值*/ -#define lidxvle(list,x) (findByIndexForNode(list, x)->value) - -/*通过节点序号直接移除节点*/ -#define lrmvidx(list,x) removeByNode(list, findByIndexForNode(list, x) - -/*从列表头移除节点的缩略*/ -#define lpoph(list) popFromHead(list) - -/*从列表尾移除节点的缩略*/ -#define lpopt(list) popFromTail(list) - -/*通过节点的ID直接获得节点的值*/ -#define lfndsid(list,sid) (findByIdForNode(list,sid)->value) - -/*创建一个不带ID的链表的缩略*/ -#define lstns() initList(0); - -/*创建一个带有ID的链表缩略*/ -#define lstn() initList(1); - -/********************************************************************************************************/ - -/********************************************************************************************************* - *安全模式开启函数:在开启安全模式后,记录代码段区间所有用户已经分配过内存的链表和节点.在结束时,释放记录在案的还未释放的链表和节点. - *注意:在开启后,只有使用库提供的初始化函数的时候才有效.安全模式打开后,只有调用安全模式结束函数后,才可以重新打开. - *运用:可以在逻辑较为复杂的代码段使用,预防内存泄漏的情况发生.可以免去繁琐的内存泄漏检查过程. - *返回: 若成功函数返回0,若失败函数返回-1. - ********************************************************************************************************/ -extern int safeModeForNode(int ifon); - -/*属于安全模式操作内部调用,释放链表而不释放其中的值.*/ -static int releaseSingleListForsafeModeForNode(List *p_list); - -/*属于安全模式操作内部调用,释放节点而不释放其中的值.*/ -static int releaseSingleNodeForsafeModeForNode(List *p_list); - -/*安全模式结束时调用,调用后将会释放所有在安全模式区间内用户已经分配过的链表和节点,安全模式将会关闭.*/ -extern int releaseAllForNode(void); - -/* - *初始化链表,并返回指向新链表的指针,参数if_sid指示是否为新链表分配ID号 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern List *initList(_Bool if_sid); - -/* - *初始化节点,并返回指向新链表的指针,参数if_sid指示是否为新节点分配ID号 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *initNode(_Bool if_sid); - - - - -/************************************************ - *链表的初始化相关函数 - ************************************************/ - -/* - *初始化单向链表节点,该种类节点可以与普通储存在List结构中. - *单向链表的引入主要在于对于简单问题提供更小开销的解决方案.但相应的操作函数较少,不如一般链表方便. - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern s_Node *s_initNode(void); - -/*库中内部调用函数,旨在为新节点的储存值获取内存,并将相应的储存值储存在获取到的内存中,并指明储存值的类型.*/ -static int initMallocValueForNode(Node *,unsigned int,const void *); - - - - -/************************************************* - *节点的插入: 节点的插入操作相关函数 - *************************************************/ - -/* - *在链表的头部插入一个节点* - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int insertInHead(List *p_list, Node *p_node); - -/* - *在链表的尾部插入一个节点 - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int insertInTail(List *p_list, Node *p_node); - -/* - *在一个节点的后面插入一个节点 - *参数说明: t_node为指向目标节点的指针;p_node为指向新节点的指针; - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int insertAfterNode(List *p_list, Node *t_node, Node *p_node); - -/* - *在一个节点的前面插入一个节点 - *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int insertBeforeNode(List *p_list, Node*t_node, Node *p_node); - -/*在单项链表的头部插入一个节点 - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int s_insertInHead(List *p_list, s_Node *s_p_node); - -/* - *在单项链表的尾部插入一个节点 - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int s_insertInTail(List *p_list, s_Node *s_p_node); - - - - -/*********************************************** - 节点的替换与调换: 节点的替换与调换相关的函数 - ***********************************************/ - -/* - *用一个新节点,替换掉链表中已经存在的节点 - *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; - */ -extern int replaceNode(List *p_list, Node *t_node, Node *p_node); - -/* - *交换两个已经在链表中的节点的位置 - *参数: t_node为指向目标节点的指针;p_node为指向新节点的指针; - */ - -extern int exchangeNode(List *p_list, Node *f_node, Node *s_node); - - - - -/********************************************** - *链表或节点的复制: 链表与节点复制相关函数 - *********************************************/ - -/* - *节点的复制,复制将会为新节点重新分配内存,并将源节点的所有值拷贝入新节点. - *注意: 源节点与新节点ID相同. - *返回: 若成功函数返回指向新节点的指针,若失败则返回NULL*/ -extern Node *copyNode(Node *); - -/* - *链表的复制,复制将会为新链表重新分配内存,并将源链表的所有节点复制. - *注意: 源链表与新链表ID相同. - *返回: 若成功函数返回指向新链表的指针,若失败则返回NULL*/ -List *copyList(List *p_list); - - - - -/*********************************************** - *节点的删除: 节点移除相关函数 - ***********************************************/ - -/* - *通过ID查找链表中的特定节点并从链表中移除相关节点,但并不释放节点内存. - *若成功函数返回0,若失败函数返回-1.*/ -extern int removeById(List *p_list, SID *s_id); - -/* - *通过指向节点的指针直接从链表中移除相关节点,但不释放节点内存 - *若成功函数返回0,若失败函数返回-1.*/ -extern int removeByNode(List *p_list, Node *p_node); - -/* - *从链表头部移除第一个节点,不释放节点内存,返回节点指向该节点的指针,方便后续操作 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *popFromHead(List *p_list); - -/* - *从链表尾部移除最后一个节点,不释放节点内存,返回节点指向该节点的指针,方便后续操作 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *popFromTail(List *p_list); - - - - -/*********************************************** - *链表或节点的属性:获取或更新链表或节点属性有关的函数 - ***********************************************/ - -/* - *返回链表长度*/ -extern unsigned long long len(List *p_list); - -/* - *查询链表是否为空 - *返回: 如果链表为空返回1,如果链表不为空则返回0.*/ -extern int isListEmpty(List *p_list); - -/* - *直接获得节点中的整型值 - *返回: 返回该节点储存的整型值*/ -extern int getByIntForNode(Node *); - -/* - *直接获得节点中的无符号整型值 - *返回: 返回该节点储存的无符号整型值*/ -extern unsigned int getByUIntForNode(Node *); - -/* - *直接获得节点中的浮点值 - *返回: 返回该节点储存的浮点值*/ -extern double getByDoubleForNode(Node *); - -/* - *直接获得节点中的字符串值 - *返回: 返回该节点储存的字符串值*/ -extern char *getByStringForNode(Node *); - -/* - *直接获得节点中的指针值 - *返回: 返回该节点储存的指针值*/ -extern void *getByPointerForNode(Node *); - -/* - *直接获得节点的序号 - *返回: 返回该节点在链表中的序号*/ -extern unsigned long long getIndexForNode(List *p_list,Node *p_node); - -/* - *通过节点的序号找到节点中相关的值,并更新其中的储存的值的指针. - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL*/ -extern Node *updateNodeByIndex(List *p_list, void *new_value, unsigned long long index); - - - - -/*********************************************** - *链表查找:查找链表中的指定节点有关的函数 - **********************************************/ - -/* - *通过ID查找链表中相关的单个节点 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByIdForNode(List *p_list, SID * s_id); - -/* - *通过节点中的值查找相关单个节点 - *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByValue(List *p_list, unsigned int type, const void *value); - -/* - *通过序号查找相关的单个节点 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByIndexForNode(List *, unsigned long long); - -/* - *通过整型值查找储存该值的单个节点 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByIntForNode(List *, int); - -/* - *通过浮点值查找储存该值的单个节点 - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByDoubleForNode(List *, double); - -/* - *通过字符串中查找储存该值的单个节点. - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByStringForNode(List *, char *); - -/* - *通过指针值查找储存该值的单个节点. - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern Node *findByPointerForNode(List *, void *); - -//void *findByIdForCustom(List *p_list, SID *s_id, int func(SID *)); - -/* - *通过节点中的值查找相关多个节点. - *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. - *返回: 如果成功返回一个链表,储存所有满足该值的节点的指针.如果失败则返回NULL.*/ -extern List *mply_findByValue(List *p_list, unsigned int type, const void *value); - - - - -/*********************************************** - *链表的排序: 使用快速排序算法,按照指定规则排序链表 - **********************************************/ - -/* - *内部函数: 通过节点中的值查找相关多个节点. - *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. - *返回: 如果成功返回0,如果失败则返回-1.*/ -static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)); - -/* - *自定义排序链表. - *参数: func是一个函数指针, 指向的函数接受两个指向链表中节点的指针,并对他们进行比较 - 如果前一的相关值个大于后一个得相关值则返会大于0的数, 反之则返回小于0的数. - *返回: 如果成功返回0,如果失败则返回-1.*/ -extern int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)); - - - - -/*********************************************** - *链表或节点的释放: 释放链表或节点所占内存的相关函数 - **********************************************/ - -/* - *释放链表所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int releaseList(List *p_list); - -/* - *释放单向链表所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseList(List *p_list); - -/* - *自定义释放链表所占的内存空间 - *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用,用于释放用户自定义的结构体的所占用内存. - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int releaseListForCustom(List *p_list, int (*func)(void *)); - -/* - *自定义释放单向链表所占的内存空间 - *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, - * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. - * 回调函数返回0代表释放成功,返回-1代表释放失败. - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseListForCustom(List *p_list, int (*func)(void *)); - -/* - *释放链表所占的内存,但不释放链表中的节点所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int releaseListForSingle(List *p_list); - -/* - *释放相关节点所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int releaseNode(Node *p_node); - -/* - *释放单向节点所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseNode(s_Node *s_p_node); - -/* - *自定义释放节点所占的内存空间 - *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, - * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. - * 回调函数返回0代表释放成功,返回-1代表释放失败. - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int releaseNodeForCustom(Node *p_node, int (*func)(void *)); - -/* - *自定义释放单向节点所占的内存空间 - *参数: func是一个函数指针,它指向的函数现在每次释放单项节点时调用, - * 接收储存在单项节点中的值得指针,释放用户自定义的结构体的所占用内存. - * 回调函数返回0代表释放成功,返回-1代表释放失败. - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)); - -/* - *释放节点所占的内存空间,不释放节点所储存的值所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int releaseOnlyNode(Node *p_node); - -/*********************************************** - *错误的提示:出现错误时,以下函数用于快捷地通报错误信息, - * 以便根据信息快速找到错误原因. - **********************************************/ - -extern int pushInfo(Info *p_info, const char *head,const char *body); - -extern Error *pushError(unsigned int type, int pri, Info *p_info); - -extern Notice *pushNotice(unsigned int type, Info *p_info); - -extern Info *initInfo(const char *head, const char *body); - -extern Error *createError(Info *info,unsigned int type,int pri); - -extern Notice *createWarning(Info *info, unsigned int type, int pri); - -extern int showError(Error *); - -extern int showWarning(Notice *); - -/*********************************************** - *长链表模式:当链表长度很长时,链表查找的代价将会很大. - * 该模式用于优化长链表的查找过程.降低时间复杂度. - ***********************************************/ -/* - *打开长链表模式 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int enableListQuick(List *p_list); - -/* - *关闭长链表模式 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int disableListQuick(List *p_list); - -static int refreshFnNode(List *p_list); - -static int indexTransfromer(List *p_list, unsigned long long m_index); - -static int indexChange(List *p_list, unsigned long long c_index, int move); - -static Node *getNodeByFnNode(List *p_list, unsigned long long index); - -static Node *findFnNode(List *p_list, Node *p_node); - -static void initIdxcList(List *p_list); - -static void digHole(List *p_list, Node *p_node); - - -//Node *getListTail(List *); - - - - -/*********************************************** - *相关的全局变量 - ***********************************************/ - -static int if_safeModeForNode; -static List *node_list; -static List *list_list; - - - - -#endif diff --git a/list/list_copy.c b/list/list_copy.c new file mode 100644 index 0000000..73edce2 --- /dev/null +++ b/list/list_copy.c @@ -0,0 +1,44 @@ +#include +#include + +Node *copyNode(Node *p_node) { + Node *t_node = NULL; +#ifdef id_enable + if (p_node->s_id == NULL) t_node = initNode(0); + else t_node = initNode(p_node->s_id->deep); + t_node->s_id = copyS_id(p_node->s_id); +#endif + t_node->last = p_node->last; + t_node->next = p_node->next; + t_node->type = p_node->type; + t_node->value = p_node->value; + t_node->f_number = p_node->f_number; + return t_node; +} + +List *copyList(List *p_list) { + Node *p_node; + Node *t_node; + List *t_list = NULL; +#ifdef id_enable + if (p_list->s_id == NULL) t_list = initList(0); + else t_list = initList(p_list->s_id->deep); +#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; + while (p_node != NULL) { + t_node = copyNode(p_node); + insertInTail(t_list, t_node); + p_node = p_node->next; + } + } + return t_list; +} diff --git a/list/list_expand.c b/list/list_expand.c deleted file mode 100644 index 72426b0..0000000 --- a/list/list_expand.c +++ /dev/null @@ -1,650 +0,0 @@ -#include "list_expand.h" - -Node *nodeWithInt(int m_int, _Bool if_sid) { - Node *p_node; - int *p_int = (int *)malloc(sizeof(int)); - if(p_int == NULL){ - showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); - return NULL; - } - *p_int = m_int; - p_node = initNode(if_sid); - initMallocValueForNode(p_node, INT, (void *)p_int); - return p_node; -} - -Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){ - Node *p_node; - unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); - if(pu_int == NULL){ - showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); - return NULL; - } - *pu_int = m_uint; - p_node = initNode(if_sid); - initMallocValueForNode(p_node, INT, (void *)pu_int); - return p_node; -} - -Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) { - Node *p_node; - unsigned long long *p_ullint = (unsigned long long *)malloc(sizeof(unsigned long long)); - if(p_ullint == NULL){ - showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); - return NULL; - } - *p_ullint = m_ullint; - p_node = initNode(if_sid); - initMallocValueForNode(p_node, ULLINT, (void *)p_ullint); - return p_node; -} - -Node *nodeWithDouble(double m_double, _Bool if_sid) { - Node *p_node; - double *p_double = (double *)malloc(sizeof(double)); - if(p_double == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of double."))); - return NULL; - } - *p_double = m_double; - p_node = initNode(if_sid); - initMallocValueForNode(p_node, DOUBLE, (void *)p_double); - return p_node; -} - -Node *nodeWithString(const char *m_string, _Bool if_sid) { - Node *p_node; - char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); - if(p_string == NULL){ - showError(pushError(STRING, STANDARD, initInfo("initWithString()", "Error in getting the memory of string."))); - return NULL; - } - strcpy(p_string, m_string); - p_node = initNode(if_sid); - initMallocValueForNode(p_node, STRING, (void *)p_string); - return p_node; -} - -Node *nodeWithPointer(const void *m_pointer, _Bool if_sid) { - Node *p_node = initNode(if_sid); - initMallocValueForNode(p_node, POINTER, m_pointer); - return p_node; -} - -Node *nodeWithComplex(void) { - Node *p_node = initNode(0); - p_node->type = LIST; - p_node->value = initList(0); - return p_node; -} - -Node *findByIndexForNode(List *p_list, unsigned long long m_index) { - if(p_list == NULL) return NULL; - 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); - } - Node *p_node = p_list->head; - unsigned long long i; - for (i = 0; i < m_index; i++) { - p_node = p_node->next; - } - return p_node; -} - -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; -} - -List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) { - Node *p_node = p_list->head; - List *m_rtnlst = NULL; - unsigned long long index = 0; - insertInTail(expand_resources, nodeWithULLInt(index, 0)); - insertInTail(expand_resources, nodeWithULLInt(p_list->length, 0)); - while (p_node != NULL) { - if (p_node->value != NULL) { - m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources); - int status = getByIntForNode(findByIndexForNode(m_rtnlst, 0)); - if (status == -1) break; - else if (status == 1) { - p_node = p_node->last; - releaseList(m_rtnlst); - m_rtnlst = NULL; - continue; - } - else { - releaseList(m_rtnlst); - m_rtnlst = NULL; - } - } - lupdull(expand_resources,expand_resources->length-2,++index); - p_node = p_node->next; - } - releaseList(expand_resources); - if(m_rtnlst != NULL) releaseNode(popFromHead(m_rtnlst)); - return m_rtnlst; -} - -unsigned long long getInfoForListThrough(List *expand_resources, int type){ - Node *p_node = NULL; - if (type == 0) { - p_node = findByIndexForNode(expand_resources, expand_resources->length-1); - }else{ - p_node = findByIndexForNode(expand_resources, expand_resources->length-2); - } - return *((unsigned long long *)p_node->value); -} - -int getByIntForNode(Node *p_node) { - if (p_node->type == INT) return *(int *)(p_node->value); - else return -1; -} - -unsigned int getByUIntForNode(Node *p_node){ - if (p_node->type == UINT) return *(unsigned int *)(p_node->value); - else return -1; -} - -char *getByStringForNode(Node *p_node) { - if (p_node->type == STRING) return (char *)(p_node->value); - else return NULL; -} - -double getByDoubleForNode(Node *p_node) { - if (p_node->type == DOUBLE) return *(double *)(p_node->value); - else return -1; -} - -void *getByPointerForNode(Node *p_node) { - return (void *)(p_node->value); -} - -void printListInfo(List *p_list, int priority) { - int i = 0; - Node *p_node; - for (i = 0; i < priority; i++) printf(" "); - printf("###LIST(location:%p, id:%s){\n", p_list, s_idToASCIIString(p_list->s_id)); - 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"); - -} - -void printList(List *p_list) { - int if_nearLast = 0; - Node *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((List *)p_node->value); - } - if (!if_nearLast) { - printf(", "); - } - p_node = p_node->next; - } - printf("]"); -} - -void printNodeInfo(Node *p_node, int priority) { - int i; - for (i = 0; i < priority; i++) printf(" "); - printf("#NODE(location:%p, id:%s){\n", p_node, s_idToASCIIString(p_node->s_id)); - 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(List):\n"); - printListInfo((List *)p_node->value, priority + 2); - } - for (i = 0; i < priority; i++) printf(" "); - printf("}\n"); -} - -void printNode(Node *p_node) { - int i; - printf("#NODE(location:%p, id:%s){\n", p_node, s_idToASCIIString(p_node->s_id)); - 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((List *)p_node->value); - } - } - else printf("NO\n"); - - printf("}\n"); -} - - -Node *findByIntForNode(List *p_list, int target) { - Node *t_node; - int *p_target = (int *)malloc(sizeof(int)); - *p_target = target; - t_node = findByValue(p_list, INT, p_target); - free(p_target); - return t_node; -} - -Node *findByDoubleForNode(List *p_list, double target) { - Node *t_node; - double *p_target = (double *)malloc(sizeof(double)); - *p_target = target; - t_node = findByValue(p_list, DOUBLE, p_target); - free(p_target); - return t_node; -} - -Node *findByStringForNode(List *p_list, char *target) { - Node *t_node; - char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); - strcpy(p_temp, target); - t_node = findByValue(p_list, STRING, p_temp); - free(p_temp); - return t_node; -} - -Node *findByPointerForNode(List *p_list, void *target) { - Node *t_node = findByValue(p_list, POINTER, target); - return t_node; -} - -int addValueForComplex(Node * p_node, int type, void *value) { - List *c_list; - Node *c_node; - if (p_node->type == LIST) { - c_list = (List *)p_node->value; - c_node = initNode(0); - initMallocValueForNode(c_node, type, value); - insertInTail(c_list, c_node); - return 0; - } - return -1; -} - -int addIntForComplex(Node *p_node, int temp) { - if (p_node->type == LIST) { - int *p_temp = (int *)malloc(sizeof(int)); - if(p_temp == NULL){ - showError(pushError(INT, STANDARD, initInfo("addIntForComplex()", "Error in getting the memory of int."))); - return -1; - } - *p_temp = temp; - addValueForComplex(p_node, INT, p_temp); - return 0; - } - return -1; -} - -int addDoubleForComplex(Node *p_node, double temp) { - if (p_node->type == LIST) { - double *p_temp = (double *)malloc(sizeof(double)); - if(p_temp == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo("addDoubleForComplex()", "Error in getting the memory of double."))); - return -1; - } - *p_temp = temp; - addValueForComplex(p_node, DOUBLE, p_temp); - return 0; - } - return -1; -} - -int addStringForComplex(Node *p_node, char *temp) { - if (p_node->type == LIST) { - char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); - if(p_temp == NULL){ - showError(pushError(STRING, STANDARD, initInfo("addStringForComplex()", "Error in getting the memory of string."))); - return -1; - } - strcpy(p_temp, temp); - addValueForComplex(p_node, STRING, p_temp); - return 0; - } - return -1; -} - -int addPointerForComplex(Node *p_node, void *temp) { - if (p_node->type == LIST) { - addValueForComplex(p_node, POINTER, temp); - return 0; - } - return -1; -} - -List *mply_findByInt(List* p_list, int temp) { - int *p_temp = (int *)malloc(sizeof(int)); - if(p_temp == NULL){ - showError(pushError(INT, STANDARD, initInfo("m_findByInt()", "Error in getting the memory of int."))); - return NULL; - } - List *t_list; - *p_temp = temp; - t_list = mply_findByValue(p_list, INT, (void *)p_temp); - free(p_temp); - return t_list; -} - -List *mply_findByDouble(List* p_list, double temp) { - List *t_list; - double *p_temp = (double *)malloc(sizeof(double)); - if(p_temp == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo("m_findByDouble()", "Error in getting the memory of double."))); - return NULL; - } - *p_temp = temp; - t_list = mply_findByValue(p_list, DOUBLE, (void *)p_temp); - free(p_temp); - return t_list; -} - -List *mply_findByString(List* p_list, char *temp) { - List *t_list; - char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); - if(p_temp == NULL){ - showError(pushError(STRING, STANDARD, initInfo("m_findByString()", "Error in getting the memory of string."))); - return NULL; - } - strcpy(p_temp, temp); - t_list = mply_findByValue(p_list, STRING, (void *)p_temp); - free(p_temp); - return t_list; -} - -List *mply_findByPointer(List* p_list, void *temp) { - List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); - return t_list; -} - -unsigned long long getIndexByNode(List *p_list, Node *p_node) { - 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; - } - else{ - register Node *t_node = p_list->head; - register unsigned long long index = 0; - while (t_node != NULL) { - if (p_node->s_id == t_node->s_id) return index; - index++; - t_node = t_node->next; - } - } - return 0; -} - -List *mply_findByIntForNode(List* p_list, int temp) { - int *p_temp = (int *)malloc(sizeof(int)); - if(p_temp == NULL){ - showError(pushError(INT, STANDARD, initInfo("m_findByIntForNode()", "Error in getting the memory of int."))); - return NULL; - } - *p_temp = temp; - return mply_findByValue(p_list, INT, (void *)p_temp); -} - -List *mply_findByDoubleForNode(List* p_list, double temp) { - double *p_temp = (double *)malloc(sizeof(double)); - if(p_temp == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo("m_findByDoubleForNode()", "Error in getting the memory of double."))); - return NULL; - } - *p_temp = temp; - return mply_findByValue(p_list, DOUBLE, (void *)p_temp); -} - -List *mply_findByStringForNode(List* p_list, char *temp) { - char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); - if(p_temp == NULL){ - showError(pushError(STRING, STANDARD, initInfo("m_findByStringForNode()", "Error in getting the memory of string."))); - return NULL; - } - strcpy(p_temp, temp); - return mply_findByValue(p_list, STRING, (void *)p_temp); -} - -List *mply_findByPointerForNode(List* p_list, void *temp) { - return mply_findByValue(p_list, POINTER, (void *)temp); -} - -unsigned long long calListMemory(List * p_list){ - Node *p_node = p_list->head; - unsigned long long nodes_size = 0LL; - unsigned long long list_size = sizeof(p_list); - while(p_node != NULL){ - nodes_size += sizeof(p_node); - p_node = p_node->next; - } - return list_size + nodes_size; -} - -int updateValueWithIntForNode(Node *p_node,int value){ - int *p_value = (int *)malloc(sizeof(int)); - if(p_value == NULL){ - showError(pushError(INT, STANDARD, initInfo("updateValueWithInt()", "Error in getting the memory of int."))); - return -1; - } - *p_value = value; - free(p_node->value); - p_node->value = p_value; - return 0; -} - -int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){ - unsigned long long *p_value = (unsigned long long *)malloc(sizeof(unsigned long long)); - if(p_value == NULL){ - showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int."))); - return -1; - } - *p_value = value; - free(p_node->value); - p_node->value = p_value; - return 0; -} - -int updateValueWithDoubleForNode(Node *p_node, double value){ - double *p_value = (double *)malloc(sizeof(double)); - if(p_value == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo("updateValueWithDouble()", "Error in getting the memory of double."))); - return -1; - } - *p_value = value; - free(p_node->value); - p_node->value = p_value; - return 0; -} - -int updateValueWithStringForNode(Node *p_node, char *string){ - char *p_value = (char *)malloc(sizeof(strlen(string)) + 1); - if(p_value == NULL){ - showError(pushError(STRING, STANDARD, initInfo("updateValueWithString()", "Error in getting the memory of string."))); - return -1; - } - strcpy(p_value, string); - free(p_node->value); - p_node->value = p_value; - return 0; -} - -int updateValueWithPointerForNode(Node *p_node, void *pointer){ - free(p_node->value); - p_node->value = pointer; - return 0; -} - -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; -} - - - -List *newReturn(int if_status ,int status, char *argc, ...){ - List *p_list = initList(0); - if(if_status){ - lisrti(p_list, status); - } - if(status != 0){ - va_list args; - va_start(args, argc); - char p_ch = argc[0]; - char t_ch[256]; - int count = 0, t_count = 0; - while(p_ch != '\0'){ - if(p_ch == '%'){ - switch (argc[count + 1]) { - case 'd': - lisrti(p_list, va_arg(args, int)); - break; - case 's': - t_count = 0; - while ((t_ch[t_count] = va_arg(args, int)) != '\0') t_count++; - t_ch[t_count] = '\0'; - lisrts(p_list, t_ch); - break; - case 'f': - lisrtd(p_list, va_arg(args, double)); - break; - case 'p': - lisrtp(p_list, va_arg(args, void *)); - break; - case 'u': - if(argc[count + 2] == 'l'){ - if(argc[count + 3] == 'l'){ - lisrtull(p_list, va_arg(args, unsigned long long)); - count += 2; - } - else{ - count++; - } - } - else{ - lisrtu(p_list, va_arg(args, unsigned int)); - } - break; - default: - break; - } - count++; - } - p_ch = argc[++count]; - } - va_end(args); - } - return p_list; -} - -List *newCReturn(void){ - return newReturn(1, 0, NULL); -} - -void printListForCustom(List *p_list,void (*func)(void *value)){ - printf("###LIST (LEN:%llu ",p_list->length); - if(p_list->s_id != NULL) printf("SID:%s",p_list->s_id->decrypt_str); - 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/list/list_expand_calculate.c b/list/list_expand_calculate.c new file mode 100644 index 0000000..ebfc7bf --- /dev/null +++ b/list/list_expand_calculate.c @@ -0,0 +1,13 @@ +#include +#include + +unsigned long long calListMemory(List * p_list){ + Node *p_node = p_list->head; + unsigned long long nodes_size = 0LL; + unsigned long long list_size = sizeof(p_list); + while(p_node != NULL){ + nodes_size += sizeof(p_node); + p_node = p_node->next; + } + return list_size + nodes_size; +} diff --git a/list/list_expand_callback.c b/list/list_expand_callback.c new file mode 100644 index 0000000..c4a4341 --- /dev/null +++ b/list/list_expand_callback.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include + +List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) { + Node *p_node = p_list->head; + List *m_rtnlst = NULL; + unsigned long long index = 0; + insertInTail(expand_resources, nodeWithULLInt(index, 0)); + insertInTail(expand_resources, nodeWithULLInt(p_list->length, 0)); + while (p_node != NULL) { + if (p_node->value != NULL) { + m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources); + int status = getByIntForNode(findByIndexForNode(m_rtnlst, 0)); + if (status == -1) break; + else if (status == 1) { + p_node = p_node->last; + releaseList(m_rtnlst); + m_rtnlst = NULL; + continue; + } + else { + releaseList(m_rtnlst); + m_rtnlst = NULL; + } + } + lupdull(expand_resources,expand_resources->length-2,++index); + p_node = p_node->next; + } + releaseList(expand_resources); + if(m_rtnlst != NULL) releaseNode(popFromHead(m_rtnlst)); + return m_rtnlst; +} + +unsigned long long getInfoForListThrough(List *expand_resources, int type){ + Node *p_node = NULL; + if (type == 0) { + p_node = findByIndexForNode(expand_resources, expand_resources->length-1); + }else{ + p_node = findByIndexForNode(expand_resources, expand_resources->length-2); + } + return *((unsigned long long *)p_node->value); +} + +int getByIntForNode(Node *p_node) { + if (p_node->type == INT) return *(int *)(p_node->value); + else return -1; +} + +unsigned int getByUIntForNode(Node *p_node){ + if (p_node->type == UINT) return *(unsigned int *)(p_node->value); + else return -1; +} + +List *newReturn(int if_status ,int status, char *argc, ...){ + List *p_list = initList(0); + if(if_status){ + lisrti(p_list, status); + } + if(status != 0){ + va_list args; + va_start(args, argc); + char p_ch = argc[0]; + char t_ch[256]; + int count = 0, t_count = 0; + while(p_ch != '\0'){ + if(p_ch == '%'){ + switch (argc[count + 1]) { + case 'd': + lisrti(p_list, va_arg(args, int)); + break; + case 's': + t_count = 0; + while ((t_ch[t_count] = va_arg(args, int)) != '\0') t_count++; + t_ch[t_count] = '\0'; + lisrts(p_list, t_ch); + break; + case 'f': + lisrtd(p_list, va_arg(args, double)); + break; + case 'p': + lisrtp(p_list, va_arg(args, void *)); + break; + case 'u': + if(argc[count + 2] == 'l'){ + if(argc[count + 3] == 'l'){ + lisrtull(p_list, va_arg(args, unsigned long long)); + count += 2; + } + else{ + count++; + } + } + else{ + lisrtu(p_list, va_arg(args, unsigned int)); + } + break; + default: + break; + } + count++; + } + p_ch = argc[++count]; + } + va_end(args); + } + return p_list; +} + +List *newCReturn(void){ + return newReturn(1, 0, NULL); +} diff --git a/list/list_expand_complex.c b/list/list_expand_complex.c new file mode 100644 index 0000000..9f9a02f --- /dev/null +++ b/list/list_expand_complex.c @@ -0,0 +1,70 @@ +#include +#include +#include + +Node *nodeWithComplex(void) { + Node *p_node = initNode(0); + p_node->type = LIST; + p_node->value = initList(0); + return p_node; +} + +int addValueForComplex(Node * p_node, int type, void *value) { + List *c_list; + Node *c_node; + if (p_node->type == LIST) { + c_list = (List *)p_node->value; + c_node = initNode(0); + initMallocValueForNode(c_node, type, value); + insertInTail(c_list, c_node); + return 0; + } + return -1; +} + +int addIntForComplex(Node *p_node, int temp) { + if (p_node->type == LIST) { + int *p_temp = (int *)malloc(sizeof(int)); + if(p_temp == NULL){ + return -1; + } + *p_temp = temp; + addValueForComplex(p_node, INT, p_temp); + return 0; + } + return -1; +} + +int addDoubleForComplex(Node *p_node, double temp) { + if (p_node->type == LIST) { + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + return -1; + } + *p_temp = temp; + addValueForComplex(p_node, DOUBLE, p_temp); + return 0; + } + return -1; +} + +int addStringForComplex(Node *p_node, char *temp) { + if (p_node->type == LIST) { + char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); + if(p_temp == NULL){ + return -1; + } + strcpy(p_temp, temp); + addValueForComplex(p_node, STRING, p_temp); + return 0; + } + return -1; +} + +int addPointerForComplex(Node *p_node, void *temp) { + if (p_node->type == LIST) { + addValueForComplex(p_node, POINTER, temp); + return 0; + } + return -1; +} diff --git a/list/list_expand_find.c b/list/list_expand_find.c new file mode 100644 index 0000000..1f06dfd --- /dev/null +++ b/list/list_expand_find.c @@ -0,0 +1,126 @@ +#include +#include +#include +#ifdef list_quick_enable +#include +#endif + +Node *findByIntForNode(List *p_list, int target) { + Node *t_node; + int *p_target = (int *)malloc(sizeof(int)); + *p_target = target; + t_node = findByValue(p_list, INT, p_target); + free(p_target); + return t_node; +} + +Node *findByDoubleForNode(List *p_list, double target) { + Node *t_node; + double *p_target = (double *)malloc(sizeof(double)); + *p_target = target; + t_node = findByValue(p_list, DOUBLE, p_target); + free(p_target); + return t_node; +} + +Node *findByStringForNode(List *p_list, char *target) { + Node *t_node; + char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); + strcpy(p_temp, target); + t_node = findByValue(p_list, STRING, p_temp); + free(p_temp); + return t_node; +} + +Node *findByPointerForNode(List *p_list, void *target) { + Node *t_node = findByValue(p_list, POINTER, target); + return t_node; +} + +List *mply_findByInt(List* p_list, int temp) { + int *p_temp = (int *)malloc(sizeof(int)); + if(p_temp == NULL){ + return NULL; + } + List *t_list; + *p_temp = temp; + t_list = mply_findByValue(p_list, INT, (void *)p_temp); + free(p_temp); + return t_list; +} + +List *mply_findByDouble(List* p_list, double temp) { + List *t_list; + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + return NULL; + } + *p_temp = temp; + t_list = mply_findByValue(p_list, DOUBLE, (void *)p_temp); + free(p_temp); + return t_list; +} + +List *mply_findByString(List* p_list, char *temp) { + List *t_list; + char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); + if(p_temp == NULL){ + return NULL; + } + strcpy(p_temp, temp); + t_list = mply_findByValue(p_list, STRING, (void *)p_temp); + free(p_temp); + return t_list; +} + +List *mply_findByPointer(List* p_list, void *temp) { + List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); + return t_list; +} + +List *mply_findByIntForNode(List* p_list, int temp) { + int *p_temp = (int *)malloc(sizeof(int)); + if(p_temp == NULL){ + return NULL; + } + *p_temp = temp; + return mply_findByValue(p_list, INT, (void *)p_temp); +} + +List *mply_findByDoubleForNode(List* p_list, double temp) { + double *p_temp = (double *)malloc(sizeof(double)); + if(p_temp == NULL){ + return NULL; + } + *p_temp = temp; + return mply_findByValue(p_list, DOUBLE, (void *)p_temp); +} + +List *mply_findByStringForNode(List* p_list, char *temp) { + char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); + if(p_temp == NULL){ + return NULL; + } + strcpy(p_temp, temp); + return mply_findByValue(p_list, STRING, (void *)p_temp); +} + +List *mply_findByPointerForNode(List* p_list, void *temp) { + return mply_findByValue(p_list, POINTER, (void *)temp); +} + +Node *findByIndexForNode(List *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; + unsigned long long i; + for (i = 0; i < m_index; i++) { + p_node = p_node->next; + } + return p_node; +} diff --git a/list/list_expand_get.c b/list/list_expand_get.c new file mode 100644 index 0000000..767d3ef --- /dev/null +++ b/list/list_expand_get.c @@ -0,0 +1,40 @@ +#include +#include +#include +#ifdef list_quick_enable +#include +#endif + +char *getByStringForNode(Node *p_node) { + if (p_node->type == STRING) return (char *)(p_node->value); + else return NULL; +} + +double getByDoubleForNode(Node *p_node) { + if (p_node->type == DOUBLE) return *(double *)(p_node->value); + else return -1; +} + +void *getByPointerForNode(Node *p_node) { + return (void *)(p_node->value); +} + +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; + register unsigned long long index = 0; + while (t_node != NULL) { +#ifdef id_enable + if (p_node->s_id == t_node->s_id) return index; +#endif + index++; + t_node = t_node->next; + } + return 0; +} diff --git a/list/list_expand_node.c b/list/list_expand_node.c new file mode 100644 index 0000000..912bef2 --- /dev/null +++ b/list/list_expand_node.c @@ -0,0 +1,70 @@ +#include +#include +#include + +Node *nodeWithInt(int m_int, _Bool if_sid) { + Node *p_node; + int *p_int = (int *)malloc(sizeof(int)); + if(p_int == NULL){ + return NULL; + } + *p_int = m_int; + p_node = initNode(if_sid); + initMallocValueForNode(p_node, INT, (void *)p_int); + return p_node; +} + +Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){ + Node *p_node; + unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); + if(pu_int == NULL){ + return NULL; + } + *pu_int = m_uint; + p_node = initNode(if_sid); + initMallocValueForNode(p_node, INT, (void *)pu_int); + return p_node; +} + +Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) { + Node *p_node; + unsigned long long *p_ullint = (unsigned long long *)malloc(sizeof(unsigned long long)); + if(p_ullint == NULL){ + return NULL; + } + *p_ullint = m_ullint; + p_node = initNode(if_sid); + initMallocValueForNode(p_node, ULLINT, (void *)p_ullint); + return p_node; +} + +Node *nodeWithDouble(double m_double, _Bool if_sid) { + Node *p_node; + double *p_double = (double *)malloc(sizeof(double)); + if(p_double == NULL){ + return NULL; + } + *p_double = m_double; + p_node = initNode(if_sid); + initMallocValueForNode(p_node, DOUBLE, (void *)p_double); + return p_node; +} + +Node *nodeWithString(const char *m_string, _Bool if_sid) { + Node *p_node; + char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); + if(p_string == NULL){ + return NULL; + } + strcpy(p_string, m_string); + p_node = initNode(if_sid); + initMallocValueForNode(p_node, STRING, (void *)p_string); + return p_node; +} + +Node *nodeWithPointer(const void *m_pointer, _Bool if_sid) { + Node *p_node = initNode(if_sid); + initMallocValueForNode(p_node, POINTER, m_pointer); + return p_node; +} + diff --git a/list/list_expand_update.c b/list/list_expand_update.c new file mode 100644 index 0000000..a89f2b3 --- /dev/null +++ b/list/list_expand_update.c @@ -0,0 +1,53 @@ +#include +#include +#include + +int updateValueWithIntForNode(Node *p_node,int value){ + int *p_value = (int *)malloc(sizeof(int)); + if(p_value == NULL){ + return -1; + } + *p_value = value; + free(p_node->value); + p_node->value = p_value; + return 0; +} + +int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){ + unsigned long long *p_value = (unsigned long long *)malloc(sizeof(unsigned long long)); + if(p_value == NULL){ + return -1; + } + *p_value = value; + free(p_node->value); + p_node->value = p_value; + return 0; +} + +int updateValueWithDoubleForNode(Node *p_node, double value){ + double *p_value = (double *)malloc(sizeof(double)); + if(p_value == NULL){ + return -1; + } + *p_value = value; + free(p_node->value); + p_node->value = p_value; + return 0; +} + +int updateValueWithStringForNode(Node *p_node, char *string){ + char *p_value = (char *)malloc(sizeof(strlen(string)) + 1); + if(p_value == NULL){ + return -1; + } + strcpy(p_value, string); + free(p_node->value); + p_node->value = p_value; + return 0; +} + +int updateValueWithPointerForNode(Node *p_node, void *pointer){ + free(p_node->value); + p_node->value = pointer; + return 0; +} diff --git a/list/list_find.c b/list/list_find.c new file mode 100644 index 0000000..f07911c --- /dev/null +++ b/list/list_find.c @@ -0,0 +1,105 @@ +#include +#include + +#ifdef id_enable +Node *findByIdForNode(List *p_list, SID * s_id) { + Node *ph_node = p_list->head; + Node *pt_node = p_list->tail; + int direction = 0; + while (ph_node != pt_node) { + if (direction == 0) { + if (simFitS_id(ph_node->s_id, s_id)) { + return ph_node; + } + else { + ph_node = ph_node->next; + } + direction = 1; + } + else { + if (simFitS_id(pt_node->s_id, s_id)) { + return pt_node; + } + else { + pt_node = pt_node->last; + } + } + } + return NULL; +} +#endif + +Node *findByValue(List *p_list, unsigned int type, const void *value) { + Node *p_node = p_list->head; + while (p_node != NULL) { + if (p_node->type != type) { + p_node = p_node->next; + continue; + } + if (type == INT) { + if (*((int *)p_node->value) == *((int *)value)) { + return p_node; + } + } + else if (type == DOUBLE) { + if (*((double *)p_node->value) == *((double *)value)) { + return p_node; + } + } + else if (type == STRING) { + if (!strcmp((char *)p_node->value, (char *)value)) + { + return p_node; + } + } + else if (type == POINTER) { + if (p_node->value == value) { + return p_node; + } + } + + p_node = p_node->next; + + } + return NULL; +} + +List *mply_findByValue(List *p_list, unsigned int type, const void *value) { + List *f_list = initList(0); + Node *p_node = p_list->head; + while (p_node != NULL) { + if (p_node->type != type) { + p_node = p_node->next; + continue; + } + if (type == INT) { + if (*((int *)p_node->value) == *((int *)value)) { + Node *f_node = p_node; + insertInTail(f_list, f_node); + } + } + else if (type == DOUBLE) { + if (*((double *)p_node->value) == *((double *)value)) { + Node *f_node = p_node; + insertInTail(f_list, f_node); + } + } + else if (type == STRING) { + if (!strcmp((char *)p_node->value, (char *)value)) + { + Node *f_node = p_node; + insertInTail(f_list, f_node); + } + } + else if (type == POINTER) { + if (p_node->value == value) { + Node *f_node = p_node; + insertInTail(f_list, f_node); + } + } + + p_node = p_node->next; + + } + return f_list; +} diff --git a/list/list_info.c b/list/list_info.c new file mode 100644 index 0000000..c1ac1dd --- /dev/null +++ b/list/list_info.c @@ -0,0 +1,12 @@ +#include +#include + +unsigned long long len(List *p_list) { + return p_list->length; +} + +int isListEmpty(List *p_list) { + if (p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty. + return 1; // But we should ensure that both of them are NULL when we + return 0; // want to make a list empty. +} diff --git a/list/list_init.c b/list/list_init.c new file mode 100644 index 0000000..39e9413 --- /dev/null +++ b/list/list_init.c @@ -0,0 +1,59 @@ +#include +#include + +Node *initNode(_Bool if_sid) { + Node *p_node = (Node *)malloc(sizeof(Node)); + if(p_node == NULL){ + return NULL; + } + Node *prec_node = NULL; +#ifdef id_enable + if (if_sid)p_node->s_id = getS_id(LIST_NODE, 1); + else p_node->s_id = NULL; +#endif + p_node->next = NULL; + p_node->last = NULL; + p_node->type = VOID; + p_node->f_number = 0; + if (if_safeModeForNode) { + if_safeModeForNode = 0; + prec_node = initNode(0); + if_safeModeForNode = 1; + initMallocValueForNode(prec_node, POINTER, (void *)p_node); + insertInTail(node_list, prec_node); + } + return p_node; +} + +List *initList(_Bool if_sid) { + Node *p_node = NULL; + List *p_list = (List *)malloc(sizeof(List)); + if(p_list == NULL){ + return NULL; + } +#ifdef id_enable + if(if_sid) p_list->s_id = getS_id(LIST, 1); + else p_list->s_id = NULL; +#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); + if_safeModeForNode = 1; + initMallocValueForNode(p_node, POINTER, (void *)p_list); + insertInTail(list_list, p_node); + } + return p_list; +} + +inline int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { + p_node->type = type; + p_node->value = (void *)p_value; + return 0; +} diff --git a/list/list_insert.c b/list/list_insert.c new file mode 100644 index 0000000..038e763 --- /dev/null +++ b/list/list_insert.c @@ -0,0 +1,65 @@ +#include +#include +#ifdef list_quick_enable +#include +#endif + +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; +} + +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/list/list_print.c b/list/list_print.c new file mode 100644 index 0000000..dce1f49 --- /dev/null +++ b/list/list_print.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include + +#ifdef id_enable +#include +#endif + +void printListInfo(List *p_list, int priority) { + int i = 0; + Node *p_node; + for (i = 0; i < priority; i++) printf(" "); + printf("###LIST(location:%p",p_list); +#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"); + +} + +void printList(List *p_list) { + int if_nearLast = 0; + Node *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((List *)p_node->value); + } + if (!if_nearLast) { + printf(", "); + } + p_node = p_node->next; + } + printf("]"); +} + +void printNodeInfo(Node *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(List):\n"); + printListInfo((List *)p_node->value, priority + 2); + } + for (i = 0; i < priority; i++) printf(" "); + printf("}\n"); +} + +void printNode(Node *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((List *)p_node->value); + } + } + else printf("NO\n"); + + printf("}\n"); +} + +void printListForCustom(List *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/list/list_quick.c b/list/list_quick.c new file mode 100644 index 0000000..a31aaae --- /dev/null +++ b/list/list_quick.c @@ -0,0 +1,237 @@ +#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/list/list_release.c b/list/list_release.c new file mode 100644 index 0000000..6ef0124 --- /dev/null +++ b/list/list_release.c @@ -0,0 +1,122 @@ +#include +#include +#ifdef list_quick_enable +#include +#endif + +int releaseNode(Node *p_node) { + if (if_safeModeForNode == 1) { + removeByNode(node_list, p_node); + } + if (p_node->value != NULL) { + if (p_node->type != POINTER && p_node->type != HOLE) { + if (p_node->type == LIST) { + releaseList((List *)p_node->value); + } + else { + free(p_node->value); + } + } + p_node->value = NULL; + } + p_node->f_number = 0; + p_node->last = NULL; + p_node->next = NULL; + p_node->type = VOID; + p_node->value = NULL; +#ifdef id_enable + if (p_node->s_id != NULL) freeS_id(p_node->s_id); +#endif + free(p_node); + return 0; +} + +int releaseOnlyNode(Node *p_node) { +#ifdef id_enable + if (p_node->s_id != NULL) freeS_id(p_node->s_id); +#endif + p_node->last = NULL; + p_node->next = NULL; + p_node->type = VOID; + p_node->value = NULL; + free(p_node); + return 0; +} + +int releaseList(List *p_list) { + Node *p_node, *pl_node; + p_node = p_list->head; + if (if_safeModeForNode == 1) { + Node *tar_list = findByValue(list_list, POINTER, (void *)p_list);//turn pointer in to int to compare. + removeByNode(list_list, tar_list); + } + while (p_node != NULL) { + pl_node = p_node; + p_node = p_node->next; + pl_node->next = NULL; + pl_node->last = NULL; + releaseNode(pl_node); + } + 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; +} + +int releaseListForSingle(List *p_list) { + releaseList(p_list); + return 0; +} + +int releaseNodeForCustom(Node *p_node, int (*func)(void *)){ + if (if_safeModeForNode) { + removeByNode(node_list, p_node); + } + if (p_node->value != NULL) { + if (func(p_node->value)) + p_node->value = NULL; + } + p_node->last = NULL; + p_node->next = NULL; + p_node->type = VOID; + p_node->value = NULL; +#ifdef id_enable + if (p_node->s_id != NULL) freeS_id(p_node->s_id); +#endif + free(p_node); + return 0; +} + +int releaseListForCustom(List *p_list, int (*func)(void *)){ + Node *p_node, *pl_node; + p_node = p_list->head; + if (if_safeModeForNode == 1) { + Node *tar_list = findByValue(list_list, POINTER, (void *)p_list); + removeByNode(list_list, tar_list); + } + while (p_node != NULL) { + pl_node = p_node; + p_node = p_node->next; + pl_node->next = NULL; + pl_node->last = NULL; + releaseNodeForCustom(pl_node,func); + } + p_list->head = NULL; + p_list->tail = NULL; + 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/list/list_remove.c b/list/list_remove.c new file mode 100644 index 0000000..575eb79 --- /dev/null +++ b/list/list_remove.c @@ -0,0 +1,137 @@ +#include +#include +#ifdef list_quick_enable +#include +#endif + +#ifdef id_enable +int removeById(List *p_list, SID *s_id) { + Node *tmp = p_list->head; + if (isListEmpty(p_list)) + return -1; + do { + if (simFitS_id(tmp->s_id, s_id)) { + if (tmp != p_list->head) { + tmp->last->next = tmp->next; + } + else { + p_list->head = tmp->next; + } + if (tmp != p_list->tail) { + tmp->next->last = tmp->last; + } + else { + p_list->tail = tmp->last; + } + + p_list->length -= 1; + return 1;//found + } + else { + tmp = tmp->next; + } + } while (tmp != NULL); + + return 0;//not find +} + +#endif + +int removeByNode(List *p_list, Node *p_node) { + if (isListEmpty(p_list)) + return -1; + if(p_node == p_list->head){ + popFromHead(p_list); + return 0; + } + else if(p_node == p_list->tail){ + 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_list->length -= 1; + return 0;//not find +} + +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; + //releaseNode(tmp); not necessary + if (isListEmpty(p_list)) { + p_list->head = NULL; + p_list->tail = NULL; + } + p_list->length -= 1; + return p_node; +} + +Node *popFromTail(List *p_list) { + Node *p_node = p_list->tail; + 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; + //releaseNode(tmp); not necessary + } + if (isListEmpty(p_list)) { + p_list->head = NULL; + p_list->tail = NULL; + } + p_list->length -= 1; + return p_node; +} diff --git a/list/list_replace.c b/list/list_replace.c new file mode 100644 index 0000000..ae08d2a --- /dev/null +++ b/list/list_replace.c @@ -0,0 +1,53 @@ +#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; + p_node->last = pt_node->last; + if (p_list->head != pt_node) pt_node->last->next = 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; +} + +int exchangeNode(List *p_list, Node *f_node, Node *s_node){ + Node *fl_node = f_node->last, *fn_node = f_node->next; + if(p_list->head != f_node) f_node->last->next = s_node; + else p_list->head = s_node; + if(p_list->tail != f_node) f_node->next->last = s_node; + else p_list->tail = s_node; + + if(p_list->head != s_node) s_node->last->next = f_node; + else p_list->head = f_node; + if(p_list->tail != s_node) s_node->next->last = f_node; + else p_list->tail = f_node; + f_node->next = s_node->next; + 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/list/list_simple.c b/list/list_simple.c new file mode 100644 index 0000000..4971fe7 --- /dev/null +++ b/list/list_simple.c @@ -0,0 +1,67 @@ +#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/list/list_simple_node.c b/list/list_simple_node.c new file mode 100644 index 0000000..0b83d9c --- /dev/null +++ b/list/list_simple_node.c @@ -0,0 +1,41 @@ +#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/list/list_sort.c b/list/list_sort.c new file mode 100644 index 0000000..6d97acf --- /dev/null +++ b/list/list_sort.c @@ -0,0 +1,50 @@ +#include +#include +#include +#ifdef list_quick_enable +#include +#endif + +/* + *内部函数: 通过节点中的值查找相关多个节点. + *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. + *返回: 如果成功返回0,如果失败则返回-1.*/ +static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)); + +static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *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 unsigned long long i = end,j = begin; + for(; i >= begin; i--){ + if(i <= j) break; + i_node = findByIndexForNode(p_list, i); + if(func(t_node, i_node) < 0){ + exchangeNode(p_list, t_node, i_node); + for(; j <= end; j++){ + if(j >= i) break; + j_node = findByIndexForNode(p_list, j); + if(func(t_node, j_node) > 0){ + exchangeNode(p_list, t_node, j_node); + break; + } + } + } + } + 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); + } + 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 + sortList(p_list, 0, p_list->length-1, func); + return 0; +} diff --git a/list/safe_mode.c b/list/safe_mode.c new file mode 100644 index 0000000..69a1564 --- /dev/null +++ b/list/safe_mode.c @@ -0,0 +1,101 @@ +#include +#include +#include + +static int if_safeModeForNode = 0; +static List *node_list = NULL; +static List *list_list = NULL; + +/*属于安全模式操作内部调用,释放节点而不释放其中的值.*/ +static int releaseSingleNodeForsafeModeForNode(List *p_list); + +/*属于安全模式操作内部调用,释放链表而不释放其中的值.*/ +static int releaseSingleListForsafeModeForNode(List *p_list); + + +int safeModeForNode(int ifon) { + if (ifon == 1) { + if (node_list == NULL && list_list == NULL) { + node_list = (List *)malloc(sizeof(List)); + if(node_list == NULL){ + return -1; + } + list_list = (List *)malloc(sizeof(List)); + if(list_list == NULL){ + return -1; + } + list_list->head = NULL; + list_list->length = 0; + list_list->tail = NULL; + + node_list->head = NULL; + node_list->length = 0; + node_list->tail = NULL; + + if_safeModeForNode = 1; + } + else { + return -1; + } + } + + return ifon; +} + +static int releaseSingleListForsafeModeForNode(List *p_list) { + Node *p_node = p_list->head; + List *plv_node = NULL; + while (p_node != NULL) { + plv_node = (List *)p_node->value; +#ifdef id_enable + freeS_id(plv_node->s_id); +#endif + plv_node->head = NULL; + plv_node->length = 0; + plv_node->tail = NULL; + free(plv_node); + p_node = p_node->next; + } + p_list->head = NULL; + p_list->length = 0; + p_list->tail = NULL; +#ifdef id_enable + freeS_id(p_list->s_id); +#endif + free(p_list); + return 0; +} + +static int releaseSingleNodeForsafeModeForNode(List *p_list) { + Node *p_node = p_list->head; + Node *pnv_node = NULL; + while (p_node != NULL) { + pnv_node = (Node *)p_node->value; +#ifdef id_enable + freeS_id(pnv_node->s_id); +#endif + pnv_node->last = NULL; + pnv_node->next = NULL; + pnv_node->type = VOID; + pnv_node->value = NULL; + free(pnv_node); + p_node = p_node->next; + } +#ifdef id_enable + free(p_list->s_id); +#endif + p_list->head = NULL; + p_list->length = 0; + p_list->tail = NULL; + free(p_list); + return 0; +} + +int releaseAllForNode(void) { + if (if_safeModeForNode == 1) { + if_safeModeForNode = 0; + releaseSingleNodeForsafeModeForNode(node_list); + releaseSingleListForsafeModeForNode(list_list); + } + return 0; +} diff --git a/stack/stack.c b/stack/stack.c index 320ff40..1f760e6 100644 --- a/stack/stack.c +++ b/stack/stack.c @@ -1,12 +1,11 @@ -#include "stack.h" +#include +#include Stack *initStack(void) { Stack *p_stack = (Stack *)malloc(sizeof(Stack)); - if(p_stack == NULL){ - showError(pushError(STACK, STANDARD, initInfo("initStack()", "Error in getting the memory of stack."))); - return NULL; - } +#ifdef id_enable p_stack->s_id = getS_id(STACK, 1); +#endif p_stack->length = 0; p_stack->top = NULL; return p_stack; @@ -14,11 +13,9 @@ Stack *initStack(void) { SNode *initSNode(void) { SNode *p_snode = (SNode *)malloc(sizeof(SNode)); - if(p_snode == NULL){ - showError(pushError(STACK_NODE, STANDARD, initInfo("initSNode()", "Error in getting the memory of snode."))); - return NULL; - } +#ifdef id_enable p_snode->s_id = getS_id(STACK_NODE, 1); +#endif p_snode->next = NULL; p_snode->value = NULL; return p_snode; @@ -50,7 +47,9 @@ int releaseStack(Stack *p_stack) { p_sndoe = p_sndoe->next; releaseSNode(pl_snode); } +#ifdef id_enable freeS_id(p_stack->s_id); +#endif p_stack->top = NULL; p_stack->length = 0; free(p_stack); @@ -58,7 +57,9 @@ int releaseStack(Stack *p_stack) { } int releaseSNode(SNode *p_snode) { +#ifdef id_enable freeS_id(p_snode->s_id); +#endif free(p_snode->value); p_snode->value = NULL; p_snode->type = VOID; diff --git a/stack/stack.h b/stack/stack.h deleted file mode 100644 index ef36892..0000000 --- a/stack/stack.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef STACK_H -#define STACK_H -#include "../type/type.h" -#include "../list/list_expand.h" - -Stack *initStack(void); -SNode *initSNode(void); -int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value); - -SNode *popStack(Stack *p_stack); -int pushStack(Stack *p_stack, SNode *p_snode); - -int releaseStack(Stack *p_stack); -int releaseSNode(SNode *p_snode); - -#endif /* stack_h */ diff --git a/stack/stack_expand.c b/stack/stack_expand.c index b0b3aa1..e4079eb 100644 --- a/stack/stack_expand.c +++ b/stack/stack_expand.c @@ -1,10 +1,11 @@ -#include "stack_expand.h" +#include +#include +#include SNode *snodeWithInt(int temp) { SNode *p_snode = initSNode(); int *p_temp = (int *)malloc(sizeof(int)); if(p_temp == NULL){ - showError(pushError(INT, STANDARD, initInfo("snodeWithInt()", "Error in getting the memory of int."))); return NULL; } *p_temp = temp; @@ -16,7 +17,6 @@ SNode *snodeWithDouble(double temp) { SNode *p_snode = initSNode(); double *p_temp = (double *)malloc(sizeof(double)); if(p_temp == NULL){ - showError(pushError(DOUBLE, STANDARD, initInfo("snodeWithDouble()", "Error in getting the memory of double."))); return NULL; } *p_temp = temp; @@ -28,7 +28,6 @@ SNode *snodeWithString(char *temp) { SNode *p_snode = initSNode(); char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); if(p_temp == NULL){ - showError(pushError(STRING, STANDARD, initInfo("snodeWithString()", "Error in getting the memory of string."))); return NULL; } strcpy(p_temp, temp); diff --git a/test.h b/test.h index 8993740..54ed677 100644 --- a/test.h +++ b/test.h @@ -3,9 +3,14 @@ #include -#include "type/type.h" -#include "list/list_expand.h" -#include "stack/stack_expand.h" +#include +#include +#include +#include +#include +#include +#include +#include //#include "tree/tree_expand.h" #include "communicate/communicate.h" diff --git a/type/type.h b/type/type.h deleted file mode 100644 index 4f8f429..0000000 --- a/type/type.h +++ /dev/null @@ -1,351 +0,0 @@ -#ifndef type_h -#define type_h - -#include -#include -#include -#include -#include -#include -#include - -/* -#include -#include -#include -#include -*/ - - - - -/************************************************ - *库相关类型的编号 - ************************************************/ - -#define VOID 0 -#define INT 1 -#define DOUBLE 2 -#define STRING 3 -#define POINTER 4 -#define LIST 5 -#define STACK 6 -#define TREE 7 -#define LIST_NODE 8 -#define TREE_NODE 9 -#define STACK_NODE 10 -#define T_SID 11 -#define UINT 12 -#define STANDARD_DATA 13 -#define DATA_FILE 14 -#define MESSAGE 15 -#define HOLE 16 -#define ULLINT 17 - - - - - -/************************************************ - *库相关参数的定义 - ************************************************/ - -#define DEEPC 1 -#define DEEPB 2 -#define DEEPA 3 -#define TYPE_LEN 5 -#define DEEPC_LEN 4 -#define DEEPB_LEN 8 -#define DEEPA_LEN 32 -#define DATA_BIT 5 -#define DEEP_LEN 25 -#define DEEPER_LEN 65 -#define DEEPEST_LEN 225 -#define SID_LEN 33 -#define FILE_TSET_LEN 18 -#define HEAD_TEST_LEN 9 -#define INFO_TEST_LEN 8 -#define ENABLE_LIST_QUICK 65535 -#define FN_NODE_SPARE 500 -#define INDEX_CHANGE_MAX 500 -#define INDEX_DISTANCE_MAX 120 -#define STD_TEXT_LEN 4 -#define HIGH 0x3 -#define STANDARD 0x2 -#define LOW 0x1 - - - - - -/************************************************ - *库相关操作宏的定义 - ************************************************/ - -#define ABS(x) ((x>0)?(x):(-x)) - - - - - -/************************************************ - *库相关结构体的定义 - ************************************************/ - -/* - *MD5的管理及操作的结构 - */ -typedef struct md5_ctx{ - unsigned int count[2]; - unsigned int state[4]; - unsigned char buffer[64]; -}MD5_CTX; - -/* - *SID的初始值管理及操作的结构 - */ -struct sid_raw{ - unsigned int type; - unsigned int *value;//4 - unsigned int *value_deeper;//8 - unsigned int *value_deepest;//32 -}; - -/* - *SID的管理及操作的结构 - */ -typedef struct s_id{ - struct sid_raw *sr;//指向SID初始值 - unsigned int deep;//SID初始值的复杂度 - MD5_CTX *md5;//指向MD5结构 - unsigned char *decrypt_hex;//指向MD5的Hex信息 - char *decrypt_str;//指向MD5的Hex信息转化成的字符串 - -}SID; - -/* - *节点的管理及操作的结构 - */ -typedef struct Node{ - unsigned long long f_number;//长链表模式下,分派的数组节点编号 - unsigned int type;//类型 - void *value;//值指针 - struct Node *next;//指向下一个节点 - struct Node *last;//指向上一个节点 - SID *s_id; -} Node; - -/* - *单向节点的管理及操作的结构 - */ -typedef struct simple_Node{ - void *value;//值指针 - struct simple_Node *next;//指向下一个节点 -}s_Node; - -/* - *长链表模式下链表缓存块的记录结构 - */ -struct lst_std_id{ - unsigned long long start_idx; - unsigned long long end_idx; - SID *sid; -}; - -struct list_quick; - -/* - *链表的管理及操作的结构 - */ -typedef struct List{ - Node *head;//指向第一个节点 - Node *tail;//指向最后一个节点 - s_Node *s_head;//指向第一个单向节点 - s_Node *s_tail;//指向最后一个单向节点 - /*如果长链表模式开启则指向对应的长链表模式的管理结构,如果未开启则为NULL*/ - struct list_quick *p_lq; - unsigned long long length;//链表的长度 - SID *s_id; -} List; - -/* - *长链表模式下链表改动偏移量的记录结构 - */ -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; -}; - -/* - *错误管理中信息的管理及操作的结构 - */ -typedef struct Info{ - char head[64];//信息头 - char body[256];//信息内容 -}Info; - -/* - *错误管理中错误的管理及操作的结构 - */ -typedef struct Error{ - unsigned int type;//错误类型号 - int priority;//优先级 - time_t time;//错误产生的时间 - Info info;//信息指针 -}Error; - -/* - *错误管理中警告的管理及操作的结构 - */ -typedef struct Notice{ - unsigned int type;//警告类型号 - time_t time;//警告产生的时间 - Info info;//信息指针 -}Notice; - -/* - *错误管理中日志信息的管理及操作的结构 - */ -typedef struct Log{ - FILE *fp;//日志文件的指针 - int if_enable;//日志文件是否启用 - unsigned long int id;//日志文件的ID -}Log; - -/* - *栈节点的管理及操作的结构 - */ -typedef struct stack_node{ - unsigned int type;//栈节点的类型 - void *value;//值指针 - struct stack_node *next;//下一个栈节点 - SID *s_id;//栈节点的ID -} SNode; - -/* - *栈的管理及操作的结构 - */ -typedef struct stack{ - unsigned long long length;//栈的长度 - SNode *top;//指向栈顶的栈节点 - SID *s_id;//栈的ID -} Stack; - -/* - *超级树节点的管理及操作的结构 - */ -typedef struct tree_node -{ - SID *s_id;//超级树节点的ID - List *home;//超级树节点的子节点列表 - struct tree_node *father;//超级树节点的父节点 - Node *room;//超级树节点的父节点的子节点列表 - unsigned long long child_num;//超级树节点的子节点数量 - unsigned int type;//超级树节点的类型 - void *value;//值指针 -}TNode; - -/* - *二叉树节点的管理及操作的结构 - */ -typedef struct simple_tree_node{ - void *value;//值指针 - struct simple_tree_node *childs[2];//子节点 -}s_TNode; - -/* - *树的管理及操作的结构 - */ -typedef struct tree -{ - SID *s_id;//超级树的SID - TNode *root;//超级树根节点 - s_TNode *s_root;//二叉树的根节点 -}Tree; - -/* - *文件头信息的管理及操作的结构 - */ -typedef struct file_head{ - char head_test[18];//数据文件头部的验证信息 - unsigned long long data_num;//数据文件中的标准数据结构的数目 -}F_HEAD; - -/* - *数据文件的管理及操作的结构 - */ -typedef struct data_file{ - FILE *fp;//数据文件 - F_HEAD *pf_head;//数据文件头 - List *pf_stdlst;//数据文件的标志数据结构的储存链表 -}D_FILE; - -/* - *标准数据结构的管理及操作的结构 - */ -typedef struct standard_data_blocks{ - unsigned int type;//数据块的类型 - unsigned long long location;//数据块在数据文件中的定位 - char *sid;//数据块的ID - _Bool if_data;//数据块是否赋值 - unsigned int blocks_num;//数据块字节大小 - char *buff;//指向数据块储存值内存空间的指针 -}STD_BLOCKS; - -/* - *标准数据结构中数据块的连接关系的管理及操作的结构 - */ -typedef struct standard_data_connection{ - unsigned long long location;//数据块链接关系结构在文件中的定位 - char *f_sid;//前一个数据块的ID - char *s_sid;//后一个数据块的ID -}STD_CTN; - -/* - *标准数据结构头的管理及操作的结构 - */ -typedef struct standard_data_head{ - unsigned long long data_blk_num;//数据块的数目 - unsigned long long data_ctn_num;//数据块链接关系结构的数目 -}STD_HEAD; - -/* - *标准数据结构的管理及操作的结构 - */ -typedef struct standard_data{ - SID *s_id;//标准数据结构的ID - int read_data;//标准数据结构是否已经读取完整 - unsigned int type;//标准数据结构所对应的类型 - unsigned long long size;//标准数据结构在数据文件中的大小 - unsigned long long location;//标准数据结构的头在数据文件中的定位 - _Bool lock;//标准数据文件是否被锁住 - List *pd_blocklst;//数据块储存链表 - List *pd_ctnlst;//数据块连接关系结构的储存链表 -}STD_DATA; - -/* - *消息的管理及操作的结构 - */ -typedef struct message{ - SID *p_sid;//消息的ID - time_t time;//消息的产生时间 - char titile[16];//消息标题 - unsigned long size;//消息的大小 - char content[0];//消息的正文 -}MSG; - -#endif /* type_h */ From 7115fbc06e9ca9ab07c478052f209d16953b46b5 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 21 Dec 2018 17:36:57 +0800 Subject: [PATCH 05/18] Change files and dirs --- .../project.pbxproj | 120 ++- .../xcdebugger/Breakpoints_v2.xcbkptlist | 634 ++++++------- .../xcschemes/xcschememanagement.plist | 5 + include/communicate/communicate.h | 24 +- include/list/list_type.h | 2 + include/type.h | 5 +- {list => src/list}/list_copy.c | 10 + {list => src/list}/list_expand_calculate.c | 6 + {list => src/list}/list_expand_callback.c | 0 {list => src/list}/list_expand_complex.c | 0 {list => src/list}/list_expand_find.c | 0 {list => src/list}/list_expand_get.c | 52 +- {list => src/list}/list_expand_node.c | 0 {list => src/list}/list_expand_update.c | 0 {list => src/list}/list_find.c | 0 {list => src/list}/list_info.c | 0 {list => src/list}/list_init.c | 0 {list => src/list}/list_insert.c | 0 {list => src/list}/list_print.c | 0 {list => src/list}/list_quick.c | 0 {list => src/list}/list_release.c | 0 {list => src/list}/list_remove.c | 0 {list => src/list}/list_replace.c | 0 {list => src/list}/list_simple.c | 0 {list => src/list}/list_simple_node.c | 0 {list => src/list}/list_sort.c | 0 {list => src/list}/safe_mode.c | 0 {stack => src/stack}/stack.c | 2 +- {stack => src/stack}/stack_expand.c | 102 +- {tree => src/tree}/tree.c | 892 +++++++++--------- {tree => src/tree}/tree_expand.c | 428 ++++----- {tree => src/tree}/tree_expand.h | 42 +- test.c => test/test.c | 120 +-- test.h => test/test.h | 22 +- 34 files changed, 1228 insertions(+), 1238 deletions(-) rename {list => src/list}/list_copy.c (83%) rename {list => src/list}/list_expand_calculate.c (63%) rename {list => src/list}/list_expand_callback.c (100%) rename {list => src/list}/list_expand_complex.c (100%) rename {list => src/list}/list_expand_find.c (100%) rename {list => src/list}/list_expand_get.c (95%) rename {list => src/list}/list_expand_node.c (100%) rename {list => src/list}/list_expand_update.c (100%) rename {list => src/list}/list_find.c (100%) rename {list => src/list}/list_info.c (100%) rename {list => src/list}/list_init.c (100%) rename {list => src/list}/list_insert.c (100%) rename {list => src/list}/list_print.c (100%) rename {list => src/list}/list_quick.c (100%) rename {list => src/list}/list_release.c (100%) rename {list => src/list}/list_remove.c (100%) rename {list => src/list}/list_replace.c (100%) rename {list => src/list}/list_simple.c (100%) rename {list => src/list}/list_simple_node.c (100%) rename {list => src/list}/list_sort.c (100%) rename {list => src/list}/safe_mode.c (100%) rename {stack => src/stack}/stack.c (99%) rename {stack => src/stack}/stack_expand.c (96%) rename {tree => src/tree}/tree.c (96%) rename {tree => src/tree}/tree_expand.c (96%) rename {tree => src/tree}/tree_expand.h (97%) rename test.c => test/test.c (92%) rename test.h => test/test.h (97%) diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj index d7447cc..5e6b815 100644 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ b/ZE-Standard-Libraries.xcodeproj/project.pbxproj @@ -7,15 +7,11 @@ objects = { /* Begin PBXBuildFile section */ - 9233C310212292B000FB2485 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 9233C30F212292B000FB2485 /* md5.c */; }; 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E7210F1B3D00161557 /* stack_expand.c */; }; 9269D4EA210F1B4B00161557 /* list_expand_get.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E9210F1B4B00161557 /* list_expand_get.c */; }; 9269D4ED210F1B5E00161557 /* test.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4EB210F1B5E00161557 /* test.c */; }; - 9269D4F4210F1BB000161557 /* id.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4F2210F1BB000161557 /* id.c */; }; 9269D4F5210F1BCE00161557 /* list_info.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246994F20CD000300B4E894 /* list_info.c */; }; 9269D4F6210F1CD900161557 /* stack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246995920CE52A700B4E894 /* stack.c */; }; - 9286EB7A211400C900752977 /* error_file.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB79211400C900752977 /* error_file.c */; }; - 9286EB7E2114022A00752977 /* communicate.c in Sources */ = {isa = PBXBuildFile; fileRef = 9286EB7D2114022A00752977 /* communicate.c */; }; 92CC992E212EF3E50060EFA5 /* list_quick.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC992D212EF3E50060EFA5 /* list_quick.c */; }; 92CC9931212EF4BF0060EFA5 /* list_sort.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9930212EF4BF0060EFA5 /* list_sort.c */; }; 92CC9934212EF5330060EFA5 /* safe_mode.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9933212EF5330060EFA5 /* safe_mode.c */; }; @@ -35,7 +31,11 @@ 92CC995D212F048B0060EFA5 /* list_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995C212F048B0060EFA5 /* list_copy.c */; }; 92CC995F212F04EE0060EFA5 /* list_insert.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995E212F04EE0060EFA5 /* list_insert.c */; }; 92CC9961212F05330060EFA5 /* list_replace.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9960212F05330060EFA5 /* list_replace.c */; }; - 92CC9969212F1DEB0060EFA5 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9968212F1DEB0060EFA5 /* error.c */; }; + 92DE530A21CCEA430057ADCB /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530821CCEA430057ADCB /* md5.c */; }; + 92DE530B21CCEA430057ADCB /* id.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530921CCEA430057ADCB /* id.c */; }; + 92DE530E21CCEA510057ADCB /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530C21CCEA510057ADCB /* error.c */; }; + 92DE530F21CCEA510057ADCB /* error_file.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530D21CCEA510057ADCB /* error_file.c */; }; + 92DE531121CCEA5B0057ADCB /* communicate.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE531021CCEA5B0057ADCB /* communicate.c */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -52,7 +52,6 @@ /* Begin PBXFileReference section */ 9233C30E212292B000FB2485 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; - 9233C30F212292B000FB2485 /* md5.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = md5.c; path = id/md5.c; sourceTree = ""; }; 9246994F20CD000300B4E894 /* list_info.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_info.c; sourceTree = ""; }; 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_expand.h; sourceTree = ""; }; 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list.h; sourceTree = ""; }; @@ -66,13 +65,10 @@ 9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = test.c; sourceTree = ""; }; 9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = test.h; sourceTree = ""; }; 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = type.h; sourceTree = ""; }; - 9269D4F2210F1BB000161557 /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = id/id.c; sourceTree = ""; }; 9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = id.h; sourceTree = ""; }; 9269D4F7210F1D0B00161557 /* tree_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree_expand.c; sourceTree = ""; }; 9269D4F9210F1D0F00161557 /* tree_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree_expand.h; sourceTree = ""; }; 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ZE-Standard-Libraries"; sourceTree = BUILT_PRODUCTS_DIR; }; - 9286EB79211400C900752977 /* error_file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error_file.c; path = error/error_file.c; sourceTree = ""; }; - 9286EB7D2114022A00752977 /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; name = communicate.c; path = communicate/communicate.c; sourceTree = ""; }; 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = communicate.h; sourceTree = ""; }; 92CC992D212EF3E50060EFA5 /* list_quick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_quick.c; sourceTree = ""; }; 92CC992F212EF4340060EFA5 /* list_quick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_quick.h; sourceTree = ""; }; @@ -102,7 +98,11 @@ 92CC9960212F05330060EFA5 /* list_replace.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_replace.c; sourceTree = ""; }; 92CC9966212F11920060EFA5 /* stack_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_type.h; sourceTree = ""; }; 92CC9967212F17C70060EFA5 /* error_file.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = error_file.h; sourceTree = ""; }; - 92CC9968212F1DEB0060EFA5 /* error.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = error.c; path = error/error.c; sourceTree = ""; }; + 92DE530821CCEA430057ADCB /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = md5.c; path = src/id/md5.c; sourceTree = ""; }; + 92DE530921CCEA430057ADCB /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = src/id/id.c; sourceTree = ""; }; + 92DE530C21CCEA510057ADCB /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = src/error/error.c; sourceTree = ""; }; + 92DE530D21CCEA510057ADCB /* error_file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error_file.c; path = src/error/error_file.c; sourceTree = ""; }; + 92DE531021CCEA5B0057ADCB /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = communicate.c; path = src/communicate/communicate.c; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -119,27 +119,27 @@ 9246994E20CD000300B4E894 /* list */ = { isa = PBXGroup; children = ( - 9246994F20CD000300B4E894 /* list_info.c */, - 9269D4E9210F1B4B00161557 /* list_expand_get.c */, - 92CC992D212EF3E50060EFA5 /* list_quick.c */, - 92CC9930212EF4BF0060EFA5 /* list_sort.c */, - 92CC9933212EF5330060EFA5 /* safe_mode.c */, - 92CC9936212EF60A0060EFA5 /* list_print.c */, - 92CC9939212EF62A0060EFA5 /* list_simple.c */, - 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */, + 92CC995C212F048B0060EFA5 /* list_copy.c */, + 92CC9951212F02200060EFA5 /* list_expand_calculate.c */, 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */, 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */, + 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */, + 9269D4E9210F1B4B00161557 /* list_expand_get.c */, 92CC994B212F00030060EFA5 /* list_expand_node.c */, 92CC994D212F003F0060EFA5 /* list_expand_update.c */, - 92CC994F212F014A0060EFA5 /* list_simple_node.c */, - 92CC9951212F02200060EFA5 /* list_expand_calculate.c */, 92CC9953212F03190060EFA5 /* list_find.c */, + 9246994F20CD000300B4E894 /* list_info.c */, 92CC9955212F037F0060EFA5 /* list_init.c */, + 92CC995E212F04EE0060EFA5 /* list_insert.c */, + 92CC9936212EF60A0060EFA5 /* list_print.c */, + 92CC992D212EF3E50060EFA5 /* list_quick.c */, 92CC9958212F03CB0060EFA5 /* list_release.c */, 92CC995A212F042E0060EFA5 /* list_remove.c */, - 92CC995C212F048B0060EFA5 /* list_copy.c */, - 92CC995E212F04EE0060EFA5 /* list_insert.c */, 92CC9960212F05330060EFA5 /* list_replace.c */, + 92CC994F212F014A0060EFA5 /* list_simple_node.c */, + 92CC9939212EF62A0060EFA5 /* list_simple.c */, + 92CC9930212EF4BF0060EFA5 /* list_sort.c */, + 92CC9933212EF5330060EFA5 /* safe_mode.c */, ); path = list; sourceTree = ""; @@ -166,25 +166,21 @@ 9269D4F1210F1B9E00161557 /* id */ = { isa = PBXGroup; children = ( - 9269D4F2210F1BB000161557 /* id.c */, - 9233C30F212292B000FB2485 /* md5.c */, + 92DE530921CCEA430057ADCB /* id.c */, + 92DE530821CCEA430057ADCB /* md5.c */, ); name = id; + path = ..; sourceTree = ""; }; 927993B420CB87D6008CE3A9 = { isa = PBXGroup; children = ( + 92DE530721CCE96D0057ADCB /* documents */, + 92DE530621CCE9280057ADCB /* bin */, + 92DE530521CCE91B0057ADCB /* test */, + 92DE530421CCE90B0057ADCB /* src */, 92CC993B212EF7400060EFA5 /* include */, - 92A15CFC211442C700826FB8 /* graph */, - 9286EB7C2114021E00752977 /* communicate */, - 9286EB78211400BD00752977 /* error */, - 9269D4F1210F1B9E00161557 /* id */, - 9246995C20CE654600B4E894 /* tree */, - 9246995720CE507900B4E894 /* stack */, - 9246994E20CD000300B4E894 /* list */, - 9269D4EB210F1B5E00161557 /* test.c */, - 9269D4EC210F1B5E00161557 /* test.h */, 927993BE20CB87D6008CE3A9 /* Products */, ); sourceTree = ""; @@ -200,18 +196,20 @@ 9286EB78211400BD00752977 /* error */ = { isa = PBXGroup; children = ( - 9286EB79211400C900752977 /* error_file.c */, - 92CC9968212F1DEB0060EFA5 /* error.c */, + 92DE530D21CCEA510057ADCB /* error_file.c */, + 92DE530C21CCEA510057ADCB /* error.c */, ); name = error; + path = ..; sourceTree = ""; }; 9286EB7C2114021E00752977 /* communicate */ = { isa = PBXGroup; children = ( - 9286EB7D2114022A00752977 /* communicate.c */, + 92DE531021CCEA5B0057ADCB /* communicate.c */, ); name = communicate; + path = ..; sourceTree = ""; }; 92A15CFC211442C700826FB8 /* graph */ = { @@ -219,6 +217,7 @@ children = ( ); name = graph; + path = ..; sourceTree = ""; }; 92CC993B212EF7400060EFA5 /* include */ = { @@ -294,6 +293,43 @@ path = communicate; sourceTree = ""; }; + 92DE530421CCE90B0057ADCB /* src */ = { + isa = PBXGroup; + children = ( + 92A15CFC211442C700826FB8 /* graph */, + 9286EB7C2114021E00752977 /* communicate */, + 9286EB78211400BD00752977 /* error */, + 9269D4F1210F1B9E00161557 /* id */, + 9246995C20CE654600B4E894 /* tree */, + 9246995720CE507900B4E894 /* stack */, + 9246994E20CD000300B4E894 /* list */, + ); + path = src; + sourceTree = ""; + }; + 92DE530521CCE91B0057ADCB /* test */ = { + isa = PBXGroup; + children = ( + 9269D4EB210F1B5E00161557 /* test.c */, + 9269D4EC210F1B5E00161557 /* test.h */, + ); + path = test; + sourceTree = ""; + }; + 92DE530621CCE9280057ADCB /* bin */ = { + isa = PBXGroup; + children = ( + ); + path = bin; + sourceTree = ""; + }; + 92DE530721CCE96D0057ADCB /* documents */ = { + isa = PBXGroup; + children = ( + ); + path = documents; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -350,32 +386,32 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 92DE530A21CCEA430057ADCB /* md5.c in Sources */, 92CC9931212EF4BF0060EFA5 /* list_sort.c in Sources */, - 9233C310212292B000FB2485 /* md5.c in Sources */, 92CC9961212F05330060EFA5 /* list_replace.c in Sources */, 9269D4F6210F1CD900161557 /* stack.c in Sources */, 92CC9959212F03CB0060EFA5 /* list_release.c in Sources */, 92CC993A212EF62A0060EFA5 /* list_simple.c in Sources */, - 9286EB7A211400C900752977 /* error_file.c in Sources */, 92CC992E212EF3E50060EFA5 /* list_quick.c in Sources */, 92CC9943212EFE7E0060EFA5 /* list_expand_find.c in Sources */, 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */, + 92DE530F21CCEA510057ADCB /* error_file.c in Sources */, 92CC9937212EF60A0060EFA5 /* list_print.c in Sources */, + 92DE530E21CCEA510057ADCB /* error.c in Sources */, 92CC994C212F00030060EFA5 /* list_expand_node.c in Sources */, + 92DE531121CCEA5B0057ADCB /* communicate.c in Sources */, 92CC9956212F037F0060EFA5 /* list_init.c in Sources */, 92CC9954212F03190060EFA5 /* list_find.c in Sources */, 92CC9949212EFF6F0060EFA5 /* list_expand_complex.c in Sources */, 92CC995D212F048B0060EFA5 /* list_copy.c in Sources */, - 9286EB7E2114022A00752977 /* communicate.c in Sources */, + 92DE530B21CCEA430057ADCB /* id.c in Sources */, 9269D4EA210F1B4B00161557 /* list_expand_get.c in Sources */, - 9269D4F4210F1BB000161557 /* id.c in Sources */, 9269D4ED210F1B5E00161557 /* test.c in Sources */, 9269D4F5210F1BCE00161557 /* list_info.c in Sources */, 92CC9952212F02200060EFA5 /* list_expand_calculate.c in Sources */, 92CC9946212EFEF70060EFA5 /* list_expand_callback.c in Sources */, 92CC9950212F014A0060EFA5 /* list_simple_node.c in Sources */, 92CC9934212EF5330060EFA5 /* safe_mode.c in Sources */, - 92CC9969212F1DEB0060EFA5 /* error.c in Sources */, 92CC995B212F042E0060EFA5 /* list_remove.c in Sources */, 92CC994E212F003F0060EFA5 /* list_expand_update.c in Sources */, 92CC995F212F04EE0060EFA5 /* list_insert.c in Sources */, @@ -500,6 +536,7 @@ CODE_SIGN_STYLE = Automatic; COPY_HEADERS_RUN_UNIFDEF = NO; HEADER_SEARCH_PATHS = "\"$(SRCROOT)/include\"/**"; + LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/bin\"/**"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -510,6 +547,7 @@ CODE_SIGN_STYLE = Automatic; COPY_HEADERS_RUN_UNIFDEF = NO; HEADER_SEARCH_PATHS = "\"$(SRCROOT)/include\"/**"; + LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/bin\"/**"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 7d471f5..b6f7cc9 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -147,22 +147,6 @@ landmarkType = "9"> - - - - @@ -557,11 +541,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.101581" + timestampString = "566967242.118185" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "165" - endingLineNumber = "165" + startingLineNumber = "166" + endingLineNumber = "166" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -573,11 +557,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.1016541" + timestampString = "566967242.1185679" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "281" - endingLineNumber = "281" + startingLineNumber = "282" + endingLineNumber = "282" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -589,13 +573,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.101725" + timestampString = "566967242.118932" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "273" - endingLineNumber = "273" - landmarkName = "releaseDFile" - landmarkType = "9"> + startingLineNumber = "274" + endingLineNumber = "274" + landmarkName = "unknown" + landmarkType = "0"> @@ -621,11 +605,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.101868" + timestampString = "566967242.1196409" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "96" - endingLineNumber = "96" + startingLineNumber = "97" + endingLineNumber = "97" landmarkName = "initStandardData" landmarkType = "9"> @@ -637,11 +621,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.101934" + timestampString = "566967242.119988" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "167" - endingLineNumber = "167" + startingLineNumber = "168" + endingLineNumber = "168" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -669,11 +653,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.102102" + timestampString = "566967242.120361" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "65" - endingLineNumber = "65" + startingLineNumber = "66" + endingLineNumber = "66" landmarkName = "initStandardDBlocks" landmarkType = "9"> @@ -685,11 +669,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.10221" + timestampString = "566967242.1207041" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "104" - endingLineNumber = "104" + startingLineNumber = "105" + endingLineNumber = "105" landmarkName = "initStandardData" landmarkType = "9"> @@ -701,11 +685,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.102289" + timestampString = "566967242.121045" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "208" - endingLineNumber = "208" + startingLineNumber = "209" + endingLineNumber = "209" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -717,11 +701,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.102362" + timestampString = "566967242.121385" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "189" - endingLineNumber = "189" + startingLineNumber = "190" + endingLineNumber = "190" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -733,13 +717,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.102428" + timestampString = "566967242.121727" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "191" - endingLineNumber = "191" - landmarkName = "unknown" - landmarkType = "0"> + startingLineNumber = "192" + endingLineNumber = "192" + landmarkName = "__CALLBACK_DEFINE" + landmarkType = "9"> - - - - - - - - + + + + + + + + + startingLineNumber = "111" + endingLineNumber = "111"> - - - - @@ -905,11 +873,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.103106" + timestampString = "566967242.123542" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "367" - endingLineNumber = "367" + startingLineNumber = "356" + endingLineNumber = "356" landmarkName = "unknown" landmarkType = "0"> @@ -921,11 +889,27 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.1031719" + timestampString = "566967242.123886" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "377" - endingLineNumber = "377" + startingLineNumber = "368" + endingLineNumber = "368" + landmarkName = "unknown" + landmarkType = "0"> + + + + @@ -937,11 +921,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.103237" + timestampString = "566967242.1245739" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "359" - endingLineNumber = "359" + startingLineNumber = "360" + endingLineNumber = "360" landmarkName = "unknown" landmarkType = "0"> @@ -953,11 +937,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.103299" + timestampString = "566967242.125172" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "386" - endingLineNumber = "386" + startingLineNumber = "387" + endingLineNumber = "387" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -985,27 +969,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.103398" + timestampString = "566967242.125859" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "159" - endingLineNumber = "159" - landmarkName = "dataFileWriteIn" - landmarkType = "9"> - - - - @@ -1017,71 +985,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.10353" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "371" - endingLineNumber = "371" - landmarkName = "unknown" - landmarkType = "0"> - - - - - - - - - - - - - - - - @@ -1113,11 +1017,91 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.103917" + timestampString = "566967242.127499" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "381" - endingLineNumber = "381" + startingLineNumber = "370" + endingLineNumber = "370" + landmarkName = "unknown" + landmarkType = "0"> + + + + + + + + + + + + + + + + + + + + @@ -1145,11 +1129,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.1040421" + timestampString = "566967242.13007" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "416" - endingLineNumber = "416" + startingLineNumber = "417" + endingLineNumber = "417" landmarkName = "readStandardData" landmarkType = "9"> @@ -1161,11 +1145,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104105" + timestampString = "566967242.130564" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "385" - endingLineNumber = "385" + startingLineNumber = "386" + endingLineNumber = "386" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1177,11 +1161,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.1041681" + timestampString = "566967242.131088" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "138" - endingLineNumber = "138" + startingLineNumber = "139" + endingLineNumber = "139" landmarkName = "initDataFileForRead" landmarkType = "9"> @@ -1193,11 +1177,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.10423" + timestampString = "566967242.131614" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "391" - endingLineNumber = "391" + startingLineNumber = "392" + endingLineNumber = "392" landmarkName = "readDataFileInfo" landmarkType = "9"> @@ -1209,23 +1193,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104292" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "145" - endingLineNumber = "145" - landmarkName = "dataFileAddStandardData" - landmarkType = "9"> - - - - + + + + @@ -1287,11 +1271,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104582" + timestampString = "566967242.134397" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "460" - endingLineNumber = "460" + startingLineNumber = "461" + endingLineNumber = "461" landmarkName = "printStandardData" landmarkType = "9"> @@ -1303,11 +1287,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104646" + timestampString = "566967242.134836" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "406" - endingLineNumber = "406" + startingLineNumber = "407" + endingLineNumber = "407" landmarkName = "readStandardData" landmarkType = "9"> @@ -1319,11 +1303,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.10471" + timestampString = "566967242.135197" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "412" - endingLineNumber = "412" + startingLineNumber = "413" + endingLineNumber = "413" landmarkName = "readStandardData" landmarkType = "9"> @@ -1335,11 +1319,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104777" + timestampString = "566967242.1355489" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "287" - endingLineNumber = "287" + startingLineNumber = "288" + endingLineNumber = "288" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1351,11 +1335,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104844" + timestampString = "566967242.135901" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "277" - endingLineNumber = "277" + startingLineNumber = "278" + endingLineNumber = "278" landmarkName = "standardDataToList" landmarkType = "9"> @@ -1367,7 +1351,23 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.104982" + timestampString = "566967242.136245" + startingColumnNumber = "9223372036854775807" + endingColumnNumber = "9223372036854775807" + startingLineNumber = "428" + endingLineNumber = "428" + landmarkName = "readStandardData" + landmarkType = "9"> + + + + - - - - @@ -1415,11 +1399,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.105185" + timestampString = "566967242.137645" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "442" - endingLineNumber = "442" + startingLineNumber = "443" + endingLineNumber = "443" landmarkName = "readStandardData" landmarkType = "9"> @@ -1431,11 +1415,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.105251" + timestampString = "566967242.138097" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "285" - endingLineNumber = "285" + startingLineNumber = "286" + endingLineNumber = "286" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> @@ -1479,31 +1463,15 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "communicate/communicate.c" - timestampString = "556736003.10543" + timestampString = "566967242.138545" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "328" - endingLineNumber = "328" + startingLineNumber = "329" + endingLineNumber = "329" landmarkName = "__CALLBACK_DEFINE" landmarkType = "9"> - - - - - - - - - - - - - - - - diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist index 2045221..c2e0451 100644 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,6 +9,11 @@ orderHint 0 + ZE-Standard-Libraries.xcscheme_^#shared#^_ + + orderHint + 0 + diff --git a/include/communicate/communicate.h b/include/communicate/communicate.h index 33cbdd8..4136b86 100644 --- a/include/communicate/communicate.h +++ b/include/communicate/communicate.h @@ -6,7 +6,7 @@ */ typedef struct file_head{ char head_test[18];//数据文件头部的验证信息 - unsigned long long data_num;//数据文件中的标准数据结构的数目 + uint32_t data_num;//数据文件中的标准数据结构的数目 }F_HEAD; /* @@ -22,8 +22,8 @@ typedef struct data_file{ *标准数据结构的管理及操作的结构 */ typedef struct standard_data_blocks{ - unsigned int type;//数据块的类型 - unsigned long long location;//数据块在数据文件中的定位 + uint16_t type;//数据块的类型 + uint32_t location;//数据块在数据文件中的定位 char *sid;//数据块的ID _Bool if_data;//数据块是否赋值 unsigned int blocks_num;//数据块字节大小 @@ -34,7 +34,7 @@ typedef struct standard_data_blocks{ *标准数据结构中数据块的连接关系的管理及操作的结构 */ typedef struct standard_data_connection{ - unsigned long long location;//数据块链接关系结构在文件中的定位 + uint32_t location;//数据块链接关系结构在文件中的定位 char *f_sid;//前一个数据块的ID char *s_sid;//后一个数据块的ID }STD_CTN; @@ -43,8 +43,8 @@ typedef struct standard_data_connection{ *标准数据结构头的管理及操作的结构 */ typedef struct standard_data_head{ - unsigned long long data_blk_num;//数据块的数目 - unsigned long long data_ctn_num;//数据块链接关系结构的数目 + uint32_t data_blk_num;//数据块的数目 + uint32_t data_ctn_num;//数据块链接关系结构的数目 }STD_HEAD; /* @@ -53,9 +53,9 @@ typedef struct standard_data_head{ typedef struct standard_data{ SID *s_id;//标准数据结构的ID int read_data;//标准数据结构是否已经读取完整 - unsigned int type;//标准数据结构所对应的类型 - unsigned long long size;//标准数据结构在数据文件中的大小 - unsigned long long location;//标准数据结构的头在数据文件中的定位 + uint16_t type;//标准数据结构所对应的类型 + uint32_t size;//标准数据结构在数据文件中的大小 + uint32_t location;//标准数据结构的头在数据文件中的定位 _Bool lock;//标准数据文件是否被锁住 List *pd_blocklst;//数据块储存链表 List *pd_ctnlst;//数据块连接关系结构的储存链表 @@ -98,7 +98,7 @@ extern D_FILE *initDataFileForRead(char *route); *参数: type指示数据块储存数据的数据类型,data_size指示数据块储存数据的大小 *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. */ -extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size); +extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size); /* *初始化数据块链接关系管理结构 @@ -113,7 +113,7 @@ extern STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid); 若s_id为NULL,则另外分配一个ID.为了方便管理,标准数据结构必须有ID. *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. */ -extern STD_DATA *initStandardData(unsigned int type, SID *s_id); +extern STD_DATA *initStandardData(uint16_t type, SID *s_id); @@ -141,7 +141,7 @@ extern int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); *参数: type指示所添加数据的数据类型, data为指向所添加数据所在内存空间的指针, data_size指示所添加数据的大小 *返回: 处理成功则返回0,不成功则返回-1. */ -extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *data, unsigned long long data_size); +extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size); /* *为标准数据结构添加数据块链接关系结构体 diff --git a/include/list/list_type.h b/include/list/list_type.h index 94a9881..b0a8786 100644 --- a/include/list/list_type.h +++ b/include/list/list_type.h @@ -9,7 +9,9 @@ *节点的管理及操作的结构 */ typedef struct Node{ +#ifdef list_quick_enable unsigned long long f_number;//长链表模式下,分派的数组节点编号 +#endif unsigned int type;//类型 void *value;//值指针 struct Node *next;//指向下一个节点 diff --git a/include/type.h b/include/type.h index 55c48eb..da588d2 100644 --- a/include/type.h +++ b/include/type.h @@ -11,13 +11,14 @@ #include #include #include +#include -/* +#ifdef UNIX #include #include #include #include -*/ +#endif diff --git a/list/list_copy.c b/src/list/list_copy.c similarity index 83% rename from list/list_copy.c rename to src/list/list_copy.c index 73edce2..99f64f8 100644 --- a/list/list_copy.c +++ b/src/list/list_copy.c @@ -1,8 +1,16 @@ #include #include + +/** + 以一个已存在的节点为模板创建一个新的节点 + + @param p_node 指向作为模板的节点的指针 + @return 返回指向新的节点的指针 + */ Node *copyNode(Node *p_node) { Node *t_node = NULL; +//当开启ID模块的时候编译 #ifdef id_enable if (p_node->s_id == NULL) t_node = initNode(0); else t_node = initNode(p_node->s_id->deep); @@ -12,7 +20,9 @@ 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; } diff --git a/list/list_expand_calculate.c b/src/list/list_expand_calculate.c similarity index 63% rename from list/list_expand_calculate.c rename to src/list/list_expand_calculate.c index ebfc7bf..b685233 100644 --- a/list/list_expand_calculate.c +++ b/src/list/list_expand_calculate.c @@ -1,6 +1,12 @@ #include #include +/** + 计算链表占用的内存空间大小,以字节为单位输出。 + + @param p_list 指向目标链表的指针 + @return 以字节为单位返回链表及链表内包含的节点所占的内存空间 + */ unsigned long long calListMemory(List * p_list){ Node *p_node = p_list->head; unsigned long long nodes_size = 0LL; diff --git a/list/list_expand_callback.c b/src/list/list_expand_callback.c similarity index 100% rename from list/list_expand_callback.c rename to src/list/list_expand_callback.c diff --git a/list/list_expand_complex.c b/src/list/list_expand_complex.c similarity index 100% rename from list/list_expand_complex.c rename to src/list/list_expand_complex.c diff --git a/list/list_expand_find.c b/src/list/list_expand_find.c similarity index 100% rename from list/list_expand_find.c rename to src/list/list_expand_find.c diff --git a/list/list_expand_get.c b/src/list/list_expand_get.c similarity index 95% rename from list/list_expand_get.c rename to src/list/list_expand_get.c index 767d3ef..dbb9347 100644 --- a/list/list_expand_get.c +++ b/src/list/list_expand_get.c @@ -1,24 +1,26 @@ #include #include #include + #ifdef list_quick_enable #include -#endif - -char *getByStringForNode(Node *p_node) { - if (p_node->type == STRING) return (char *)(p_node->value); - else return NULL; -} - -double getByDoubleForNode(Node *p_node) { - if (p_node->type == DOUBLE) return *(double *)(p_node->value); - else return -1; -} - -void *getByPointerForNode(Node *p_node) { - return (void *)(p_node->value); -} - +#endif + +/*直接获得节点中储存的字符串值*/ +char *getByStringForNode(Node *p_node) { + if (p_node->type == STRING) return (char *)(p_node->value); + else return NULL; +} + +double getByDoubleForNode(Node *p_node) { + if (p_node->type == DOUBLE) return *(double *)(p_node->value); + else return -1; +} + +void *getByPointerForNode(Node *p_node) { + return (void *)(p_node->value); +} + unsigned long long getIndexByNode(List *p_list, Node *p_node) { #ifdef list_quick_enable if (p_list->p_lq != NULL){ @@ -26,15 +28,15 @@ unsigned long long getIndexByNode(List *p_list, Node *p_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; - register unsigned long long index = 0; +#endif + register Node *t_node = p_list->head; + register unsigned long long index = 0; while (t_node != NULL) { -#ifdef id_enable +#ifdef id_enable if (p_node->s_id == t_node->s_id) return index; -#endif - index++; - t_node = t_node->next; - } - return 0; +#endif + index++; + t_node = t_node->next; + } + return 0; } diff --git a/list/list_expand_node.c b/src/list/list_expand_node.c similarity index 100% rename from list/list_expand_node.c rename to src/list/list_expand_node.c diff --git a/list/list_expand_update.c b/src/list/list_expand_update.c similarity index 100% rename from list/list_expand_update.c rename to src/list/list_expand_update.c diff --git a/list/list_find.c b/src/list/list_find.c similarity index 100% rename from list/list_find.c rename to src/list/list_find.c diff --git a/list/list_info.c b/src/list/list_info.c similarity index 100% rename from list/list_info.c rename to src/list/list_info.c diff --git a/list/list_init.c b/src/list/list_init.c similarity index 100% rename from list/list_init.c rename to src/list/list_init.c diff --git a/list/list_insert.c b/src/list/list_insert.c similarity index 100% rename from list/list_insert.c rename to src/list/list_insert.c diff --git a/list/list_print.c b/src/list/list_print.c similarity index 100% rename from list/list_print.c rename to src/list/list_print.c diff --git a/list/list_quick.c b/src/list/list_quick.c similarity index 100% rename from list/list_quick.c rename to src/list/list_quick.c diff --git a/list/list_release.c b/src/list/list_release.c similarity index 100% rename from list/list_release.c rename to src/list/list_release.c diff --git a/list/list_remove.c b/src/list/list_remove.c similarity index 100% rename from list/list_remove.c rename to src/list/list_remove.c diff --git a/list/list_replace.c b/src/list/list_replace.c similarity index 100% rename from list/list_replace.c rename to src/list/list_replace.c diff --git a/list/list_simple.c b/src/list/list_simple.c similarity index 100% rename from list/list_simple.c rename to src/list/list_simple.c diff --git a/list/list_simple_node.c b/src/list/list_simple_node.c similarity index 100% rename from list/list_simple_node.c rename to src/list/list_simple_node.c diff --git a/list/list_sort.c b/src/list/list_sort.c similarity index 100% rename from list/list_sort.c rename to src/list/list_sort.c diff --git a/list/safe_mode.c b/src/list/safe_mode.c similarity index 100% rename from list/safe_mode.c rename to src/list/safe_mode.c diff --git a/stack/stack.c b/src/stack/stack.c similarity index 99% rename from stack/stack.c rename to src/stack/stack.c index 1f760e6..ad66956 100644 --- a/stack/stack.c +++ b/src/stack/stack.c @@ -71,4 +71,4 @@ int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value) { p_snode->type = type; p_snode->value = value; return 0; -} +} diff --git a/stack/stack_expand.c b/src/stack/stack_expand.c similarity index 96% rename from stack/stack_expand.c rename to src/stack/stack_expand.c index e4079eb..39287fd 100644 --- a/stack/stack_expand.c +++ b/src/stack/stack_expand.c @@ -1,62 +1,62 @@ #include #include -#include - -SNode *snodeWithInt(int temp) { - SNode *p_snode = initSNode(); +#include + +SNode *snodeWithInt(int temp) { + SNode *p_snode = initSNode(); int *p_temp = (int *)malloc(sizeof(int)); if(p_temp == NULL){ return NULL; - } - *p_temp = temp; - initMallocValueForSNode(p_snode, INT, p_temp); - return p_snode; -} - -SNode *snodeWithDouble(double temp) { - SNode *p_snode = initSNode(); + } + *p_temp = temp; + initMallocValueForSNode(p_snode, INT, p_temp); + return p_snode; +} + +SNode *snodeWithDouble(double temp) { + SNode *p_snode = initSNode(); double *p_temp = (double *)malloc(sizeof(double)); if(p_temp == NULL){ return NULL; - } - *p_temp = temp; - initMallocValueForSNode(p_snode, DOUBLE, p_temp); - return p_snode; -} - -SNode *snodeWithString(char *temp) { - SNode *p_snode = initSNode(); + } + *p_temp = temp; + initMallocValueForSNode(p_snode, DOUBLE, p_temp); + return p_snode; +} + +SNode *snodeWithString(char *temp) { + SNode *p_snode = initSNode(); char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); if(p_temp == NULL){ return NULL; - } - strcpy(p_temp, temp); - initMallocValueForSNode(p_snode, STRING, p_temp); - return p_snode; -} - -SNode *snodeWithPointer(void *temp) { - SNode *p_snode = initSNode(); - initMallocValueForSNode(p_snode, POINTER, temp); - return p_snode; -} - -int getValueByIntForSNode(SNode *p_snode) { - if (p_snode->type == INT) return *(int *)p_snode->value; - else return -1; -} - -double getValueByDoubleForSNode(SNode *p_snode) { - if (p_snode->type == DOUBLE) return *(double *)p_snode->value; - else return -1; -} - -char *getValueByStringForSNode(SNode *p_snode) { - if (p_snode->type == STRING) return (char *)p_snode->value; - else return NULL; -} - -void *getValueByPointerForSNode(SNode *p_snode) { - if (p_snode->type == POINTER) return (void *)p_snode->value; - else return NULL; -} + } + strcpy(p_temp, temp); + initMallocValueForSNode(p_snode, STRING, p_temp); + return p_snode; +} + +SNode *snodeWithPointer(void *temp) { + SNode *p_snode = initSNode(); + initMallocValueForSNode(p_snode, POINTER, temp); + return p_snode; +} + +int getValueByIntForSNode(SNode *p_snode) { + if (p_snode->type == INT) return *(int *)p_snode->value; + else return -1; +} + +double getValueByDoubleForSNode(SNode *p_snode) { + if (p_snode->type == DOUBLE) return *(double *)p_snode->value; + else return -1; +} + +char *getValueByStringForSNode(SNode *p_snode) { + if (p_snode->type == STRING) return (char *)p_snode->value; + else return NULL; +} + +void *getValueByPointerForSNode(SNode *p_snode) { + if (p_snode->type == POINTER) return (void *)p_snode->value; + else return NULL; +} diff --git a/tree/tree.c b/src/tree/tree.c similarity index 96% rename from tree/tree.c rename to src/tree/tree.c index 87794fa..87e5e51 100644 --- a/tree/tree.c +++ b/src/tree/tree.c @@ -1,497 +1,497 @@ -#include"tree.h" - -static int if_safeModeForTree = 0; - -int safeModeForTree(int ifon) { - if (ifon == 1) { - if (tnode_list == NULL && tree_list == NULL) { +#include"tree.h" + +static int if_safeModeForTree = 0; + +int safeModeForTree(int ifon) { + if (ifon == 1) { + if (tnode_list == NULL && tree_list == NULL) { tnode_list = (List *)malloc(sizeof(List)); if(tnode_list == NULL){ showError(pushError(TREE_NODE, HIGH, initInfo("safeModeForTree()", "Error in get the memory of tnode_list."))); return -1; - } - tree_list = (List *)malloc(sizeof(List)); + } + tree_list = (List *)malloc(sizeof(List)); if(tree_list == NULL){ showError(pushError(TREE_NODE, HIGH, initInfo("safeModeForTree()", "Error in get the memory of tree_list."))); return -1; - } - tree_list->head = NULL; - tree_list->length = 0; - tree_list->tail = NULL; - - tnode_list->head = NULL; - tnode_list->length = 0; - tnode_list->tail = NULL; - - if_safeModeForTree = 1; - } - else { - return -1; - } - } - - return ifon; -} - -TNode *initTNode(void) { - Node *s_node; + } + tree_list->head = NULL; + tree_list->length = 0; + tree_list->tail = NULL; + + tnode_list->head = NULL; + tnode_list->length = 0; + tnode_list->tail = NULL; + + if_safeModeForTree = 1; + } + else { + return -1; + } + } + + return ifon; +} + +TNode *initTNode(void) { + Node *s_node; TNode *p_tnode = (TNode *)malloc(sizeof(TNode)); if(p_tnode == NULL){ showError(pushError(TREE_NODE, STANDARD, initInfo("initTNode()", "Error in getting the memory of tnode."))); return NULL; } p_tnode->s_id = getS_id(TREE_NODE, 1); - p_tnode->if_sid = 1; - p_tnode->child_num = 0; - p_tnode->father = NULL; - p_tnode->if_malloc = 0; - p_tnode->value = NULL; - p_tnode->type = VOID; - p_tnode->home = initList(); - p_tnode->room = NULL; - if (if_safeModeForTree) { - if (if_safeModeForNode) { - if_safeModeForNode = 0; - s_node = initNode(); - initMallocValueForNode(s_node, POINTER, (void *)p_tnode); - insertInTail(tnode_list, s_node); - if_safeModeForNode = 1; - } - else - { - s_node = initNode(); - initMallocValueForNode(s_node, POINTER, (void *)p_tnode); - insertInTail(tnode_list, s_node); - } - } - return p_tnode; -} - -Tree *initTree(void) { - Node *s_node; + p_tnode->if_sid = 1; + p_tnode->child_num = 0; + p_tnode->father = NULL; + p_tnode->if_malloc = 0; + p_tnode->value = NULL; + p_tnode->type = VOID; + p_tnode->home = initList(); + p_tnode->room = NULL; + if (if_safeModeForTree) { + if (if_safeModeForNode) { + if_safeModeForNode = 0; + s_node = initNode(); + initMallocValueForNode(s_node, POINTER, (void *)p_tnode); + insertInTail(tnode_list, s_node); + if_safeModeForNode = 1; + } + else + { + s_node = initNode(); + initMallocValueForNode(s_node, POINTER, (void *)p_tnode); + insertInTail(tnode_list, s_node); + } + } + return p_tnode; +} + +Tree *initTree(void) { + Node *s_node; Tree *p_tree = (Tree *)malloc(sizeof(Tree)); if(p_tree == NULL){ showError(pushError(TREE, STANDARD, initInfo("initTree()", "Error in getting the memory of tree."))); return NULL; } p_tree->s_id = getS_id(TREE, 1); - p_tree->if_sid = 1; - p_tree->root = NULL; - if (if_safeModeForTree) { - if (if_safeModeForNode) { - if_safeModeForNode = 0; - s_node = initNode(); - initMallocValueForNode(s_node, POINTER, (void *)p_tree); - if_safeModeForNode = 1; - insertInTail(tree_list, s_node); - } - else - { - s_node = initNode(); - initMallocValueForNode(s_node, POINTER, (void *)p_tree); - insertInTail(tree_list, s_node); - } - } - return p_tree; -} - -int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value) { - p_tnode->type = type; - p_tnode->value = value; - p_tnode->if_malloc = 1; - return 0; -} - -int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { - Node *p_node = initNode(); - initMallocValueForNode(p_node, POINTER, c_tnode); - insertInHead(f_tnode->home, p_node); - c_tnode->father = f_tnode; - c_tnode->room = p_node; - f_tnode->child_num++; - return 0; -} - -int addChildInRight(TNode *f_tnode, TNode *c_tnode) { - Node *p_node = initNode(); - initMallocValueForNode(p_node, POINTER, c_tnode); - insertInTail(f_tnode->home, p_node); - c_tnode->father = f_tnode; - c_tnode->room = p_node; - f_tnode->child_num++; - return 0; -} - -TNode *getBrotherInLeft(TNode *p_tnode) { - List *p_home = p_tnode->father->home; - Node *p_node = p_tnode->room; - unsigned long long index = getIndexByNode(p_home, p_node); - if (index > 0) return (TNode *)(findByIndexForNode(p_home, index - 1)->value); - return NULL; -} - -TNode *getBrotherInRight(TNode *p_tnode) { - List *p_home = p_tnode->father->home; - Node *p_node = p_home->head; - unsigned long long index = getIndexByNode(p_home, p_node); - if (index < p_home->length - 1) return (TNode *)(findByIndexForNode(p_home, index + 1)->value); - return NULL; -} - -int removeChildInLeft(TNode *p_tnode) { - TNode *c_tnode = (TNode *)p_tnode->home->head->value; - c_tnode->father = NULL; - releaseOnlyNode(c_tnode->room); - c_tnode->room = NULL; - p_tnode->child_num--; - popFromHead(p_tnode->home); - return 0; -} - -int removeChildInRight(TNode *p_tnode) { - TNode *c_tnode = (TNode *)p_tnode->home->tail->value; - c_tnode->father = NULL; - releaseOnlyNode(c_tnode->room); - c_tnode->room = NULL; - p_tnode->child_num--; - popFromTail(p_tnode->home); - return 0; -} - - -TNode *getChildById(TNode *p_tnode, const SID *s_id) { - List *p_home = p_tnode->home; + p_tree->if_sid = 1; + p_tree->root = NULL; + if (if_safeModeForTree) { + if (if_safeModeForNode) { + if_safeModeForNode = 0; + s_node = initNode(); + initMallocValueForNode(s_node, POINTER, (void *)p_tree); + if_safeModeForNode = 1; + insertInTail(tree_list, s_node); + } + else + { + s_node = initNode(); + initMallocValueForNode(s_node, POINTER, (void *)p_tree); + insertInTail(tree_list, s_node); + } + } + return p_tree; +} + +int *initMallocValueForTNode(TNode *p_tnode, unsigned int type, void *value) { + p_tnode->type = type; + p_tnode->value = value; + p_tnode->if_malloc = 1; + return 0; +} + +int addChildInLeft(TNode *f_tnode, TNode *c_tnode) { + Node *p_node = initNode(); + initMallocValueForNode(p_node, POINTER, c_tnode); + insertInHead(f_tnode->home, p_node); + c_tnode->father = f_tnode; + c_tnode->room = p_node; + f_tnode->child_num++; + return 0; +} + +int addChildInRight(TNode *f_tnode, TNode *c_tnode) { + Node *p_node = initNode(); + initMallocValueForNode(p_node, POINTER, c_tnode); + insertInTail(f_tnode->home, p_node); + c_tnode->father = f_tnode; + c_tnode->room = p_node; + f_tnode->child_num++; + return 0; +} + +TNode *getBrotherInLeft(TNode *p_tnode) { + List *p_home = p_tnode->father->home; + Node *p_node = p_tnode->room; + unsigned long long index = getIndexByNode(p_home, p_node); + if (index > 0) return (TNode *)(findByIndexForNode(p_home, index - 1)->value); + return NULL; +} + +TNode *getBrotherInRight(TNode *p_tnode) { + List *p_home = p_tnode->father->home; + Node *p_node = p_home->head; + unsigned long long index = getIndexByNode(p_home, p_node); + if (index < p_home->length - 1) return (TNode *)(findByIndexForNode(p_home, index + 1)->value); + return NULL; +} + +int removeChildInLeft(TNode *p_tnode) { + TNode *c_tnode = (TNode *)p_tnode->home->head->value; + c_tnode->father = NULL; + releaseOnlyNode(c_tnode->room); + c_tnode->room = NULL; + p_tnode->child_num--; + popFromHead(p_tnode->home); + return 0; +} + +int removeChildInRight(TNode *p_tnode) { + TNode *c_tnode = (TNode *)p_tnode->home->tail->value; + c_tnode->father = NULL; + releaseOnlyNode(c_tnode->room); + c_tnode->room = NULL; + p_tnode->child_num--; + popFromTail(p_tnode->home); + return 0; +} + + +TNode *getChildById(TNode *p_tnode, const SID *s_id) { + List *p_home = p_tnode->home; target_value_sid = NULL; List *er_list = initList(); - insertInTail(er_list, nodeWithPointer(s_id)); + insertInTail(er_list, nodeWithPointer(s_id)); List *rtnc_list = listThrough(p_home, _dogetChildById, er_list); free(er_list); - Node *p_node= findByIndexForNode(rtnc_list, 1); + Node *p_node= findByIndexForNode(rtnc_list, 1); if (p_node != NULL) { TNode *p_tnode = getByPointerForNode(p_node); - free(rtnc_list); - return p_tnode; - } - return NULL; -} - + free(rtnc_list); + return p_tnode; + } + return NULL; +} + List *_dogetChildById(unsigned int type, void *value, List *er_list) { SID *target_sid = getByPointerForNode(findByIndexForNode(er_list, 0)); - List *rtn_list = initList(); - if (type == POINTER) { - TNode *p_tode = (TNode *)value; - if (simFitS_id(p_tode->s_id, target_sid)) { + List *rtn_list = initList(); + if (type == POINTER) { + TNode *p_tode = (TNode *)value; + if (simFitS_id(p_tode->s_id, target_sid)) { target_value_sid = p_tode; insertInTail(rtn_list, nodeWithInt(-1)); - insertInTail(rtn_list, nodeWithPointer(target_value_sid)); - return rtn_list; - } + insertInTail(rtn_list, nodeWithPointer(target_value_sid)); + return rtn_list; + } } - insertInTail(rtn_list, nodeWithInt(0)); - return rtn_list; -} - -TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value) { - List *p_home = p_tnode->home; - target_value = value; - target_type = type; + insertInTail(rtn_list, nodeWithInt(0)); + return rtn_list; +} + +TNode *getChildByValue(TNode *p_tnode, unsigned int type, void *value) { + List *p_home = p_tnode->home; + target_value = value; + target_type = type; target_value_value = NULL; List *er_list = initList(); insertInTail(er_list, nodeWithUInt(type)); insertInTail(er_list, nodeWithPointer(value)); List *rtnc_list = listThrough(p_home, _dogetChildByValue,er_list); free(er_list); - Node *p_node = NULL; + Node *p_node = NULL; if ((p_node = findByIndexForNode(rtnc_list, 1)) != NULL) { TNode *p_tnode = getByPointerForNode(p_node); - free(rtnc_list); - return p_tnode; - } - return NULL; -} - + free(rtnc_list); + return p_tnode; + } + return NULL; +} + List *_dogetChildByValue(unsigned int type, void *value, List *er_list) { List *rtn_list = initList(); unsigned int target_type = getByUIntForNode(findByIndexForNode(rtn_list, 0)); - void *target_value = getByPointerForNode(findByIndexForNode(rtn_list, 1)); - if (type == target_type) { - TNode *p_tode = (TNode *)value; - if (target_type == INT) { - if (*(int *)p_tode->value == *(int *)target_value) + void *target_value = getByPointerForNode(findByIndexForNode(rtn_list, 1)); + if (type == target_type) { + TNode *p_tode = (TNode *)value; + if (target_type == INT) { + if (*(int *)p_tode->value == *(int *)target_value) { insertInTail(rtn_list, nodeWithInt(-1)); - insertInTail(rtn_list, nodeWithPointer(p_tode)); - return rtn_list; - } - } - else if (target_type == DOUBLE) - { - if (*(double *)p_tode->value == *(double *)target_value) + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; + } + } + else if (target_type == DOUBLE) + { + if (*(double *)p_tode->value == *(double *)target_value) { insertInTail(rtn_list, nodeWithInt(-1)); - insertInTail(rtn_list, nodeWithPointer(p_tode)); - return rtn_list; - } - } - else if (target_type == STRING) - { - if (!strcmp((char *)p_tode->value, (char *)target_value)) + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; + } + } + else if (target_type == STRING) + { + if (!strcmp((char *)p_tode->value, (char *)target_value)) { insertInTail(rtn_list, nodeWithInt(-1)); - insertInTail(rtn_list, nodeWithPointer(p_tode)); - return rtn_list; - } - } - else if (target_type == POINTER) - { - if (p_tode->value == target_value) + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; + } + } + else if (target_type == POINTER) + { + if (p_tode->value == target_value) { insertInTail(rtn_list, nodeWithInt(-1)); - insertInTail(rtn_list, nodeWithPointer(p_tode)); - return rtn_list; - } - } - + insertInTail(rtn_list, nodeWithPointer(p_tode)); + return rtn_list; + } + } + } - insertInTail(rtn_list, nodeWithInt(0)); - return rtn_list; -} - -int removeChildById(TNode *p_tnode, const SID *s_id) { - TNode *t_tnode = getChildById(p_tnode, s_id); - if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; - p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->s_id); - releaseOnlyNode(t_tnode->room); - t_tnode->room = NULL; - return 0; - } - return -1; -} - -int removeChildByValue(TNode *p_tnode, unsigned int type, void *value) { - TNode *t_tnode = getChildByValue(p_tnode, type, value); - if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; - p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->s_id); - releaseOnlyNode(t_tnode->room); - t_tnode->room = NULL; - return 0; - } - return -1; -} - -TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) { - List *p_home = p_tnode->home; - Node *p_node = p_home->head; - int m_index = 0; - if (index < p_tnode->child_num) - { - while (p_node != NULL && m_index < index) { - m_index++; - p_node = p_node->next; - } - return (TNode *)p_node->value; - } - return NULL; -} - -unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { - List *p_home = f_tnode->home; - Node *p_node = p_home->head; - int m_index = 0; - while (p_node != NULL) { - TNode *p_tnode = (TNode *)p_node->value; - if (p_tnode->s_id == c_tnode->s_id) { - return m_index; - } - m_index++; - p_node = p_node->next; - } - return -1; -} - -int removeChildByIndex(TNode *p_tnode, unsigned long long index) { - TNode *t_tnode = getChildByIndex(p_tnode, index); - if (t_tnode != NULL) { - TNode *p_fnode = t_tnode->father; - p_fnode->child_num--; - removeById(p_fnode->home, t_tnode->room->s_id); - releaseOnlyNode(t_tnode->room); - t_tnode->room = NULL; - return 0; - } - return -1; -} - - -int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { - int i; - TNode *p_tnode = p_tree->root; - if (p_tnode != NULL) { - if (p_tnode->child_num > 0) { - for (i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughUp(getChildByIndex(p_tnode, i), 1, func) == -1) { - break; - } - } - } - func(p_tnode, 0); - } - return 0; -} - -int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { - int i, func_back; - - if (p_tnode->child_num > 0) { - for (i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughUp(getChildByIndex(p_tnode, i), height + 1, func)) return -1; - } - } - func_back = func(p_tnode, height); - if (func_back == -1)return -1; - return 0; -} - - -int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { - int i; - TNode *p_tnode = p_tree->root; - if (p_tree->root != NULL) { - func(p_tnode, 0); - if (p_tree->root->child_num > 0) { - for (i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { - break; - } - } - } - } - return 0; -} - -int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { - int i; - int func_back = func(p_tnode, height); - if (p_tnode->child_num > 0) { - for (i = 0; i < p_tnode->child_num; i++) { - if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; - } - } - if (func_back == -1)return -1; - return 0; -} - -int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { - TNode *p_tnode = p_tree->root; - unsigned long long height = 0; - if (p_tnode != NULL) { - int func_back = func(p_tnode, height); - while (func_back > -2) { - if (func_back > -1) { - p_tnode = getChildByIndex(p_tnode, func_back); - func(p_tnode, height + 1); - } - else - { - p_tnode = p_tnode->father; - func(p_tnode, height - 1); - - } - } - } - return 0; -} -int releaseTNode(TNode *p_tnode) { - if (p_tnode->child_num == 0) { - releaseList(p_tnode->home); - if (p_tnode->father != NULL) { - removeChildById(p_tnode->father, p_tnode->s_id); - } - if (p_tnode->type != POINTER) { - if (p_tnode->type == LIST) { - releaseList((List *)p_tnode->value); - } - else { - free(p_tnode->value); - } - } - p_tnode->value = NULL; - p_tnode->type = VOID; - freeS_id(p_tnode->s_id); - p_tnode->if_malloc = 0; - free(p_tnode); - } - return 0; -} - -int releaseTree(Tree *p_tree) { - TreeThroughUp(p_tree, _doreleaseTree); - p_tree->root = NULL; - freeS_id(p_tree->s_id); - free(p_tree); - return 0; -} - -int _doreleaseTree(TNode *p_tnode, unsigned long long height) { - releaseTNode(p_tnode); - return 0; -} - -int releaseOnlyTree(Tree *p_tree) { - freeS_id(p_tree->s_id); - p_tree->root = NULL; - free(p_tree); - return 0; -} - -int releaseOnlyTNode(TNode *p_tnode) { - releaseList(p_tnode->home); - if (p_tnode->if_malloc) { - if (p_tnode->type != STRING) { - if (p_tnode->type == LIST) { - releaseList((List *)p_tnode->value); - } - else { - free(p_tnode->value); - } - } - } - p_tnode->value = NULL; - p_tnode->type = VOID; - freeS_id(p_tnode->s_id); - p_tnode->if_malloc = 0; - free(p_tnode); - return 0; -} - -int releaseAllForTree(void) { - Node *p_node; - Tree *p_tree; - if (if_safeModeForTree) { - if_safeModeForTree = 0; - p_node = tnode_list->head; - while (p_node != NULL) { - TNode *p_tnode = (TNode *)p_node->value; - releaseOnlyTNode(p_tnode); - p_node = p_node->next; - } - p_node = tree_list->head; - while (p_node != NULL) { - p_tree = (Tree *)p_node->value; - releaseOnlyTree(p_tree); - p_node = p_node->next; - } - releaseList(tnode_list); - releaseList(tree_list); - } - return 0; -} - -int setRoot(Tree *p_tree, TNode *p_tnode) { - p_tree->root = p_tnode; - return 0; + insertInTail(rtn_list, nodeWithInt(0)); + return rtn_list; +} + +int removeChildById(TNode *p_tnode, const SID *s_id) { + TNode *t_tnode = getChildById(p_tnode, s_id); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->s_id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +int removeChildByValue(TNode *p_tnode, unsigned int type, void *value) { + TNode *t_tnode = getChildByValue(p_tnode, type, value); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->s_id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + +TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) { + List *p_home = p_tnode->home; + Node *p_node = p_home->head; + int m_index = 0; + if (index < p_tnode->child_num) + { + while (p_node != NULL && m_index < index) { + m_index++; + p_node = p_node->next; + } + return (TNode *)p_node->value; + } + return NULL; +} + +unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) { + List *p_home = f_tnode->home; + Node *p_node = p_home->head; + int m_index = 0; + while (p_node != NULL) { + TNode *p_tnode = (TNode *)p_node->value; + if (p_tnode->s_id == c_tnode->s_id) { + return m_index; + } + m_index++; + p_node = p_node->next; + } + return -1; +} + +int removeChildByIndex(TNode *p_tnode, unsigned long long index) { + TNode *t_tnode = getChildByIndex(p_tnode, index); + if (t_tnode != NULL) { + TNode *p_fnode = t_tnode->father; + p_fnode->child_num--; + removeById(p_fnode->home, t_tnode->room->s_id); + releaseOnlyNode(t_tnode->room); + t_tnode->room = NULL; + return 0; + } + return -1; +} + + +int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + int i; + TNode *p_tnode = p_tree->root; + if (p_tnode != NULL) { + if (p_tnode->child_num > 0) { + for (i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughUp(getChildByIndex(p_tnode, i), 1, func) == -1) { + break; + } + } + } + func(p_tnode, 0); + } + return 0; +} + +int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + int i, func_back; + + if (p_tnode->child_num > 0) { + for (i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughUp(getChildByIndex(p_tnode, i), height + 1, func)) return -1; + } + } + func_back = func(p_tnode, height); + if (func_back == -1)return -1; + return 0; +} + + +int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + int i; + TNode *p_tnode = p_tree->root; + if (p_tree->root != NULL) { + func(p_tnode, 0); + if (p_tree->root->child_num > 0) { + for (i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) { + break; + } + } + } + } + return 0; +} + +int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) { + int i; + int func_back = func(p_tnode, height); + if (p_tnode->child_num > 0) { + for (i = 0; i < p_tnode->child_num; i++) { + if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1; + } + } + if (func_back == -1)return -1; + return 0; +} + +int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) { + TNode *p_tnode = p_tree->root; + unsigned long long height = 0; + if (p_tnode != NULL) { + int func_back = func(p_tnode, height); + while (func_back > -2) { + if (func_back > -1) { + p_tnode = getChildByIndex(p_tnode, func_back); + func(p_tnode, height + 1); + } + else + { + p_tnode = p_tnode->father; + func(p_tnode, height - 1); + + } + } + } + return 0; +} +int releaseTNode(TNode *p_tnode) { + if (p_tnode->child_num == 0) { + releaseList(p_tnode->home); + if (p_tnode->father != NULL) { + removeChildById(p_tnode->father, p_tnode->s_id); + } + if (p_tnode->type != POINTER) { + if (p_tnode->type == LIST) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } + } + p_tnode->value = NULL; + p_tnode->type = VOID; + freeS_id(p_tnode->s_id); + p_tnode->if_malloc = 0; + free(p_tnode); + } + return 0; +} + +int releaseTree(Tree *p_tree) { + TreeThroughUp(p_tree, _doreleaseTree); + p_tree->root = NULL; + freeS_id(p_tree->s_id); + free(p_tree); + return 0; +} + +int _doreleaseTree(TNode *p_tnode, unsigned long long height) { + releaseTNode(p_tnode); + return 0; +} + +int releaseOnlyTree(Tree *p_tree) { + freeS_id(p_tree->s_id); + p_tree->root = NULL; + free(p_tree); + return 0; +} + +int releaseOnlyTNode(TNode *p_tnode) { + releaseList(p_tnode->home); + if (p_tnode->if_malloc) { + if (p_tnode->type != STRING) { + if (p_tnode->type == LIST) { + releaseList((List *)p_tnode->value); + } + else { + free(p_tnode->value); + } + } + } + p_tnode->value = NULL; + p_tnode->type = VOID; + freeS_id(p_tnode->s_id); + p_tnode->if_malloc = 0; + free(p_tnode); + return 0; +} + +int releaseAllForTree(void) { + Node *p_node; + Tree *p_tree; + if (if_safeModeForTree) { + if_safeModeForTree = 0; + p_node = tnode_list->head; + while (p_node != NULL) { + TNode *p_tnode = (TNode *)p_node->value; + releaseOnlyTNode(p_tnode); + p_node = p_node->next; + } + p_node = tree_list->head; + while (p_node != NULL) { + p_tree = (Tree *)p_node->value; + releaseOnlyTree(p_tree); + p_node = p_node->next; + } + releaseList(tnode_list); + releaseList(tree_list); + } + return 0; +} + +int setRoot(Tree *p_tree, TNode *p_tnode) { + p_tree->root = p_tnode; + return 0; } diff --git a/tree/tree_expand.c b/src/tree/tree_expand.c similarity index 96% rename from tree/tree_expand.c rename to src/tree/tree_expand.c index 5d9992d..0a584df 100644 --- a/tree/tree_expand.c +++ b/src/tree/tree_expand.c @@ -1,231 +1,231 @@ -#include "tree_expand.h" - -TNode *tnodeWithInt(int temp) { - TNode *p_tnode = initTNode(); +#include "tree_expand.h" + +TNode *tnodeWithInt(int temp) { + TNode *p_tnode = initTNode(); int *p_temp = (int *)malloc(sizeof(int)); if(p_temp == NULL){ showError(pushError(INT, STANDARD, initInfo("tnodeWithInt()", "Error in getting the memory of int."))); return NULL; - } - *p_temp = temp; - initMallocValueForTNode(p_tnode, INT, p_temp); - return p_tnode; -} - -TNode *tnodeWithDouble(double temp) { - TNode *p_tnode = initTNode(); + } + *p_temp = temp; + initMallocValueForTNode(p_tnode, INT, p_temp); + return p_tnode; +} + +TNode *tnodeWithDouble(double temp) { + TNode *p_tnode = initTNode(); double *p_temp = (double *)malloc(sizeof(double)); if(p_temp == NULL){ showError(pushError(DOUBLE, STANDARD, initInfo("tnodeWithDouble()", "Error in getting the memory of double."))); return NULL; - } - *p_temp = temp; - initMallocValueForTNode(p_tnode, DOUBLE, p_temp); - return p_tnode; -} -TNode *tnodeWithString(char *temp) { - TNode *p_tnode = initTNode(); + } + *p_temp = temp; + initMallocValueForTNode(p_tnode, DOUBLE, p_temp); + return p_tnode; +} +TNode *tnodeWithString(char *temp) { + TNode *p_tnode = initTNode(); char *p_temp = (char *)malloc(sizeof(temp)); if(p_temp == NULL){ showError(pushError(STRING, STANDARD, initInfo("tnodeWithString()", "Error in getting the memory of string."))); return NULL; - } - strcpy(p_temp, temp); - initMallocValueForTNode(p_tnode, STRING, p_temp); - return p_tnode; -} - -TNode *tnodeWithPointer(void *temp) { - TNode *p_tnode = initTNode(); - initMallocValueForTNode(p_tnode, POINTER, temp); - return p_tnode; -} - -int getValueByIntForTree(TNode *p_tnode) { - if (p_tnode->type == INT) { - return *(int *)p_tnode->value; - } - return -1; -} - -double getValueByDoubleForTree(TNode *p_tnode) { - if (p_tnode->type == DOUBLE) { - return *(double *)p_tnode->value; - } - return -1; -} - -char *getValueByStringForTree(TNode *p_tnode) { - if (p_tnode->type == STRING) { - return (char *)p_tnode->value; - } - return NULL; -} - -void *getValueByPointerForTree(TNode *p_tnode) { - if (p_tnode->type == POINTER) { - return p_tnode->value; - } - return NULL; -} - -int printTNode(TNode *p_tnode, int priority) { - int i; - if (p_tnode != NULL) { - for (i = 0; i < priority; i++) printf(" "); - if (priority == 0) printf("###"); - else printf("#"); - - printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); - for (i = 0; i < priority + 1; i++) printf(" "); - printf("ifMalloc: "); - if (p_tnode->if_malloc) { - printf("YES\n"); - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %d): ", p_tnode->type); - if (p_tnode->type == INT) { - printf("%d\n", *(int *)(p_tnode->value)); - } - else if (p_tnode->type == DOUBLE) { - printf("%a\n", *(double *)(p_tnode->value)); - } - else if (p_tnode->type == STRING) { - printf("%s\n", (char *)(p_tnode->value)); - } - else if (p_tnode->type == POINTER) { - printf("%p\n", (char *)(p_tnode->value)); - } - } - else printf("NO\n"); - - if (p_tnode->child_num > 0) { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Child number: %llu\n", p_tnode->child_num); - } - return 0; - } - return -1; -} - -int printTNodeWithHome(TNode *p_tnode,int priority) { - int i; - List *p_home; - Node *p_node; - if (p_tnode != NULL) { - if (priority == 0) printf("###"); - else printf("#"); - printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); - for (i = 0; i < priority + 1; i++) printf(" "); - printf("ifMalloc: "); - if (p_tnode->if_malloc) { - printf("YES\n"); - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %d): ", p_tnode->type); - if (p_tnode->type == INT) { - printf("%d\n", *(int *)(p_tnode->value)); - } - else if (p_tnode->type == DOUBLE) { - printf("%a\n", *(double *)(p_tnode->value)); - } - else if (p_tnode->type == STRING) { - printf("%s\n", (char *)(p_tnode->value)); - } - else if (p_tnode->type == POINTER) { - printf("%p\n", (char *)(p_tnode->value)); - } - } - else printf("NO\n"); - - if (p_tnode->father != NULL) { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id)); - } - else - { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Father: NO\n"); - } - - if (p_tnode->child_num > 0) { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Child(number: %llu):\n", p_tnode->child_num); - } - - p_home = p_tnode->home; - p_node = p_home->head; - while (p_node != NULL) { - printTNode((TNode *)p_node->value, priority + 2); - p_node = p_node->next; - } - return 0; - } - return -1; -} - -int printTNodeWithFamily(TNode *p_tnode, int priority) { - int i; - List *p_home; - Node *p_node; - if (p_tnode != NULL) { - for (i = 0; i < priority; i++) printf(" "); - if (priority == 0) printf("###"); - else printf("#"); - printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); - for (i = 0; i < priority + 1; i++) printf(" "); - printf("ifMalloc: "); - if (p_tnode->if_malloc) { - printf("YES\n"); - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Value(type: %d): ", p_tnode->type); - if (p_tnode->type == INT) { - printf("%d\n", *(int *)(p_tnode->value)); - } - else if (p_tnode->type == DOUBLE) { - printf("%a\n", *(double *)(p_tnode->value)); - } - else if (p_tnode->type == STRING) { - printf("%s\n", (char *)(p_tnode->value)); - } - else if (p_tnode->type == POINTER) { - printf("%p\n", (char *)(p_tnode->value)); - } - } - else printf("NO\n"); - - if (p_tnode->father != NULL) { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id)); - } - else - { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Father: NO\n"); - } - - if (p_tnode->child_num > 0) { - for (i = 0; i < priority + 1; i++) printf(" "); - printf("Child(number: %llu):\n", p_tnode->child_num); - } - - p_home = p_tnode->home; - p_node = p_home->head; - while (p_node != NULL) { - printTNodeWithFamily((TNode *)p_node->value, priority + 2); - p_node = p_node->next; - } - return 0; - } - return -1; -} - -int printTree(Tree *p_tree) { - printf("###"); - printf("Tree(id: %s)",s_idToASCIIString(p_tree->s_id)); - printTNodeWithFamily(p_tree->root,0); - return 0; + } + strcpy(p_temp, temp); + initMallocValueForTNode(p_tnode, STRING, p_temp); + return p_tnode; } -static unsigned long long tnodes_size = 0LL; +TNode *tnodeWithPointer(void *temp) { + TNode *p_tnode = initTNode(); + initMallocValueForTNode(p_tnode, POINTER, temp); + return p_tnode; +} + +int getValueByIntForTree(TNode *p_tnode) { + if (p_tnode->type == INT) { + return *(int *)p_tnode->value; + } + return -1; +} + +double getValueByDoubleForTree(TNode *p_tnode) { + if (p_tnode->type == DOUBLE) { + return *(double *)p_tnode->value; + } + return -1; +} + +char *getValueByStringForTree(TNode *p_tnode) { + if (p_tnode->type == STRING) { + return (char *)p_tnode->value; + } + return NULL; +} + +void *getValueByPointerForTree(TNode *p_tnode) { + if (p_tnode->type == POINTER) { + return p_tnode->value; + } + return NULL; +} + +int printTNode(TNode *p_tnode, int priority) { + int i; + if (p_tnode != NULL) { + for (i = 0; i < priority; i++) printf(" "); + if (priority == 0) printf("###"); + else printf("#"); + + printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("ifMalloc: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (p_tnode->type == DOUBLE) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (p_tnode->type == STRING) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (p_tnode->type == POINTER) { + printf("%p\n", (char *)(p_tnode->value)); + } + } + else printf("NO\n"); + + if (p_tnode->child_num > 0) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Child number: %llu\n", p_tnode->child_num); + } + return 0; + } + return -1; +} + +int printTNodeWithHome(TNode *p_tnode,int priority) { + int i; + List *p_home; + Node *p_node; + if (p_tnode != NULL) { + if (priority == 0) printf("###"); + else printf("#"); + printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("ifMalloc: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (p_tnode->type == DOUBLE) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (p_tnode->type == STRING) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (p_tnode->type == POINTER) { + printf("%p\n", (char *)(p_tnode->value)); + } + } + else printf("NO\n"); + + if (p_tnode->father != NULL) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id)); + } + else + { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Father: NO\n"); + } + + if (p_tnode->child_num > 0) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Child(number: %llu):\n", p_tnode->child_num); + } + + p_home = p_tnode->home; + p_node = p_home->head; + while (p_node != NULL) { + printTNode((TNode *)p_node->value, priority + 2); + p_node = p_node->next; + } + return 0; + } + return -1; +} + +int printTNodeWithFamily(TNode *p_tnode, int priority) { + int i; + List *p_home; + Node *p_node; + if (p_tnode != NULL) { + for (i = 0; i < priority; i++) printf(" "); + if (priority == 0) printf("###"); + else printf("#"); + printf("TNode(id: %s)\n", s_idToASCIIString(p_tnode->s_id)); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("ifMalloc: "); + if (p_tnode->if_malloc) { + printf("YES\n"); + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Value(type: %d): ", p_tnode->type); + if (p_tnode->type == INT) { + printf("%d\n", *(int *)(p_tnode->value)); + } + else if (p_tnode->type == DOUBLE) { + printf("%a\n", *(double *)(p_tnode->value)); + } + else if (p_tnode->type == STRING) { + printf("%s\n", (char *)(p_tnode->value)); + } + else if (p_tnode->type == POINTER) { + printf("%p\n", (char *)(p_tnode->value)); + } + } + else printf("NO\n"); + + if (p_tnode->father != NULL) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Father id: %s\n", s_idToASCIIString(p_tnode->father->s_id)); + } + else + { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Father: NO\n"); + } + + if (p_tnode->child_num > 0) { + for (i = 0; i < priority + 1; i++) printf(" "); + printf("Child(number: %llu):\n", p_tnode->child_num); + } + + p_home = p_tnode->home; + p_node = p_home->head; + while (p_node != NULL) { + printTNodeWithFamily((TNode *)p_node->value, priority + 2); + p_node = p_node->next; + } + return 0; + } + return -1; +} + +int printTree(Tree *p_tree) { + printf("###"); + printf("Tree(id: %s)",s_idToASCIIString(p_tree->s_id)); + printTNodeWithFamily(p_tree->root,0); + return 0; +} + +static unsigned long long tnodes_size = 0LL; unsigned long long calTreeMemory(Tree *p_tree){ tnodes_size = 0LL; diff --git a/tree/tree_expand.h b/src/tree/tree_expand.h similarity index 97% rename from tree/tree_expand.h rename to src/tree/tree_expand.h index bec0086..8649f82 100644 --- a/tree/tree_expand.h +++ b/src/tree/tree_expand.h @@ -1,27 +1,27 @@ -#ifndef TREE_EXPAND_H -#define TREE_EXPAND_H - -#include "tree.h" - -TNode *tnodeWithInt(int); -TNode *tnodeWithDouble(double); -TNode *tnodeWithString(char *); -TNode *tnodeWithPointer(void *); - -int getValueByIntForTree(TNode *); -double getValueByDoubleForTree(TNode *); -char *getValueByStringForTree(TNode *); -void *getValueByPointerForTree(TNode *); - -int printTree(Tree *p_tree); -int printTNodeWithHome(TNode *p_tnode, int priority); -int printTNodeWithFamily(TNode *p_tnode, int priority); -int printTNode(TNode *p_tnode, int priority); +#ifndef TREE_EXPAND_H +#define TREE_EXPAND_H + +#include "tree.h" + +TNode *tnodeWithInt(int); +TNode *tnodeWithDouble(double); +TNode *tnodeWithString(char *); +TNode *tnodeWithPointer(void *); + +int getValueByIntForTree(TNode *); +double getValueByDoubleForTree(TNode *); +char *getValueByStringForTree(TNode *); +void *getValueByPointerForTree(TNode *); + +int printTree(Tree *p_tree); +int printTNodeWithHome(TNode *p_tnode, int priority); +int printTNodeWithFamily(TNode *p_tnode, int priority); +int printTNode(TNode *p_tnode, int priority); unsigned long long calTreeMemory(Tree *); int _doCalTreeMemory(TNode *p_tnode, unsigned long long height); List *treeToList(Tree *p_tree); - -#endif + +#endif diff --git a/test.c b/test/test.c similarity index 92% rename from test.c rename to test/test.c index 3438b13..65025bb 100644 --- a/test.c +++ b/test/test.c @@ -1,7 +1,7 @@ -#include "test.h" - - -int list(void) { +#include "test.h" + + +int list(void) { List *p_list = initList(1); for(int i = 0; i < 12; i++){ insertInTail(p_list, nodeWithInt(i, 0)); @@ -13,53 +13,52 @@ int list(void) { dataFileAddStandardData(pd_file, pa_std); dataFileWriteIn(pd_file); releaseList(p_list); - releaseDFile(pd_file); - - return 0; -} - -/*int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) { - printTNode(p_tnode,0); - return 0; -}*/ - - -/*int tree(void) { - TNode *t_tnode, *cr_tnode, *cl_tnode; - Tree *t_tree; - TNode *gs_tnode; - safeModeForTree(1); - t_tree = initTree(); - t_tnode = tnodeWithInt(1); - cr_tnode = tnodeWithInt(3); - cl_tnode = tnodeWithInt(2); - addChildInRight(t_tnode, cl_tnode); - addChildInRight(t_tnode, cr_tnode); - addChildInRight(cl_tnode, tnodeWithInt(4)); - gs_tnode = tnodeWithInt(5); - addChildInRight(cl_tnode,gs_tnode); - addChildInRight(cr_tnode, tnodeWithInt(6)); - addChildInRight(cr_tnode, tnodeWithInt(7)); - addChildInRight(gs_tnode, tnodeWithInt(8)); - setRoot(t_tree, t_tnode); - TreeThroughUp(t_tree, _useTreeThroughDown); - //printTNodeWithFamily(t_tnode, 0); - releaseAllForTree(); - return 0; -}*/ - -int stack(void) { - int i; - Stack *t_stack = initStack(); - for (i = 0; i < 10; i++) { - pushStack(t_stack, snodeWithInt(i)); - } - for (i = 0; i < 10; i++) { - printf("%d", getValueByIntForSNode(popStack(t_stack))); - } - releaseStack(t_stack); - return 0; -} + releaseDFile(pd_file); + + return 0; +} + +/*int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) { + printTNode(p_tnode,0); + return 0; +}*/ + +/*int tree(void) { + TNode *t_tnode, *cr_tnode, *cl_tnode; + Tree *t_tree; + TNode *gs_tnode; + safeModeForTree(1); + t_tree = initTree(); + t_tnode = tnodeWithInt(1); + cr_tnode = tnodeWithInt(3); + cl_tnode = tnodeWithInt(2); + addChildInRight(t_tnode, cl_tnode); + addChildInRight(t_tnode, cr_tnode); + addChildInRight(cl_tnode, tnodeWithInt(4)); + gs_tnode = tnodeWithInt(5); + addChildInRight(cl_tnode,gs_tnode); + addChildInRight(cr_tnode, tnodeWithInt(6)); + addChildInRight(cr_tnode, tnodeWithInt(7)); + addChildInRight(gs_tnode, tnodeWithInt(8)); + setRoot(t_tree, t_tnode); + TreeThroughUp(t_tree, _useTreeThroughDown); + //printTNodeWithFamily(t_tnode, 0); + releaseAllForTree(); + return 0; +}*/ + +int stack(void) { + int i; + Stack *t_stack = initStack(); + for (i = 0; i < 10; i++) { + pushStack(t_stack, snodeWithInt(i)); + } + for (i = 0; i < 10; i++) { + printf("%d", getValueByIntForSNode(popStack(t_stack))); + } + releaseStack(t_stack); + return 0; +} int time_avg(void){ List *t_list = initList(0); @@ -82,11 +81,11 @@ int time_avg(void){ printf("TIME: %fus\n",avg_time); releaseList(t_list); return 0; -} - +} + int main(int argc, char **argv) { //time_avg(); - List *t_list = initList(0); + /*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); @@ -98,6 +97,13 @@ int main(int argc, char **argv) { insertBeforeNode(t_list, findByIndexForNode(t_list, 5), lni(6)); popFromHead(t_list); Node *p_node = findByIndexForNode(t_list, 7); - releaseList(t_list); - return 0; -} + releaseList(t_list);*/ + while(1){ + List *p_list = initList(0); + for(int i = 0; i < 65535; i++){ + insertInTail(p_list, nodeWithInt(i, 1)); + } + releaseList(p_list); + } + return 0; +} diff --git a/test.h b/test/test.h similarity index 97% rename from test.h rename to test/test.h index 54ed677..adb1ab8 100644 --- a/test.h +++ b/test/test.h @@ -1,22 +1,22 @@ -#ifndef TEST_H +#ifndef TEST_H #define TEST_H #include - + #include -#include +#include #include #include #include -#include +#include #include -#include +#include //#include "tree/tree_expand.h" -#include "communicate/communicate.h" - -int stack(void); -int list(void); +#include "communicate/communicate.h" + +int stack(void); +int list(void); int tree(void); -int time_avg(void); - +int time_avg(void); + #endif // TEST_H From ab027f2c4eff6571ee83dd5940b5ec2f40f2e839 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 21 Dec 2018 17:40:15 +0800 Subject: [PATCH 06/18] Fixed dirs. --- .../communicate}/communicate.c | 84 +++++++++---------- {error => src/error}/error.c | 0 {error => src/error}/error_file.c | 0 {graph => src/graph}/graph.c | 0 {graph => src/graph}/graph.h | 0 {id => src/id}/id.c | 0 {id => src/id}/md5.c | 0 7 files changed, 42 insertions(+), 42 deletions(-) rename {communicate => src/communicate}/communicate.c (84%) rename {error => src/error}/error.c (100%) rename {error => src/error}/error_file.c (100%) rename {graph => src/graph}/graph.c (100%) rename {graph => src/graph}/graph.h (100%) rename {id => src/id}/id.c (100%) rename {id => src/id}/md5.c (100%) diff --git a/communicate/communicate.c b/src/communicate/communicate.c similarity index 84% rename from communicate/communicate.c rename to src/communicate/communicate.c index 71bcd9d..6966348 100644 --- a/communicate/communicate.c +++ b/src/communicate/communicate.c @@ -9,7 +9,7 @@ /* *计算标准数据结构在文件中占用的空间,以字节为单位. */ -static unsigned long long calStandardData(STD_DATA *p_std); +static uint32_t calStandardData(STD_DATA *p_std); /* *数据文件管理结构中标准数据结构管理结构的简略信息的写入函数 @@ -58,7 +58,7 @@ __CALLBACK_STATE(findStandardDataBySid); -STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size){ +STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){ STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); if(p_sid != NULL){ p_stdb->sid = s_idToASCIIString(p_sid); @@ -66,7 +66,7 @@ STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long lon else p_stdb->sid = NULL; p_stdb->if_data = 0; p_stdb->location = 0; - unsigned int blocks_num = (unsigned int)(data_size/sizeof(char)); + uint32_t blocks_num = (uint32_t)(data_size/sizeof(char)); p_stdb->blocks_num = blocks_num; p_stdb->type = type; p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num); @@ -91,7 +91,7 @@ STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){ return p_stdc; } -STD_DATA *initStandardData(unsigned int type, SID *s_id){ +STD_DATA *initStandardData(uint16_t type, SID *s_id){ STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA)); p_std->pd_blocklst = initList(0); p_std->pd_ctnlst = initList(0); @@ -107,7 +107,7 @@ STD_DATA *initStandardData(unsigned int type, SID *s_id){ return p_std; } -int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *data, unsigned long long data_size){ +int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){ if (p_std->lock) return -1; STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size); dataForStandardDBlock(p_stdb, data); @@ -143,14 +143,14 @@ D_FILE *initDataFileForRead(char *route){ int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0)); - p_dfile->pf_head->data_num = p_dfile->pf_stdlst->length; + p_dfile->pf_head->data_num = (uint32_t)p_dfile->pf_stdlst->length; return 0; } int dataFileWriteIn(D_FILE *p_dfile){ fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp); - fwrite(&p_dfile->pf_head->data_num, sizeof(unsigned long long), 1, p_dfile->fp); + fwrite(&p_dfile->pf_head->data_num, sizeof(uint32_t), 1, p_dfile->fp); fwrite("STDINFO", sizeof(char), 8, p_dfile->fp); listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataInfoWrite), __SEND_ARG("%p", p_dfile->fp)); fwrite("STDLST", sizeof(char), 7, p_dfile->fp); @@ -162,10 +162,10 @@ __CALLBACK_DEFINE(StandardDataInfoWrite){ FILE *fp = __ARGS_P(0, FILE); STD_DATA *p_std = __VALUE(STD_DATA *); fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp); - fwrite(&p_std->type, sizeof(unsigned int), 1, fp); - unsigned long long std_size = calStandardData(p_std); + fwrite(&p_std->type, sizeof(uint16_t), 1, fp); + uint32_t std_size = calStandardData(p_std); p_std->size = std_size; - fwrite(&std_size, sizeof(unsigned long long), 1, fp); + fwrite(&std_size, sizeof(uint32_t), 1, fp); return __CRETURN__; } @@ -174,8 +174,8 @@ __CALLBACK_DEFINE(StandardDataWrite){ STD_DATA *p_std = __VALUE(STD_DATA *); fwrite("STD", sizeof(char), 4, fp); fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp); - fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp); - fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp); + fwrite(&p_std->pd_ctnlst->length, sizeof(uint32_t), 1, fp); + fwrite(&p_std->pd_blocklst->length, sizeof(uint32_t), 1, fp); listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(StandardDConnectionWrite), __SEND_ARG("%p", fp)); listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDBlockWrite), __SEND_ARG("%p", fp)); return __CRETURN__; @@ -202,8 +202,8 @@ __CALLBACK_DEFINE(StandardDBlockWrite){ else{ fwrite(&if_sid, sizeof(int), 1, fp); } - fwrite(&p_stdb->type, sizeof(unsigned int), 1, fp); - fwrite(&blocks_num, sizeof(unsigned long), 1, fp); + fwrite(&p_stdb->type, sizeof(uint16_t), 1, fp); + fwrite(&blocks_num, sizeof(uint32_t), 1, fp); fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp); return __CRETURN__; } @@ -217,10 +217,10 @@ STD_DATA *listToSTD(List *p_list){ else p_std = initStandardData(LIST, NULL); while (p_node != NULL) { if(p_node->type == HOLE) continue; - unsigned long long data_size = 0; + uint32_t data_size = 0; if(p_node->type == INT) data_size = sizeof(int); else if (p_node->type == DOUBLE) data_size = sizeof(double); - else if (p_node->type == STRING) data_size = strlen((char *)p_node->value) + 1; + else if (p_node->type == STRING) data_size = (uint32_t)strlen((char *)p_node->value) + 1; else data_size = sizeof(void *); standardDataAddBlock(p_std, p_node->s_id, p_node->type, p_node->value, data_size); p_node = p_node->next; @@ -290,25 +290,25 @@ __CALLBACK_DEFINE(StandardDataToList){ return __CRETURN__; } -unsigned long long calStandardData(STD_DATA *p_std){ +uint32_t calStandardData(STD_DATA *p_std){ List *rtn_lst = NULL; - unsigned long long size = 4 + sizeof(unsigned long long) * 2; + uint32_t size = 4 + sizeof(unsigned long long) * 2; if(p_std->s_id != NULL) size += SID_LEN * sizeof(char); rtn_lst = listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(calStandardDataCTN), __SEND_ARG("%d", size)); if(rtn_lst != NULL){ - size = __RTN_ARGS(rtn_lst, 0, unsigned long long); + size = __RTN_ARGS(rtn_lst, 0, uint32_t); releaseList(rtn_lst); } rtn_lst = listThrough(p_std->pd_blocklst, __CALLBACK_CALL(calStandardDataBLK), __SEND_ARG("%d", size)); if(rtn_lst != NULL){ - size = __RTN_ARGS(rtn_lst, 0, unsigned long long); + size = __RTN_ARGS(rtn_lst, 0, uint32_t); releaseList(rtn_lst); } return size; } __CALLBACK_DEFINE(calStandardDataCTN){ - unsigned long long size = __ARGS(0, unsigned long long); + uint32_t size = __ARGS(0, uint32_t); size += 64; //unsigned long long temp = __NOW_INDEX; if(__NOW_INDEX == __LIST_LEN - 1){ @@ -318,11 +318,11 @@ __CALLBACK_DEFINE(calStandardDataCTN){ } __CALLBACK_DEFINE(calStandardDataBLK){ - unsigned long long size = __ARGS(0, unsigned long long); + uint32_t size = __ARGS(0, uint32_t); STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *); - if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int); - else size += sizeof(int); - size += p_stdb->blocks_num + sizeof(unsigned int) + sizeof(unsigned long); + if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int32_t); + else size += sizeof(int32_t); + size += p_stdb->blocks_num + sizeof(uint16_t) + sizeof(uint32_t); //unsigned long long temp = __NOW_INDEX; if(__NOW_INDEX == __LIST_LEN - 1){ return __RETURN("%ull", size); @@ -375,19 +375,19 @@ MSG *createMessage(char *title, void *data, unsigned long data_size){ int readDataFileInfo(D_FILE *p_dfile){ if(checkIfDataFile(p_dfile)){ - unsigned long long std_num = 0,std_size; - unsigned int std_type = VOID; + uint32_t std_num = 0,std_size; + uint16_t std_type = VOID; char info_begin[INFO_TEST_LEN], s_id[SID_LEN]; - unsigned long long location = 0; - fread(&std_num, sizeof(unsigned long long), 1, p_dfile->fp); + uint32_t location = 0; + fread(&std_num, sizeof(uint32_t), 1, p_dfile->fp); fread(info_begin, sizeof(char),INFO_TEST_LEN,p_dfile->fp); - location += INFO_TEST_LEN + sizeof(unsigned long long) + FILE_TSET_LEN; + location += INFO_TEST_LEN + sizeof(uint32_t) + FILE_TSET_LEN; if(!strcmp(info_begin, "STDINFO")){ location += std_num * 45 + 7; for(int i = 0; i < std_num; i++){ fread(s_id, sizeof(char), SID_LEN, p_dfile->fp); - fread(&std_type, sizeof(unsigned int), 1, p_dfile->fp); - fread(&std_size, sizeof(unsigned long long), 1, p_dfile->fp); + fread(&std_type, sizeof(uint16_t), 1, p_dfile->fp); + fread(&std_size, sizeof(uint32_t), 1, p_dfile->fp); SID *temp_sid = setS_idWithString(s_id); STD_DATA *p_std = initStandardData(std_type,temp_sid); freeS_id(temp_sid); @@ -410,9 +410,9 @@ int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){ fread(s_id, sizeof(char), SID_LEN, p_dfile->fp); if(!strcmp(s_id, p_std->s_id->decrypt_str)){ - unsigned long long ctn_num = 0, blk_num = 0; - fread(&ctn_num, sizeof(unsigned long long), 1, p_dfile->fp); - fread(&blk_num, sizeof(unsigned long long), 1, p_dfile->fp); + uint32_t ctn_num = 0, blk_num = 0; + fread(&ctn_num, sizeof(uint32_t), 1, p_dfile->fp); + fread(&blk_num, sizeof(uint32_t), 1, p_dfile->fp); for(int i = 0; i < ctn_num; i++){ SID *fs_id = NULL, *ss_id = NULL; char t_sid[SID_LEN]; @@ -426,15 +426,15 @@ int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){ } for(int i = 0; i < blk_num; i++){ int if_sid = 0; - unsigned int type = VOID; - unsigned long blk_size = 0; + uint16_t type = VOID; + uint32_t blk_size = 0; char t_sid[SID_LEN]; - fread(&if_sid, sizeof(int), 1, p_dfile->fp); + fread(&if_sid, sizeof(int32_t), 1, p_dfile->fp); if(if_sid){ fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); } - fread(&type, sizeof(int), 1, p_dfile->fp); - fread(&blk_size, sizeof(unsigned long), 1, p_dfile->fp); + fread(&type, sizeof(int32_t), 1, p_dfile->fp); + fread(&blk_size, sizeof(uint32_t), 1, p_dfile->fp); char *buff = malloc(sizeof(char) * blk_size); fread(buff, sizeof(char), blk_size, p_dfile->fp); SID *sb_sid = NULL; @@ -459,8 +459,8 @@ int checkIfDataFile(D_FILE *p_dfile){ void printStandardData(void *value){ STD_DATA *p_std = (STD_DATA *)value; printf("SID:%s\n",p_std->s_id->decrypt_str); - printf("Loaction:%llu\n",p_std->location); - printf("Size:%llu\n",p_std->size); + printf("Loaction:%u\n",p_std->location); + printf("Size:%u\n",p_std->size); printf("Ctn number:%llu\n",p_std->pd_ctnlst->length); printf("Blk number:%llu\n",p_std->pd_blocklst->length); } diff --git a/error/error.c b/src/error/error.c similarity index 100% rename from error/error.c rename to src/error/error.c diff --git a/error/error_file.c b/src/error/error_file.c similarity index 100% rename from error/error_file.c rename to src/error/error_file.c diff --git a/graph/graph.c b/src/graph/graph.c similarity index 100% rename from graph/graph.c rename to src/graph/graph.c diff --git a/graph/graph.h b/src/graph/graph.h similarity index 100% rename from graph/graph.h rename to src/graph/graph.h diff --git a/id/id.c b/src/id/id.c similarity index 100% rename from id/id.c rename to src/id/id.c diff --git a/id/md5.c b/src/id/md5.c similarity index 100% rename from id/md5.c rename to src/id/md5.c From 9c51d27d1b9612df0bf2837df163b616208793f2 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 21 Dec 2018 17:44:34 +0800 Subject: [PATCH 07/18] Fixed. --- .../project.pbxproj | 579 ------- .../contents.xcworkspacedata | 7 - .../xcshareddata/IDEWorkspaceChecks.plist | 8 - .../xcdebugger/Expressions.xcexplist | 197 --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 1506 ----------------- .../xcschemes/xcschememanagement.plist | 19 - 6 files changed, 2316 deletions(-) delete mode 100644 ZE-Standard-Libraries.xcodeproj/project.pbxproj delete mode 100644 ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist delete mode 100644 ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist delete mode 100644 ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/ZE-Standard-Libraries.xcodeproj/project.pbxproj b/ZE-Standard-Libraries.xcodeproj/project.pbxproj deleted file mode 100644 index 5e6b815..0000000 --- a/ZE-Standard-Libraries.xcodeproj/project.pbxproj +++ /dev/null @@ -1,579 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 50; - objects = { - -/* Begin PBXBuildFile section */ - 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E7210F1B3D00161557 /* stack_expand.c */; }; - 9269D4EA210F1B4B00161557 /* list_expand_get.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4E9210F1B4B00161557 /* list_expand_get.c */; }; - 9269D4ED210F1B5E00161557 /* test.c in Sources */ = {isa = PBXBuildFile; fileRef = 9269D4EB210F1B5E00161557 /* test.c */; }; - 9269D4F5210F1BCE00161557 /* list_info.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246994F20CD000300B4E894 /* list_info.c */; }; - 9269D4F6210F1CD900161557 /* stack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246995920CE52A700B4E894 /* stack.c */; }; - 92CC992E212EF3E50060EFA5 /* list_quick.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC992D212EF3E50060EFA5 /* list_quick.c */; }; - 92CC9931212EF4BF0060EFA5 /* list_sort.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9930212EF4BF0060EFA5 /* list_sort.c */; }; - 92CC9934212EF5330060EFA5 /* safe_mode.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9933212EF5330060EFA5 /* safe_mode.c */; }; - 92CC9937212EF60A0060EFA5 /* list_print.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9936212EF60A0060EFA5 /* list_print.c */; }; - 92CC993A212EF62A0060EFA5 /* list_simple.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9939212EF62A0060EFA5 /* list_simple.c */; }; - 92CC9943212EFE7E0060EFA5 /* list_expand_find.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */; }; - 92CC9946212EFEF70060EFA5 /* list_expand_callback.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */; }; - 92CC9949212EFF6F0060EFA5 /* list_expand_complex.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */; }; - 92CC994C212F00030060EFA5 /* list_expand_node.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC994B212F00030060EFA5 /* list_expand_node.c */; }; - 92CC994E212F003F0060EFA5 /* list_expand_update.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC994D212F003F0060EFA5 /* list_expand_update.c */; }; - 92CC9950212F014A0060EFA5 /* list_simple_node.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC994F212F014A0060EFA5 /* list_simple_node.c */; }; - 92CC9952212F02200060EFA5 /* list_expand_calculate.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9951212F02200060EFA5 /* list_expand_calculate.c */; }; - 92CC9954212F03190060EFA5 /* list_find.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9953212F03190060EFA5 /* list_find.c */; }; - 92CC9956212F037F0060EFA5 /* list_init.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9955212F037F0060EFA5 /* list_init.c */; }; - 92CC9959212F03CB0060EFA5 /* list_release.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9958212F03CB0060EFA5 /* list_release.c */; }; - 92CC995B212F042E0060EFA5 /* list_remove.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995A212F042E0060EFA5 /* list_remove.c */; }; - 92CC995D212F048B0060EFA5 /* list_copy.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995C212F048B0060EFA5 /* list_copy.c */; }; - 92CC995F212F04EE0060EFA5 /* list_insert.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC995E212F04EE0060EFA5 /* list_insert.c */; }; - 92CC9961212F05330060EFA5 /* list_replace.c in Sources */ = {isa = PBXBuildFile; fileRef = 92CC9960212F05330060EFA5 /* list_replace.c */; }; - 92DE530A21CCEA430057ADCB /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530821CCEA430057ADCB /* md5.c */; }; - 92DE530B21CCEA430057ADCB /* id.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530921CCEA430057ADCB /* id.c */; }; - 92DE530E21CCEA510057ADCB /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530C21CCEA510057ADCB /* error.c */; }; - 92DE530F21CCEA510057ADCB /* error_file.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE530D21CCEA510057ADCB /* error_file.c */; }; - 92DE531121CCEA5B0057ADCB /* communicate.c in Sources */ = {isa = PBXBuildFile; fileRef = 92DE531021CCEA5B0057ADCB /* communicate.c */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 927993BB20CB87D6008CE3A9 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 9233C30E212292B000FB2485 /* md5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; - 9246994F20CD000300B4E894 /* list_info.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_info.c; sourceTree = ""; }; - 9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_expand.h; sourceTree = ""; }; - 9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list.h; sourceTree = ""; }; - 9246995820CE52A700B4E894 /* stack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = ""; }; - 9246995920CE52A700B4E894 /* stack.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stack.c; sourceTree = ""; }; - 9246995B20CE5C8900B4E894 /* stack_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_expand.h; sourceTree = ""; }; - 9246995D20CE655900B4E894 /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = ""; }; - 9246995E20CE655900B4E894 /* tree.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = ""; }; - 9269D4E7210F1B3D00161557 /* stack_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_expand.c; sourceTree = ""; }; - 9269D4E9210F1B4B00161557 /* list_expand_get.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_expand_get.c; sourceTree = ""; }; - 9269D4EB210F1B5E00161557 /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = test.c; sourceTree = ""; }; - 9269D4EC210F1B5E00161557 /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = test.h; sourceTree = ""; }; - 9269D4F0210F1B8000161557 /* type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = type.h; sourceTree = ""; }; - 9269D4F3210F1BB000161557 /* id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = id.h; sourceTree = ""; }; - 9269D4F7210F1D0B00161557 /* tree_expand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree_expand.c; sourceTree = ""; }; - 9269D4F9210F1D0F00161557 /* tree_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree_expand.h; sourceTree = ""; }; - 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ZE-Standard-Libraries"; sourceTree = BUILT_PRODUCTS_DIR; }; - 9286EB7F2114022F00752977 /* communicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = communicate.h; sourceTree = ""; }; - 92CC992D212EF3E50060EFA5 /* list_quick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_quick.c; sourceTree = ""; }; - 92CC992F212EF4340060EFA5 /* list_quick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_quick.h; sourceTree = ""; }; - 92CC9930212EF4BF0060EFA5 /* list_sort.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = list_sort.c; sourceTree = ""; }; - 92CC9932212EF5330060EFA5 /* safe_mode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = safe_mode.h; sourceTree = ""; }; - 92CC9933212EF5330060EFA5 /* safe_mode.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = safe_mode.c; sourceTree = ""; }; - 92CC9935212EF60A0060EFA5 /* list_print.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = list_print.h; sourceTree = ""; }; - 92CC9936212EF60A0060EFA5 /* list_print.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_print.c; sourceTree = ""; }; - 92CC9938212EF62A0060EFA5 /* list_simple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = list_simple.h; sourceTree = ""; }; - 92CC9939212EF62A0060EFA5 /* list_simple.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_simple.c; sourceTree = ""; }; - 92CC993E212EFB050060EFA5 /* list_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_type.h; sourceTree = ""; }; - 92CC993F212EFD590060EFA5 /* list_expand_1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand_1.h; sourceTree = ""; }; - 92CC9941212EFE050060EFA5 /* error.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = error.h; sourceTree = ""; }; - 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_find.c; sourceTree = ""; }; - 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_callback.c; sourceTree = ""; }; - 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_complex.c; sourceTree = ""; }; - 92CC994B212F00030060EFA5 /* list_expand_node.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_node.c; sourceTree = ""; }; - 92CC994D212F003F0060EFA5 /* list_expand_update.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_update.c; sourceTree = ""; }; - 92CC994F212F014A0060EFA5 /* list_simple_node.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_simple_node.c; sourceTree = ""; }; - 92CC9951212F02200060EFA5 /* list_expand_calculate.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_expand_calculate.c; sourceTree = ""; }; - 92CC9953212F03190060EFA5 /* list_find.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_find.c; sourceTree = ""; }; - 92CC9955212F037F0060EFA5 /* list_init.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_init.c; sourceTree = ""; }; - 92CC9958212F03CB0060EFA5 /* list_release.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_release.c; sourceTree = ""; }; - 92CC995A212F042E0060EFA5 /* list_remove.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_remove.c; sourceTree = ""; }; - 92CC995C212F048B0060EFA5 /* list_copy.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_copy.c; sourceTree = ""; }; - 92CC995E212F04EE0060EFA5 /* list_insert.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_insert.c; sourceTree = ""; }; - 92CC9960212F05330060EFA5 /* list_replace.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list_replace.c; sourceTree = ""; }; - 92CC9966212F11920060EFA5 /* stack_type.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_type.h; sourceTree = ""; }; - 92CC9967212F17C70060EFA5 /* error_file.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = error_file.h; sourceTree = ""; }; - 92DE530821CCEA430057ADCB /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = md5.c; path = src/id/md5.c; sourceTree = ""; }; - 92DE530921CCEA430057ADCB /* id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = id.c; path = src/id/id.c; sourceTree = ""; }; - 92DE530C21CCEA510057ADCB /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error.c; path = src/error/error.c; sourceTree = ""; }; - 92DE530D21CCEA510057ADCB /* error_file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = error_file.c; path = src/error/error_file.c; sourceTree = ""; }; - 92DE531021CCEA5B0057ADCB /* communicate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = communicate.c; path = src/communicate/communicate.c; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 927993BA20CB87D6008CE3A9 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 9246994E20CD000300B4E894 /* list */ = { - isa = PBXGroup; - children = ( - 92CC995C212F048B0060EFA5 /* list_copy.c */, - 92CC9951212F02200060EFA5 /* list_expand_calculate.c */, - 92CC9945212EFEF70060EFA5 /* list_expand_callback.c */, - 92CC9948212EFF6F0060EFA5 /* list_expand_complex.c */, - 92CC9942212EFE7E0060EFA5 /* list_expand_find.c */, - 9269D4E9210F1B4B00161557 /* list_expand_get.c */, - 92CC994B212F00030060EFA5 /* list_expand_node.c */, - 92CC994D212F003F0060EFA5 /* list_expand_update.c */, - 92CC9953212F03190060EFA5 /* list_find.c */, - 9246994F20CD000300B4E894 /* list_info.c */, - 92CC9955212F037F0060EFA5 /* list_init.c */, - 92CC995E212F04EE0060EFA5 /* list_insert.c */, - 92CC9936212EF60A0060EFA5 /* list_print.c */, - 92CC992D212EF3E50060EFA5 /* list_quick.c */, - 92CC9958212F03CB0060EFA5 /* list_release.c */, - 92CC995A212F042E0060EFA5 /* list_remove.c */, - 92CC9960212F05330060EFA5 /* list_replace.c */, - 92CC994F212F014A0060EFA5 /* list_simple_node.c */, - 92CC9939212EF62A0060EFA5 /* list_simple.c */, - 92CC9930212EF4BF0060EFA5 /* list_sort.c */, - 92CC9933212EF5330060EFA5 /* safe_mode.c */, - ); - path = list; - sourceTree = ""; - }; - 9246995720CE507900B4E894 /* stack */ = { - isa = PBXGroup; - children = ( - 9246995920CE52A700B4E894 /* stack.c */, - 9269D4E7210F1B3D00161557 /* stack_expand.c */, - ); - path = stack; - sourceTree = ""; - }; - 9246995C20CE654600B4E894 /* tree */ = { - isa = PBXGroup; - children = ( - 9246995E20CE655900B4E894 /* tree.c */, - 9269D4F9210F1D0F00161557 /* tree_expand.h */, - 9269D4F7210F1D0B00161557 /* tree_expand.c */, - ); - path = tree; - sourceTree = ""; - }; - 9269D4F1210F1B9E00161557 /* id */ = { - isa = PBXGroup; - children = ( - 92DE530921CCEA430057ADCB /* id.c */, - 92DE530821CCEA430057ADCB /* md5.c */, - ); - name = id; - path = ..; - sourceTree = ""; - }; - 927993B420CB87D6008CE3A9 = { - isa = PBXGroup; - children = ( - 92DE530721CCE96D0057ADCB /* documents */, - 92DE530621CCE9280057ADCB /* bin */, - 92DE530521CCE91B0057ADCB /* test */, - 92DE530421CCE90B0057ADCB /* src */, - 92CC993B212EF7400060EFA5 /* include */, - 927993BE20CB87D6008CE3A9 /* Products */, - ); - sourceTree = ""; - }; - 927993BE20CB87D6008CE3A9 /* Products */ = { - isa = PBXGroup; - children = ( - 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */, - ); - name = Products; - sourceTree = ""; - }; - 9286EB78211400BD00752977 /* error */ = { - isa = PBXGroup; - children = ( - 92DE530D21CCEA510057ADCB /* error_file.c */, - 92DE530C21CCEA510057ADCB /* error.c */, - ); - name = error; - path = ..; - sourceTree = ""; - }; - 9286EB7C2114021E00752977 /* communicate */ = { - isa = PBXGroup; - children = ( - 92DE531021CCEA5B0057ADCB /* communicate.c */, - ); - name = communicate; - path = ..; - sourceTree = ""; - }; - 92A15CFC211442C700826FB8 /* graph */ = { - isa = PBXGroup; - children = ( - ); - name = graph; - path = ..; - sourceTree = ""; - }; - 92CC993B212EF7400060EFA5 /* include */ = { - isa = PBXGroup; - children = ( - 92CC9964212F06C10060EFA5 /* communicate */, - 92CC9963212F06650060EFA5 /* tree */, - 92CC9962212F06190060EFA5 /* stack */, - 92CC9940212EFDF50060EFA5 /* error */, - 92CC993D212EF7DE0060EFA5 /* id */, - 92CC993C212EF75C0060EFA5 /* list */, - 9269D4F0210F1B8000161557 /* type.h */, - ); - path = include; - sourceTree = ""; - }; - 92CC993C212EF75C0060EFA5 /* list */ = { - isa = PBXGroup; - children = ( - 9246995120CD000300B4E894 /* list.h */, - 9246995020CD000300B4E894 /* list_expand.h */, - 92CC992F212EF4340060EFA5 /* list_quick.h */, - 92CC9932212EF5330060EFA5 /* safe_mode.h */, - 92CC9935212EF60A0060EFA5 /* list_print.h */, - 92CC9938212EF62A0060EFA5 /* list_simple.h */, - 92CC993E212EFB050060EFA5 /* list_type.h */, - 92CC993F212EFD590060EFA5 /* list_expand_1.h */, - ); - path = list; - sourceTree = ""; - }; - 92CC993D212EF7DE0060EFA5 /* id */ = { - isa = PBXGroup; - children = ( - 9269D4F3210F1BB000161557 /* id.h */, - 9233C30E212292B000FB2485 /* md5.h */, - ); - path = id; - sourceTree = ""; - }; - 92CC9940212EFDF50060EFA5 /* error */ = { - isa = PBXGroup; - children = ( - 92CC9941212EFE050060EFA5 /* error.h */, - 92CC9967212F17C70060EFA5 /* error_file.h */, - ); - path = error; - sourceTree = ""; - }; - 92CC9962212F06190060EFA5 /* stack */ = { - isa = PBXGroup; - children = ( - 9246995B20CE5C8900B4E894 /* stack_expand.h */, - 9246995820CE52A700B4E894 /* stack.h */, - 92CC9966212F11920060EFA5 /* stack_type.h */, - ); - path = stack; - sourceTree = ""; - }; - 92CC9963212F06650060EFA5 /* tree */ = { - isa = PBXGroup; - children = ( - 9246995D20CE655900B4E894 /* tree.h */, - ); - path = tree; - sourceTree = ""; - }; - 92CC9964212F06C10060EFA5 /* communicate */ = { - isa = PBXGroup; - children = ( - 9286EB7F2114022F00752977 /* communicate.h */, - ); - path = communicate; - sourceTree = ""; - }; - 92DE530421CCE90B0057ADCB /* src */ = { - isa = PBXGroup; - children = ( - 92A15CFC211442C700826FB8 /* graph */, - 9286EB7C2114021E00752977 /* communicate */, - 9286EB78211400BD00752977 /* error */, - 9269D4F1210F1B9E00161557 /* id */, - 9246995C20CE654600B4E894 /* tree */, - 9246995720CE507900B4E894 /* stack */, - 9246994E20CD000300B4E894 /* list */, - ); - path = src; - sourceTree = ""; - }; - 92DE530521CCE91B0057ADCB /* test */ = { - isa = PBXGroup; - children = ( - 9269D4EB210F1B5E00161557 /* test.c */, - 9269D4EC210F1B5E00161557 /* test.h */, - ); - path = test; - sourceTree = ""; - }; - 92DE530621CCE9280057ADCB /* bin */ = { - isa = PBXGroup; - children = ( - ); - path = bin; - sourceTree = ""; - }; - 92DE530721CCE96D0057ADCB /* documents */ = { - isa = PBXGroup; - children = ( - ); - path = documents; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 927993BC20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = { - isa = PBXNativeTarget; - buildConfigurationList = 927993C420CB87D6008CE3A9 /* Build configuration list for PBXNativeTarget "ZE-Standard-Libraries" */; - buildPhases = ( - 927993B920CB87D6008CE3A9 /* Sources */, - 927993BA20CB87D6008CE3A9 /* Frameworks */, - 927993BB20CB87D6008CE3A9 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "ZE-Standard-Libraries"; - productName = "ZE-Standard-Libraries"; - productReference = 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 927993B520CB87D6008CE3A9 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0940; - ORGANIZATIONNAME = ZE; - TargetAttributes = { - 927993BC20CB87D6008CE3A9 = { - CreatedOnToolsVersion = 9.4; - }; - }; - }; - buildConfigurationList = 927993B820CB87D6008CE3A9 /* Build configuration list for PBXProject "ZE-Standard-Libraries" */; - compatibilityVersion = "Xcode 9.3"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 927993B420CB87D6008CE3A9; - productRefGroup = 927993BE20CB87D6008CE3A9 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 927993BC20CB87D6008CE3A9 /* ZE-Standard-Libraries */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 927993B920CB87D6008CE3A9 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 92DE530A21CCEA430057ADCB /* md5.c in Sources */, - 92CC9931212EF4BF0060EFA5 /* list_sort.c in Sources */, - 92CC9961212F05330060EFA5 /* list_replace.c in Sources */, - 9269D4F6210F1CD900161557 /* stack.c in Sources */, - 92CC9959212F03CB0060EFA5 /* list_release.c in Sources */, - 92CC993A212EF62A0060EFA5 /* list_simple.c in Sources */, - 92CC992E212EF3E50060EFA5 /* list_quick.c in Sources */, - 92CC9943212EFE7E0060EFA5 /* list_expand_find.c in Sources */, - 9269D4E8210F1B3D00161557 /* stack_expand.c in Sources */, - 92DE530F21CCEA510057ADCB /* error_file.c in Sources */, - 92CC9937212EF60A0060EFA5 /* list_print.c in Sources */, - 92DE530E21CCEA510057ADCB /* error.c in Sources */, - 92CC994C212F00030060EFA5 /* list_expand_node.c in Sources */, - 92DE531121CCEA5B0057ADCB /* communicate.c in Sources */, - 92CC9956212F037F0060EFA5 /* list_init.c in Sources */, - 92CC9954212F03190060EFA5 /* list_find.c in Sources */, - 92CC9949212EFF6F0060EFA5 /* list_expand_complex.c in Sources */, - 92CC995D212F048B0060EFA5 /* list_copy.c in Sources */, - 92DE530B21CCEA430057ADCB /* id.c in Sources */, - 9269D4EA210F1B4B00161557 /* list_expand_get.c in Sources */, - 9269D4ED210F1B5E00161557 /* test.c in Sources */, - 9269D4F5210F1BCE00161557 /* list_info.c in Sources */, - 92CC9952212F02200060EFA5 /* list_expand_calculate.c in Sources */, - 92CC9946212EFEF70060EFA5 /* list_expand_callback.c in Sources */, - 92CC9950212F014A0060EFA5 /* list_simple_node.c in Sources */, - 92CC9934212EF5330060EFA5 /* safe_mode.c in Sources */, - 92CC995B212F042E0060EFA5 /* list_remove.c in Sources */, - 92CC994E212F003F0060EFA5 /* list_expand_update.c in Sources */, - 92CC995F212F04EE0060EFA5 /* list_insert.c in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 927993C220CB87D6008CE3A9 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - 927993C320CB87D6008CE3A9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx; - }; - name = Release; - }; - 927993C520CB87D6008CE3A9 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - COPY_HEADERS_RUN_UNIFDEF = NO; - HEADER_SEARCH_PATHS = "\"$(SRCROOT)/include\"/**"; - LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/bin\"/**"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 927993C620CB87D6008CE3A9 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - COPY_HEADERS_RUN_UNIFDEF = NO; - HEADER_SEARCH_PATHS = "\"$(SRCROOT)/include\"/**"; - LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/bin\"/**"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 927993B820CB87D6008CE3A9 /* Build configuration list for PBXProject "ZE-Standard-Libraries" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 927993C220CB87D6008CE3A9 /* Debug */, - 927993C320CB87D6008CE3A9 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 927993C420CB87D6008CE3A9 /* Build configuration list for PBXNativeTarget "ZE-Standard-Libraries" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 927993C520CB87D6008CE3A9 /* Debug */, - 927993C620CB87D6008CE3A9 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 927993B520CB87D6008CE3A9 /* Project object */; -} diff --git a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist b/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist deleted file mode 100644 index 52a1b4f..0000000 --- a/ZE-Standard-Libraries.xcodeproj/project.xcworkspace/xcuserdata/huyibing.xcuserdatad/xcdebugger/Expressions.xcexplist +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index b6f7cc9..0000000 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,1506 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist b/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index c2e0451..0000000 --- a/ZE-Standard-Libraries.xcodeproj/xcuserdata/huyibing.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,19 +0,0 @@ - - - - - SchemeUserState - - ZE-Standard-Libraries.xcscheme - - orderHint - 0 - - ZE-Standard-Libraries.xcscheme_^#shared#^_ - - orderHint - 0 - - - - From 16b326b1779cf2079d2e04a34b793a18ac3bb744 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Thu, 3 Jan 2019 16:42:03 +0800 Subject: [PATCH 08/18] Fixed. --- src/list/list_sort.c | 18 ++++++++++++++++++ test/test.c | 13 ------------- test/test.h | 5 +---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/list/list_sort.c b/src/list/list_sort.c index 6d97acf..0adea99 100644 --- a/src/list/list_sort.c +++ b/src/list/list_sort.c @@ -11,6 +11,15 @@ *返回: 如果成功返回0,如果失败则返回-1.*/ static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)); +/** + 链表排序函数,该函数不直接对用户开放 + + @param p_list 指向需要操作的链表的指针 + @param begin 开始的节点的序号 + @param end 结束的节点的序号 + @param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。 + @return 成功进行操作则返回0 + */ static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)){ unsigned long long target_index = begin; register Node *t_node = findByIndexForNode(p_list, target_index); @@ -41,6 +50,15 @@ static int sortList(List *p_list, unsigned long long begin, unsigned long long e return 0; } + + +/** + 向用户开放的链表排序函数 + + @param p_list 指向需要操作的链表 + @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; diff --git a/test/test.c b/test/test.c index 65025bb..cacba84 100644 --- a/test/test.c +++ b/test/test.c @@ -47,19 +47,6 @@ int list(void) { return 0; }*/ -int stack(void) { - int i; - Stack *t_stack = initStack(); - for (i = 0; i < 10; i++) { - pushStack(t_stack, snodeWithInt(i)); - } - for (i = 0; i < 10; i++) { - printf("%d", getValueByIntForSNode(popStack(t_stack))); - } - releaseStack(t_stack); - return 0; -} - int time_avg(void){ List *t_list = initList(0); int64_t time_all = 0; diff --git a/test/test.h b/test/test.h index adb1ab8..7f9e36b 100644 --- a/test/test.h +++ b/test/test.h @@ -9,10 +9,7 @@ #include #include #include -#include -#include -//#include "tree/tree_expand.h" -#include "communicate/communicate.h" +#include int stack(void); int list(void); From 36560ef07bdb1207c09a3cee3835b9a00ea5e2b5 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Thu, 3 Jan 2019 18:33:14 +0800 Subject: [PATCH 09/18] Added. --- src/list/list_copy.c | 9 ++++++- src/list/list_expand_complex.c | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/list/list_copy.c b/src/list/list_copy.c index 99f64f8..4cf7549 100644 --- a/src/list/list_copy.c +++ b/src/list/list_copy.c @@ -3,7 +3,7 @@ /** - 以一个已存在的节点为模板创建一个新的节点 + 以一个已存在的节点为模板创建一个相同的新的节点 @param p_node 指向作为模板的节点的指针 @return 返回指向新的节点的指针 @@ -26,6 +26,13 @@ Node *copyNode(Node *p_node) { return t_node; } + +/** + 根据已存在的链表创建一个相同的新的链表 + + @param p_list 指向作为模板的链表的指针 + @return 返回指向新链表的指针 + */ List *copyList(List *p_list) { Node *p_node; Node *t_node; diff --git a/src/list/list_expand_complex.c b/src/list/list_expand_complex.c index 9f9a02f..62fb00e 100644 --- a/src/list/list_expand_complex.c +++ b/src/list/list_expand_complex.c @@ -2,6 +2,11 @@ #include #include +/** + 创建一个新的且内容为链表的节点 + + @return 返回指向新节点的指针 + */ Node *nodeWithComplex(void) { Node *p_node = initNode(0); p_node->type = LIST; @@ -9,6 +14,15 @@ Node *nodeWithComplex(void) { return p_node; } + +/** + 为一个内容为链表的节点中的链表中添加节点并指定内容 + + @param p_node 指向该节点的指针 + @param type 内容的类型 + @param value 指向该内容所在内存的指针 + @return 操作成功则返回一个非负整数 + */ int addValueForComplex(Node * p_node, int type, void *value) { List *c_list; Node *c_node; @@ -22,6 +36,14 @@ int addValueForComplex(Node * p_node, int type, void *value) { return -1; } + +/** + 为一个内容为链表的节点中的链表中添加整型类型的节点并初始化为相应的值 + + @param p_node 指向该节点的指针 + @param temp 相应的整型值 + @return 操作成功则返回非负整数 + */ int addIntForComplex(Node *p_node, int temp) { if (p_node->type == LIST) { int *p_temp = (int *)malloc(sizeof(int)); @@ -35,6 +57,14 @@ int addIntForComplex(Node *p_node, int temp) { return -1; } + +/** + 为一个内容为链表的节点中的链表中添加双精度浮点类型的节点并初始化为相应的值 + + @param p_node 指向该节点的指针 + @param temp 相应的双精度浮点值 + @return 操作成功则返回非负整数 + */ int addDoubleForComplex(Node *p_node, double temp) { if (p_node->type == LIST) { double *p_temp = (double *)malloc(sizeof(double)); @@ -48,6 +78,14 @@ int addDoubleForComplex(Node *p_node, double temp) { return -1; } + +/** + 为一个内容为链表的节点中的链表中添加字符串类型的节点并初始化为相应的值 + + @param p_node 指向该节点的指针 + @param temp 相应的字符数组 + @return 操作成功则返回非负整数 + */ int addStringForComplex(Node *p_node, char *temp) { if (p_node->type == LIST) { char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1)); @@ -61,6 +99,14 @@ int addStringForComplex(Node *p_node, char *temp) { return -1; } + +/** + 为一个内容为链表的节点中的链表中添加指针类型的节点并初始化为相应的值 + + @param p_node 指向该节点的指针 + @param temp 相应的指针 + @return 操作成功则返回非负整数 + */ int addPointerForComplex(Node *p_node, void *temp) { if (p_node->type == LIST) { addValueForComplex(p_node, POINTER, temp); From 08f2d523c861cf1945448ad2ba1e311f03ada194 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Fri, 4 Jan 2019 18:16:16 +0800 Subject: [PATCH 10/18] Added. --- .gitignore | 1 + src/list/list_expand_find.c | 130 +++++++++++++++++++++++++++++------- src/list/list_expand_get.c | 33 ++++++++- 3 files changed, 138 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 9db3cb7..ba9c358 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /ZE-Standard-Libraries /ZE-Standard-Libraries.sln /.vs +*.xcodeproj diff --git a/src/list/list_expand_find.c b/src/list/list_expand_find.c index 1f06dfd..5329de9 100644 --- a/src/list/list_expand_find.c +++ b/src/list/list_expand_find.c @@ -1,10 +1,19 @@ #include #include #include +//长链表模式可能启用则包含以下头文件 #ifdef list_quick_enable #include #endif + +/** + 通过节点中储存的整型值来找到链表中第一个符合条件的节点 + + @param p_list 指向目标链表的指针 + @param target 目标节点中储存的整型值 + @return 返回指向目标节点的指针 + */ Node *findByIntForNode(List *p_list, int target) { Node *t_node; int *p_target = (int *)malloc(sizeof(int)); @@ -14,6 +23,13 @@ Node *findByIntForNode(List *p_list, int target) { return t_node; } +/** + 通过节点中储存的双精度浮点值来找到链表中第一个符合条件的节点 + + @param p_list 指向目标链表的指针 + @param target 目标节点中储存的双精度浮点值 + @return 返回指向目标节点的指针 + */ Node *findByDoubleForNode(List *p_list, double target) { Node *t_node; double *p_target = (double *)malloc(sizeof(double)); @@ -23,6 +39,13 @@ Node *findByDoubleForNode(List *p_list, double target) { return t_node; } +/** + 通过节点中储存的字符串值来找到链表中第一个符合条件的节点 + + @param p_list 指向目标链表的指针 + @param target 目标节点中储存的字符数组值 + @return 返回指向目标节点的指针 + */ Node *findByStringForNode(List *p_list, char *target) { Node *t_node; char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1)); @@ -32,11 +55,27 @@ Node *findByStringForNode(List *p_list, char *target) { return t_node; } + +/** + 通过节点中储存的指针值来找到链表中第一个符合条件的节点 + + @param p_list 指向目标链表的指针 + @param target 目标节点中储存的字符指针值 + @return 返回指向目标节点的指针 + */ Node *findByPointerForNode(List *p_list, void *target) { Node *t_node = findByValue(p_list, POINTER, target); return t_node; } + +/** + 通过节点中储存的整型值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的整型值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ List *mply_findByInt(List* p_list, int temp) { int *p_temp = (int *)malloc(sizeof(int)); if(p_temp == NULL){ @@ -49,6 +88,13 @@ List *mply_findByInt(List* p_list, int temp) { return t_list; } +/** + 通过节点中储存的双精度浮点值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的双精度浮点值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ List *mply_findByDouble(List* p_list, double temp) { List *t_list; double *p_temp = (double *)malloc(sizeof(double)); @@ -61,6 +107,13 @@ List *mply_findByDouble(List* p_list, double temp) { return t_list; } +/** + 通过节点中储存的字符串值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的字符串值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ List *mply_findByString(List* p_list, char *temp) { List *t_list; char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); @@ -73,44 +126,75 @@ List *mply_findByString(List* p_list, char *temp) { return t_list; } + +/** + 通过节点中储存的指针值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的指针值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ List *mply_findByPointer(List* p_list, void *temp) { List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp); return t_list; } -List *mply_findByIntForNode(List* p_list, int temp) { - int *p_temp = (int *)malloc(sizeof(int)); - if(p_temp == NULL){ - return NULL; - } - *p_temp = temp; - return mply_findByValue(p_list, INT, (void *)p_temp); + +/** + 通过节点中储存的整型值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的整型值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ +inline List *mply_findByIntForNode(List* p_list, int temp) { + return mply_findByInt(p_list, temp); } -List *mply_findByDoubleForNode(List* p_list, double temp) { - double *p_temp = (double *)malloc(sizeof(double)); - if(p_temp == NULL){ - return NULL; - } - *p_temp = temp; - return mply_findByValue(p_list, DOUBLE, (void *)p_temp); +/** + 通过节点中储存的双精度浮点值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的双精度浮点值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ +inline List *mply_findByDoubleForNode(List* p_list, double temp) { + return mply_findByDouble(p_list, temp); } -List *mply_findByStringForNode(List* p_list, char *temp) { - char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1)); - if(p_temp == NULL){ - return NULL; - } - strcpy(p_temp, temp); - return mply_findByValue(p_list, STRING, (void *)p_temp); +/** + 通过节点中储存的字符串值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的字符串值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ +inline List *mply_findByStringForNode(List* p_list, char *temp) { + return mply_findByString(p_list, temp); } -List *mply_findByPointerForNode(List* p_list, void *temp) { - return mply_findByValue(p_list, POINTER, (void *)temp); +/** + 通过节点中储存的指针值来找到链表中所有符合条件的节点 + + @param p_list 指向目标链表的指针 + @param temp 目标节点中储存的指针值 + @return 返回包含所有符合条件的节点的新的重组链表 + */ +inline List *mply_findByPointerForNode(List* p_list, void *temp) { + return mply_findByPointer(p_list, temp); } + +/** + 通过节点在链表中的序号位置来找到符合条件的节点 + + @param p_list 指向目标链表的指针 + @param m_index 序号位置 + @return 返回指向符合条件的链表的指针 + */ Node *findByIndexForNode(List *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; diff --git a/src/list/list_expand_get.c b/src/list/list_expand_get.c index dbb9347..e8d5812 100644 --- a/src/list/list_expand_get.c +++ b/src/list/list_expand_get.c @@ -1,27 +1,53 @@ #include #include #include - +//长链表模式可能启用则包含以下头文件 #ifdef list_quick_enable #include #endif -/*直接获得节点中储存的字符串值*/ +/** + 直接获得节点中储存的字符串 + + @param p_node 指向目标节点的指针 + @return 返回节点中储存的字符串 + */ char *getByStringForNode(Node *p_node) { if (p_node->type == STRING) return (char *)(p_node->value); else return NULL; } +/** + 直接获得节点中储存的双精度浮点值 + + @param p_node 指向目标节点的指针 + @return 返回节点中储存的双精度浮点值 + */ double getByDoubleForNode(Node *p_node) { if (p_node->type == DOUBLE) return *(double *)(p_node->value); - else return -1; + else return -1.0; } +/** + 直接获得节点中储存的指针值 + + @param p_node 指向目标节点的指针 + @return 返回节点中储存的指针值 + */ void *getByPointerForNode(Node *p_node) { return (void *)(p_node->value); } + +/** + 通过链表中相应的节点获得其在链表中的排列序号 + + @param p_list 指向目标链表 + @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; @@ -32,6 +58,7 @@ unsigned long long getIndexByNode(List *p_list, Node *p_node) { register Node *t_node = p_list->head; register unsigned long long index = 0; while (t_node != NULL) { +// id模块可能启用的时候则编译以下代码 #ifdef id_enable if (p_node->s_id == t_node->s_id) return index; #endif From 940087e8204c9584a9a8b2dfd25b7ea03fa7ed76 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sun, 6 Jan 2019 18:44:11 +0800 Subject: [PATCH 11/18] Added and Fixed. --- include/list/list.h | 8 +++++ include/list/list_expand.h | 48 +++++++++++++------------- include/list/list_expand_1.h | 6 ++-- src/list/list_expand_calculate.c | 6 ++-- src/list/list_expand_callback.c | 12 +++++-- src/list/list_expand_node.c | 58 +++++++++++++++++++++++++++++--- src/list/list_expand_update.c | 44 ++++++++++++++++++++++-- src/list/list_find.c | 28 ++++++++++++++- src/list/list_info.c | 15 ++++++++- src/list/list_init.c | 39 +++++++++++++++++++-- src/list/list_sort.c | 6 ++-- 11 files changed, 224 insertions(+), 46 deletions(-) diff --git a/include/list/list.h b/include/list/list.h index 534f0c5..e5919de 100644 --- a/include/list/list.h +++ b/include/list/list.h @@ -11,12 +11,20 @@ /* *初始化链表,并返回指向新链表的指针,参数if_sid指示是否为新链表分配ID号 *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +#ifdef id_enable extern List *initList(_Bool if_sid); +#else +extern List *initList(void); +#endif /* *初始化节点,并返回指向新链表的指针,参数if_sid指示是否为新节点分配ID号 *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ +#ifdef id_enable extern Node *initNode(_Bool if_sid); +#else +extern Node *initNode(void); +#endif /*库中内部调用函数,旨在为新节点的储存值获取内存,并将相应的储存值储存在获取到的内存中,并指明储存值的类型.*/ extern int initMallocValueForNode(Node *,unsigned int,const void *); diff --git a/include/list/list_expand.h b/include/list/list_expand.h index 58926e5..5469a1e 100644 --- a/include/list/list_expand.h +++ b/include/list/list_expand.h @@ -1,4 +1,4 @@ -#ifndef list_expand_h +#ifndef list_expand_h #define list_expand_h #include @@ -12,7 +12,7 @@ /* *为新节点获取内存空间, 并使用整型值初始化新节点 *参数if_sid指示函数是否为节点获取ID - *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ extern Node *nodeWithInt(int, _Bool if_sid); /* @@ -30,23 +30,23 @@ extern Node *nodeWithULLInt(unsigned long long, _Bool if_sid); /* *为新节点获取内存空间, 并使用浮点值初始化新节点 *参数if_sid指示函数是否为节点获取ID - *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ extern Node *nodeWithDouble(double, _Bool if_sid); /* *为新节点获取内存空间, 并使用字符串值初始化新节点 *参数if_sid指示函数是否为节点获取ID - *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ extern Node *nodeWithString(const char *, _Bool if_sid); /* *为新节点获取内存空间, 并使用指针值初始化新节点 *参数if_sid指示函数是否为节点获取ID - *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ + *返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/ extern Node *nodeWithPointer(const void *, _Bool if_sid); - + /************************************************ *嵌套节点的快速初始化: 为嵌套节点节点分配内存空间, * 并使用输入值对其进行初始化 @@ -55,33 +55,33 @@ extern Node *nodeWithPointer(const void *, _Bool if_sid); /* *为新嵌套节点获取内存空间 - *返回: 若成功指向新嵌套节点的指针,若失败函数返回NULL.*/ + *返回: 若成功指向新嵌套节点的指针,若失败函数返回NULL.*/ extern Node *nodeWithComplex(void); /* *用输入的值初始化嵌套节点 *参数: type指明所输入值的类型,value为指向所输入值的内存空间的指针 - *返回: 若成功则返回0,若失败函数返回-1.*/ + *返回: 若成功则返回0,若失败函数返回-1.*/ extern int addValueForComplex(Node *, int type, void *value); /* *用输入的整型值初始化嵌套节点 - *返回: 若成功则返回0,若失败函数返回-1.*/ + *返回: 若成功则返回0,若失败函数返回-1.*/ extern int addIntForComplex(Node *, int); /* *用输入的浮点值初始化嵌套节点 - *返回: 若成功则返回0,若失败函数返回-1.*/ + *返回: 若成功则返回0,若失败函数返回-1.*/ extern int addDoubleForComplex(Node *, double); /* *用输入的字符串初始化嵌套节点 - *返回: 若成功则返回0,若失败函数返回-1.*/ + *返回: 若成功则返回0,若失败函数返回-1.*/ extern int addStringForComplex(Node *, char *); /* *用输入的指针值初始化嵌套节点 - *返回: 若成功则返回0,若失败函数返回-1.*/ + *返回: 若成功则返回0,若失败函数返回-1.*/ extern int addPointerForComplex(Node *, void *); @@ -99,7 +99,7 @@ extern int updateValueWithIntForNode(Node *,int); /* *用输入的无符号长整型值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithULLIntForNode(Node *, unsigned long long); +extern int updateValueWithULLIntForNode(Node *, uint64_t); /* *用输入的浮点值更新节点中的值 @@ -114,7 +114,7 @@ extern int updateValueWithStringForNode(Node *,char *); /* *用输入的指针值更新节点中的值 *返回: 若成功则返回0,若失败函数返回-1.*/ -extern int updateValueWithPointerForNode(Node *,void *); +extern int updateValueWithPointerForNode(Node *,void *); @@ -125,23 +125,23 @@ extern int updateValueWithPointerForNode(Node *,void *); /* *通过输入的整型值,查找链表中多个含有该值的节点 - *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ List *mply_findByIntForNode(List*, int); /* *通过输入的浮点值,查找链表中多个含有该值的节点 - *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ List *mply_findByDoubleForNode(List*, double); /* *通过输入的字符串值,查找链表中多个含有该值的节点 - *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ List *mply_findByStringForNode(List*, char *); /* *通过输入的指针值,查找链表中多个含有该值的节点 - *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ -List *mply_findByPointerForNode(List*, void *); + *返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/ +List *mply_findByPointerForNode(List*, void *); @@ -157,7 +157,7 @@ List *mply_findByPointerForNode(List*, void *); *参数: p_func为一个函数指针, 指向的回调函数的职能在于接受每个节点的类型(type)/值指针(value)/传入参数链表(args), 然后进行相关操作,并返回一个链表,其中包含返回状态,若有,也可以包含想要传递给母函数的值 expand_resources为一个链表,储存母函数想要传递给回调函数的值 - *返回: 如果回调函数有需要返回给母函数的值,则返回包含这些值的链表,否则返回NULL.*/ + *返回: 如果回调函数有需要返回给母函数的值,则返回包含这些值的链表,否则返回NULL.*/ extern List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *args), List *expand_resources); /* @@ -186,7 +186,7 @@ unsigned long long getInfoForListThrough(List *expand_resources, int type); /* *以字节为单位计算链表的大小 */ -unsigned long long calListMemory(List *); +uint64_t calListMemory(List *); @@ -197,7 +197,7 @@ unsigned long long calListMemory(List *); /* *返回链表长度*/ -extern unsigned long long len(List *p_list); +extern uint64_t len(List *p_list); /* *查询链表是否为空 @@ -283,5 +283,5 @@ extern Node *findByStringForNode(List *, char *); *通过指针值查找储存该值的单个节点. *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ extern Node *findByPointerForNode(List *, void *); - -#endif + +#endif diff --git a/include/list/list_expand_1.h b/include/list/list_expand_1.h index 9a4193c..a8e4028 100644 --- a/include/list/list_expand_1.h +++ b/include/list/list_expand_1.h @@ -4,11 +4,11 @@ #include /************************************************ - *节点快速初始化相关宏 + *节点快速初始化相关宏,提供函数名较为简单的调用方式 ************************************************/ /**** - *不带ID相关 + *不带ID模块相关宏 */ /*直接获取一个以整型值初始化的节点不带ID的缩略*/ @@ -30,7 +30,7 @@ #define lnp(x) nodeWithPointer(x,0) /**** - *带ID相关 + *带ID模块的相关宏 */ /*直接获取一个以整型值初始化的带ID节点的缩略*/ diff --git a/src/list/list_expand_calculate.c b/src/list/list_expand_calculate.c index b685233..8f93edf 100644 --- a/src/list/list_expand_calculate.c +++ b/src/list/list_expand_calculate.c @@ -7,10 +7,10 @@ @param p_list 指向目标链表的指针 @return 以字节为单位返回链表及链表内包含的节点所占的内存空间 */ -unsigned long long calListMemory(List * p_list){ +uint64_t calListMemory(List * p_list){ Node *p_node = p_list->head; - unsigned long long nodes_size = 0LL; - unsigned long long list_size = sizeof(p_list); + uint64_t nodes_size = 0LL; + uint64_t list_size = sizeof(p_list); while(p_node != NULL){ nodes_size += sizeof(p_node); p_node = p_node->next; diff --git a/src/list/list_expand_callback.c b/src/list/list_expand_callback.c index c4a4341..6dca02e 100644 --- a/src/list/list_expand_callback.c +++ b/src/list/list_expand_callback.c @@ -3,10 +3,18 @@ #include #include -List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) { + +/** + 顺序遍历链表的操作函数,不对用户开放。回调函数返回-1退出遍历,返回1继续向后遍历,返回其他值则暂停向下遍历。 + 回调函数接受一个整数、一个指向节点内容的指针、一个而外的参数链表,且回调函数需要返回一个链表,链表的第一个值作为函数的实际返回值。 + @param p_list 指向目标链表的指针 + @param p_func 指向回调函数的指针 + @return 返回参数链表 + */ +List *listThrough(List *p_list, List *(*p_func)(uint32_t, void *, List *), List *expand_resources) { Node *p_node = p_list->head; List *m_rtnlst = NULL; - unsigned long long index = 0; + uint64_t index = 0; insertInTail(expand_resources, nodeWithULLInt(index, 0)); insertInTail(expand_resources, nodeWithULLInt(p_list->length, 0)); while (p_node != NULL) { diff --git a/src/list/list_expand_node.c b/src/list/list_expand_node.c index 912bef2..b30777e 100644 --- a/src/list/list_expand_node.c +++ b/src/list/list_expand_node.c @@ -2,6 +2,14 @@ #include #include + +/** + 直接使用一个整型值初始化一个新的节点 + + @param m_int 整型值 + @param if_sid 新的节点有无id + @return 返回指向新节点的指针 + */ Node *nodeWithInt(int m_int, _Bool if_sid) { Node *p_node; int *p_int = (int *)malloc(sizeof(int)); @@ -14,21 +22,37 @@ Node *nodeWithInt(int m_int, _Bool if_sid) { return p_node; } -Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){ + +/** + 直接使用一个无符号整型值初始化一个新的节点 + + @param m_uint 无符号整型值 + @param if_sid 新的节点有无id + @return 返回指向新节点的指针 + */ +Node *nodeWithUInt(uint32_t m_uint, _Bool if_sid){ Node *p_node; - unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); + unsigned int *pu_int = (uint32_t *)malloc(sizeof(uint32_t)); if(pu_int == NULL){ return NULL; } *pu_int = m_uint; p_node = initNode(if_sid); - initMallocValueForNode(p_node, INT, (void *)pu_int); + initMallocValueForNode(p_node, UINT, (void *)pu_int); return p_node; } -Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) { + +/** + 直接使用一个无符号长整型值(占用8个字节)初始化一个新的节点 + + @param m_ullint 无符号长整型值 + @param if_sid 新的节点有无id + @return 返回指向新节点的指针 + */ +Node *nodeWithULLInt(uint64_t m_ullint, _Bool if_sid) { Node *p_node; - unsigned long long *p_ullint = (unsigned long long *)malloc(sizeof(unsigned long long)); + unsigned long long *p_ullint = (uint64_t *)malloc(sizeof(uint64_t)); if(p_ullint == NULL){ return NULL; } @@ -38,6 +62,14 @@ Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) { return p_node; } + +/** + 直接使用一个双精度浮点值初始化一个新的节点 + + @param m_double 双精度浮点值 + @param if_sid 新的节点有无id + @return 返回指向新节点的指针 + */ Node *nodeWithDouble(double m_double, _Bool if_sid) { Node *p_node; double *p_double = (double *)malloc(sizeof(double)); @@ -50,6 +82,14 @@ Node *nodeWithDouble(double m_double, _Bool if_sid) { return p_node; } + +/** + 直接使用一个字符串值初始化一个新的节点 + + @param m_string 字符串值 + @param if_sid 新的节点有无id + @return 返回指向新节点的指针 + */ Node *nodeWithString(const char *m_string, _Bool if_sid) { Node *p_node; char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); @@ -62,6 +102,14 @@ Node *nodeWithString(const char *m_string, _Bool if_sid) { return p_node; } + +/** + 直接使用一个指针值初始化一个新的节点 + + @param m_pointer 指针值 + @param if_sid 新的节点有无id + @return 返回指向新节点的指针 + */ Node *nodeWithPointer(const void *m_pointer, _Bool if_sid) { Node *p_node = initNode(if_sid); initMallocValueForNode(p_node, POINTER, m_pointer); diff --git a/src/list/list_expand_update.c b/src/list/list_expand_update.c index a89f2b3..9a2772a 100644 --- a/src/list/list_expand_update.c +++ b/src/list/list_expand_update.c @@ -2,6 +2,14 @@ #include #include + +/** + 用一个整型值更新一个现有节点的值 + + @param p_node 指向目标节点的指针 + @param value 整型值 + @return 操作成功则返回0 + */ int updateValueWithIntForNode(Node *p_node,int value){ int *p_value = (int *)malloc(sizeof(int)); if(p_value == NULL){ @@ -13,8 +21,16 @@ int updateValueWithIntForNode(Node *p_node,int value){ return 0; } -int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){ - unsigned long long *p_value = (unsigned long long *)malloc(sizeof(unsigned long long)); + +/** + 用一个无符号长整型(8个字节)更新一个现有节点的值 + + @param p_node 指向目标节点的指针 + @param value 无符号长整型值 + @return 操作成功则返回0 + */ +int updateValueWithULLIntForNode(Node *p_node, uint64_t value){ + uint64_t *p_value = (uint64_t *)malloc(sizeof(uint64_t)); if(p_value == NULL){ return -1; } @@ -24,6 +40,14 @@ int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){ return 0; } + +/** + 用一个双精度浮点值更新一个现有节点的值 + + @param p_node 指向目标节点的指针 + @param value 双精度浮点值 + @return 操作成功则返回0 + */ int updateValueWithDoubleForNode(Node *p_node, double value){ double *p_value = (double *)malloc(sizeof(double)); if(p_value == NULL){ @@ -35,6 +59,14 @@ int updateValueWithDoubleForNode(Node *p_node, double value){ return 0; } + +/** + 用一个字符串值更新一个现有节点的值 + + @param p_node 指向目标节点的指针 + @param string 字符串值 + @return 操作成功则返回0 + */ int updateValueWithStringForNode(Node *p_node, char *string){ char *p_value = (char *)malloc(sizeof(strlen(string)) + 1); if(p_value == NULL){ @@ -46,6 +78,14 @@ int updateValueWithStringForNode(Node *p_node, char *string){ return 0; } + +/** + 用一个指针值更新一个现有节点的值 + + @param p_node 指向目标节点的指针 + @param pointer 指针值 + @return 操作成功则返回0 + */ int updateValueWithPointerForNode(Node *p_node, void *pointer){ free(p_node->value); p_node->value = pointer; diff --git a/src/list/list_find.c b/src/list/list_find.c index f07911c..c159265 100644 --- a/src/list/list_find.c +++ b/src/list/list_find.c @@ -1,7 +1,16 @@ #include #include +//如果ID模块可能启用则编译以下代码 #ifdef id_enable + +/** + 通过ID查找链表中符合条件的第一个节点 + + @param p_list 指向目标链表的指针 + @param s_id ID值 + @return 成功返回指向符合条件的节点的指针,不成功则返回NULL + */ Node *findByIdForNode(List *p_list, SID * s_id) { Node *ph_node = p_list->head; Node *pt_node = p_list->tail; @@ -29,7 +38,16 @@ Node *findByIdForNode(List *p_list, SID * s_id) { } #endif -Node *findByValue(List *p_list, unsigned int type, const void *value) { + +/** + 通过值来查找链表中符合条件的第一个节点 + + @param p_list 指向目标链表的指针 + @param type 值的类型 + @param value 值 + @return 成功返回指向符合条件的节点的指针,不成功则返回NULL + */ +Node *findByValue(List *p_list, uint type, const void *value) { Node *p_node = p_list->head; while (p_node != NULL) { if (p_node->type != type) { @@ -64,6 +82,14 @@ Node *findByValue(List *p_list, unsigned int type, const void *value) { return NULL; } +/** + 通过值来查找链表中符合条件的所有节点 + + @param p_list 指向目标链表的指针 + @param type 值的类型 + @param value 值 + @return 返回含有所有符合条件的节点的重组链表 + */ List *mply_findByValue(List *p_list, unsigned int type, const void *value) { List *f_list = initList(0); Node *p_node = p_list->head; diff --git a/src/list/list_info.c b/src/list/list_info.c index c1ac1dd..2404b22 100644 --- a/src/list/list_info.c +++ b/src/list/list_info.c @@ -1,10 +1,23 @@ #include #include -unsigned long long len(List *p_list) { + +/** + 返回链表的长度 + + @param p_list 指向目标链表的指针 + @return 返回目标链表的长度 + */ +uint64_t len(List *p_list) { return p_list->length; } +/** + 检查链表是否为空 + + @param p_list 指向目标链表的指针 + @return 目标链表为空返回1,不为空返回0 + */ int isListEmpty(List *p_list) { if (p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty. return 1; // But we should ensure that both of them are NULL when we diff --git a/src/list/list_init.c b/src/list/list_init.c index 39e9413..cf7ecef 100644 --- a/src/list/list_init.c +++ b/src/list/list_init.c @@ -1,12 +1,25 @@ #include #include -Node *initNode(_Bool if_sid) { + +/** + 创建一个新的节点,并为其分配内存空间 + + @param if_sid 新的节点是否带ID + @return 返回指向新的节点的内存地址指针 + */ +#ifdef id_enable +Node *initNode(_Bool if_sid) +#else +Node *initNode(void) +#endif +{ Node *p_node = (Node *)malloc(sizeof(Node)); if(p_node == NULL){ return NULL; } Node *prec_node = NULL; +//如果ID模块可能启用则编译以下代码 #ifdef id_enable if (if_sid)p_node->s_id = getS_id(LIST_NODE, 1); else p_node->s_id = NULL; @@ -15,6 +28,7 @@ Node *initNode(_Bool if_sid) { p_node->last = NULL; p_node->type = VOID; p_node->f_number = 0; +// 链表内存安全模式相关操作 if (if_safeModeForNode) { if_safeModeForNode = 0; prec_node = initNode(0); @@ -25,12 +39,24 @@ Node *initNode(_Bool if_sid) { return p_node; } -List *initList(_Bool if_sid) { +/** + 创建一个新的链表,并为其分配内存空间 + + @param if_sid 新的链表是否带ID + @return 返回指向新的链表的内存地址指针 + */ +#ifdef id_enable +List *initList(_Bool if_sid) +#else +List *initList(void) +#endif +{ Node *p_node = NULL; List *p_list = (List *)malloc(sizeof(List)); if(p_list == NULL){ return NULL; } +//如果ID模块可能启用则编译以下代码 #ifdef id_enable if(if_sid) p_list->s_id = getS_id(LIST, 1); else p_list->s_id = NULL; @@ -39,6 +65,7 @@ List *initList(_Bool if_sid) { p_list->tail = NULL; p_list->length = 0; p_list->p_lq = NULL; +// 如果简单链表模式启用则编译以下代码 #ifdef list_simple_h p_list->s_head = NULL; #endif @@ -52,6 +79,14 @@ List *initList(_Bool if_sid) { return p_list; } +/** + 为新的节点设定初始值 + + @param p_node 指向目标节点的指针 + @param type 值得类型 + @param p_value 指向目标值的内存空间的指针 + @return 执行成功则返回0 + */ inline int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) { p_node->type = type; p_node->value = (void *)p_value; diff --git a/src/list/list_sort.c b/src/list/list_sort.c index 0adea99..7b82d60 100644 --- a/src/list/list_sort.c +++ b/src/list/list_sort.c @@ -9,10 +9,10 @@ *内部函数: 通过节点中的值查找相关多个节点. *参数: type指明相关值的类型;value为指向储存相关值的内存的指针. *返回: 如果成功返回0,如果失败则返回-1.*/ -static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)); +static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node *f_node, Node *s_node)); /** - 链表排序函数,该函数不直接对用户开放 + 链表排序函数,该函数不直接对用户开放。采用快速排序的算法。 @param p_list 指向需要操作的链表的指针 @param begin 开始的节点的序号 @@ -20,7 +20,7 @@ static int sortList(List *p_list, unsigned long long begin, unsigned long long e @param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。 @return 成功进行操作则返回0 */ -static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)){ +static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node *f_node, Node *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; From 30323b5d63008abae3a28f68b1977c5f08684c56 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sun, 6 Jan 2019 22:50:06 +0800 Subject: [PATCH 12/18] Fixed. --- include/list/list_expand.h | 2 +- src/list/list_expand_callback.c | 38 ++++++++++++++++++++++----------- src/list/list_expand_get.c | 23 ++++++++++++++++++++ src/list/list_insert.c | 19 ++++++++++++++++- src/list/list_print.c | 33 ++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 14 deletions(-) diff --git a/include/list/list_expand.h b/include/list/list_expand.h index 5469a1e..0578247 100644 --- a/include/list/list_expand.h +++ b/include/list/list_expand.h @@ -173,7 +173,7 @@ List *newCReturn(void); /* *回调函数相关宏操作的辅助函数,用于给回调函数获取母函数传入的参数返提供便利 */ -unsigned long long getInfoForListThrough(List *expand_resources, int type); +uint64_t getInfoForListThrough(List *expand_resources, int type); diff --git a/src/list/list_expand_callback.c b/src/list/list_expand_callback.c index 6dca02e..8d3e93e 100644 --- a/src/list/list_expand_callback.c +++ b/src/list/list_expand_callback.c @@ -5,8 +5,9 @@ /** - 顺序遍历链表的操作函数,不对用户开放。回调函数返回-1退出遍历,返回1继续向后遍历,返回其他值则暂停向下遍历。 + 顺序遍历链表的操作函数。回调函数返回-1退出遍历,返回1继续向后遍历,返回其他值则暂停向下遍历。 回调函数接受一个整数、一个指向节点内容的指针、一个而外的参数链表,且回调函数需要返回一个链表,链表的第一个值作为函数的实际返回值。 + 一般配合宏使用 @param p_list 指向目标链表的指针 @param p_func 指向回调函数的指针 @return 返回参数链表 @@ -41,26 +42,34 @@ List *listThrough(List *p_list, List *(*p_func)(uint32_t, void *, List *), List return m_rtnlst; } -unsigned long long getInfoForListThrough(List *expand_resources, int type){ + +/** + 回调宏相关函数,type为1时用于回调函数获取当前参数列表的参数个数。 + type为2时用于获取当前节点在链表中的序号 + + @param expand_resources 指向参数列表的指针 + @param type 模式 + @return 返回需要获取的数据 + */ +uint64_t getInfoForListThrough(List *expand_resources, int type){ Node *p_node = NULL; if (type == 0) { p_node = findByIndexForNode(expand_resources, expand_resources->length-1); }else{ p_node = findByIndexForNode(expand_resources, expand_resources->length-2); } - return *((unsigned long long *)p_node->value); + return *((uint64_t *)p_node->value); } -int getByIntForNode(Node *p_node) { - if (p_node->type == INT) return *(int *)(p_node->value); - else return -1; -} - -unsigned int getByUIntForNode(Node *p_node){ - if (p_node->type == UINT) return *(unsigned int *)(p_node->value); - else return -1; -} +/** + 回调宏相关函数,构造回调函数的返回参数列表 + @param if_status 模式参数 + @param status 模式参数 + @param argc 参数说明 + @param ... 参数 + @return 指向构造的参数列表的指针 + */ List *newReturn(int if_status ,int status, char *argc, ...){ List *p_list = initList(0); if(if_status){ @@ -116,6 +125,11 @@ List *newReturn(int if_status ,int status, char *argc, ...){ return p_list; } +/** + 回调宏相关函数,用于回调函数不带而外参数的返回 + + @return 指向构造的参数列表的指针 + */ List *newCReturn(void){ return newReturn(1, 0, NULL); } diff --git a/src/list/list_expand_get.c b/src/list/list_expand_get.c index e8d5812..892491b 100644 --- a/src/list/list_expand_get.c +++ b/src/list/list_expand_get.c @@ -6,6 +6,29 @@ #include #endif +/** + 直接获取储存整型数据的节点的值 + + @param p_node 指向目标节点的指针 + @return 成功则返回对应整型值,失败返回0 + */ +int getByIntForNode(Node *p_node) { + if (p_node->type == INT) return *(int *)(p_node->value); + else return 0; +} + + +/** + 直接获取储存无符号整型数据的节点的值 + + @param p_node 指向目标节点的指针 + @return 成功则返回对应无符号整型值,失败返回0 + */ +unsigned int getByUIntForNode(Node *p_node){ + if (p_node->type == UINT) return *(unsigned int *)(p_node->value); + else return 0; +} + /** 直接获得节点中储存的字符串 diff --git a/src/list/list_insert.c b/src/list/list_insert.c index 038e763..521d8c8 100644 --- a/src/list/list_insert.c +++ b/src/list/list_insert.c @@ -4,7 +4,16 @@ #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){ @@ -34,7 +43,15 @@ int insertInHead(List *p_list, Node *p_node) { 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 @@ -48,7 +65,7 @@ int insertInTail(List *p_list, Node *p_node) { 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; diff --git a/src/list/list_print.c b/src/list/list_print.c index dce1f49..82d4c50 100644 --- a/src/list/list_print.c +++ b/src/list/list_print.c @@ -8,11 +8,18 @@ #include #endif +/** + 打印链表及链表中节点的相关数据 + + @param p_list 指向目标链表的指针 + @param priority 行缩进次数 + */ void printListInfo(List *p_list, int priority) { int i = 0; Node *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 @@ -32,6 +39,12 @@ void printListInfo(List *p_list, int priority) { } + +/** + 打印链表及其节点写详细信息 + + @param p_list 指向目标链表的指针 + */ void printList(List *p_list) { int if_nearLast = 0; Node *p_node = p_list->head; @@ -61,6 +74,13 @@ void printList(List *p_list) { printf("]"); } + +/** + 打印节点的信息 + + @param p_node 指向目标节点的指针 + @param priority 行缩进次数 + */ void printNodeInfo(Node *p_node, int priority) { int i; for (i = 0; i < priority; i++) printf(" "); @@ -96,6 +116,11 @@ void printNodeInfo(Node *p_node, int priority) { printf("}\n"); } +/** + 打印节点的详细信息 + + @param p_node 指向目标节点的指针 + */ void printNode(Node *p_node) { int i; printf("#NODE(location:%p",p_node); @@ -132,6 +157,13 @@ void printNode(Node *p_node) { printf("}\n"); } + +/** + 遍历链表并自定义打印节点信息 + + @param p_list 指向目标链表的指针 + @param func 指向自定义打印函数的指针,函数接受指向目标节点的指针 + */ void printListForCustom(List *p_list,void (*func)(void *value)){ printf("###LIST (LEN:%llu ",p_list->length); #ifdef id_enable @@ -141,6 +173,7 @@ void printListForCustom(List *p_list,void (*func)(void *value)){ 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); From a7b6538bac028cc966f2ed7d29c6c293036f83e8 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sun, 6 Jan 2019 22:50:32 +0800 Subject: [PATCH 13/18] Added and Fixed. --- include/block/block.h | 7 ++++ include/block/block_expand.h | 5 +++ include/block/block_type.h | 22 +++++++++++ include/stack/stack.h | 19 --------- include/stack/stack_expand.h | 14 ------- include/stack/stack_type.h | 31 --------------- src/block/block.c | 2 + src/block/block_expand.c | 2 + src/stack/stack.c | 74 ------------------------------------ src/stack/stack_expand.c | 62 ------------------------------ 10 files changed, 38 insertions(+), 200 deletions(-) create mode 100644 include/block/block.h create mode 100644 include/block/block_expand.h create mode 100644 include/block/block_type.h delete mode 100644 include/stack/stack.h delete mode 100644 include/stack/stack_expand.h delete mode 100644 include/stack/stack_type.h create mode 100644 src/block/block.c create mode 100644 src/block/block_expand.c delete mode 100644 src/stack/stack.c delete mode 100644 src/stack/stack_expand.c diff --git a/include/block/block.h b/include/block/block.h new file mode 100644 index 0000000..21e11a9 --- /dev/null +++ b/include/block/block.h @@ -0,0 +1,7 @@ +#ifndef block_h +#define block_h + +#include + + +#endif /* block_h */ diff --git a/include/block/block_expand.h b/include/block/block_expand.h new file mode 100644 index 0000000..5b33ca2 --- /dev/null +++ b/include/block/block_expand.h @@ -0,0 +1,5 @@ +#ifndef BLOCK_EXPAND_H +#define BLOCK_EXPAND_H + + +#endif /* block_expand_h */ diff --git a/include/block/block_type.h b/include/block/block_type.h new file mode 100644 index 0000000..074c4c2 --- /dev/null +++ b/include/block/block_type.h @@ -0,0 +1,22 @@ +#ifndef block_type_h +#define block_type_h + +#include +#ifdef id_enable +#include +#endif + +/* + *块的管理及操作的结构 + */ +typedef struct block{ + uint64_t size; + uint32_t carve; + void *data; +#ifdef id_enable + SID *s_id;//栈节点的ID +#endif +} SNode; + + +#endif /* block_type_h */ diff --git a/include/stack/stack.h b/include/stack/stack.h deleted file mode 100644 index 2274b40..0000000 --- a/include/stack/stack.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef stack_h -#define stack_h - -#include - -extern Stack *initStack(void); -extern SNode *initSNode(void); - -extern int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value); - -extern SNode *popStack(Stack *p_stack); - -extern int pushStack(Stack *p_stack, SNode *p_snode); - -extern int releaseStack(Stack *p_stack); - -extern int releaseSNode(SNode *p_snode); - -#endif /* stack_h */ diff --git a/include/stack/stack_expand.h b/include/stack/stack_expand.h deleted file mode 100644 index e16279c..0000000 --- a/include/stack/stack_expand.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef STACK_EXPAND_H -#define STACK_EXPAND_H - -SNode *snodeWithInt(int); -SNode *snodeWithDouble(double); -SNode *snodeWithString(char *); -SNode *snodeWithPointer(void *); - -int getValueByIntForSNode(SNode *); -double getValueByDoubleForSNode(SNode *); -char *getValueByStringForSNode(SNode *); -void *getValueByPointerForSNode(SNode *); - -#endif /* stack_expand_h */ diff --git a/include/stack/stack_type.h b/include/stack/stack_type.h deleted file mode 100644 index 05f43f8..0000000 --- a/include/stack/stack_type.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef stack_type_h -#define stack_type_h - -#ifdef id_enable -#include -#endif - -/* - *栈节点的管理及操作的结构 - */ -typedef struct stack_node{ - unsigned int type;//栈节点的类型 - void *value;//值指针 - struct stack_node *next;//下一个栈节点 -#ifdef id_enable - SID *s_id;//栈节点的ID -#endif -} SNode; - -/* - *栈的管理及操作的结构 - */ -typedef struct stack{ - unsigned long long length;//栈的长度 - SNode *top;//指向栈顶的栈节点 -#ifdef id_enable - SID *s_id;//栈的ID -#endif -} Stack; - -#endif /* stack_type_h */ diff --git a/src/block/block.c b/src/block/block.c new file mode 100644 index 0000000..91b351f --- /dev/null +++ b/src/block/block.c @@ -0,0 +1,2 @@ +#include + diff --git a/src/block/block_expand.c b/src/block/block_expand.c new file mode 100644 index 0000000..0284594 --- /dev/null +++ b/src/block/block_expand.c @@ -0,0 +1,2 @@ +#include +#include diff --git a/src/stack/stack.c b/src/stack/stack.c deleted file mode 100644 index ad66956..0000000 --- a/src/stack/stack.c +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include - -Stack *initStack(void) { - Stack *p_stack = (Stack *)malloc(sizeof(Stack)); -#ifdef id_enable - p_stack->s_id = getS_id(STACK, 1); -#endif - p_stack->length = 0; - p_stack->top = NULL; - return p_stack; -} - -SNode *initSNode(void) { - SNode *p_snode = (SNode *)malloc(sizeof(SNode)); -#ifdef id_enable - p_snode->s_id = getS_id(STACK_NODE, 1); -#endif - p_snode->next = NULL; - p_snode->value = NULL; - return p_snode; -} - -SNode *popStack(Stack *p_stack) { - if (p_stack->top != NULL) { - SNode *p_snode = p_stack->top; - p_stack->top = p_snode->next; - p_snode->next = NULL; - p_stack->length -= 1; - return p_snode; - } - else return NULL; -} - -int pushStack(Stack *p_stack, SNode *p_snode) { - SNode *pn_snode = p_stack->top; - p_stack->top = p_snode; - p_snode->next = pn_snode; - p_stack->length -= 1; - return 0; -} - -int releaseStack(Stack *p_stack) { - SNode *p_sndoe = p_stack->top; - while (p_sndoe != NULL) { - SNode *pl_snode = p_sndoe; - p_sndoe = p_sndoe->next; - releaseSNode(pl_snode); - } -#ifdef id_enable - freeS_id(p_stack->s_id); -#endif - p_stack->top = NULL; - p_stack->length = 0; - free(p_stack); - return 0; -} - -int releaseSNode(SNode *p_snode) { -#ifdef id_enable - freeS_id(p_snode->s_id); -#endif - free(p_snode->value); - p_snode->value = NULL; - p_snode->type = VOID; - free(p_snode); - return 0; -} - -int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value) { - p_snode->type = type; - p_snode->value = value; - return 0; -} diff --git a/src/stack/stack_expand.c b/src/stack/stack_expand.c deleted file mode 100644 index 39287fd..0000000 --- a/src/stack/stack_expand.c +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include - -SNode *snodeWithInt(int temp) { - SNode *p_snode = initSNode(); - int *p_temp = (int *)malloc(sizeof(int)); - if(p_temp == NULL){ - return NULL; - } - *p_temp = temp; - initMallocValueForSNode(p_snode, INT, p_temp); - return p_snode; -} - -SNode *snodeWithDouble(double temp) { - SNode *p_snode = initSNode(); - double *p_temp = (double *)malloc(sizeof(double)); - if(p_temp == NULL){ - return NULL; - } - *p_temp = temp; - initMallocValueForSNode(p_snode, DOUBLE, p_temp); - return p_snode; -} - -SNode *snodeWithString(char *temp) { - SNode *p_snode = initSNode(); - char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); - if(p_temp == NULL){ - return NULL; - } - strcpy(p_temp, temp); - initMallocValueForSNode(p_snode, STRING, p_temp); - return p_snode; -} - -SNode *snodeWithPointer(void *temp) { - SNode *p_snode = initSNode(); - initMallocValueForSNode(p_snode, POINTER, temp); - return p_snode; -} - -int getValueByIntForSNode(SNode *p_snode) { - if (p_snode->type == INT) return *(int *)p_snode->value; - else return -1; -} - -double getValueByDoubleForSNode(SNode *p_snode) { - if (p_snode->type == DOUBLE) return *(double *)p_snode->value; - else return -1; -} - -char *getValueByStringForSNode(SNode *p_snode) { - if (p_snode->type == STRING) return (char *)p_snode->value; - else return NULL; -} - -void *getValueByPointerForSNode(SNode *p_snode) { - if (p_snode->type == POINTER) return (void *)p_snode->value; - else return NULL; -} From 14ec30b0beeb3ef10e7b001cc209a807ad009624 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 12 Jan 2019 01:00:51 +0800 Subject: [PATCH 14/18] Struct modified. --- include/block/block_expand.h | 4 +- include/block/block_print.h | 5 + include/block/block_type.h | 3 +- include/communicate/communicate.h | 280 +--------------- include/communicate/communicate_file.h | 269 +++++++++++++++ include/communicate/communicate_type.h | 77 +++++ include/list/list_expand_1.h | 4 +- src/communicate/communicate.c | 433 +------------------------ src/communicate/dfile/dfile_in.c | 49 +++ src/communicate/dfile/dfile_info.c | 13 + src/communicate/dfile/dfile_init.c | 24 ++ src/communicate/dfile/dfile_insert.c | 11 + src/communicate/dfile/dfile_out.c | 15 + src/communicate/dfile/dfile_release.c | 13 + src/communicate/std/std_find.c | 14 + src/communicate/std/std_in.c | 59 ++++ src/communicate/std/std_info.c | 44 +++ src/communicate/std/std_init.c | 31 ++ src/communicate/std/std_insert.c | 20 ++ src/communicate/std/std_out.c | 29 ++ src/communicate/std/std_relaese.c | 13 + src/communicate/stdb/stdb_in.c | 6 + src/communicate/stdb/stdb_init.c | 30 ++ src/communicate/stdb/stdb_out.c | 24 ++ src/communicate/stdb/stdb_release.c | 12 + src/communicate/stdc/stdc_in.c | 14 + src/communicate/stdc/stdc_info.c | 15 + src/communicate/stdc/stdc_init.c | 6 + src/communicate/stdc/stdc_out.c | 6 + src/communicate/stdc/stdc_release.c | 12 + src/communicate/stdcvt/stcvt_in.c | 25 ++ src/communicate/stdcvt/stdcvt_out.c | 23 ++ 32 files changed, 867 insertions(+), 716 deletions(-) create mode 100644 include/block/block_print.h create mode 100644 include/communicate/communicate_file.h create mode 100644 include/communicate/communicate_type.h create mode 100644 src/communicate/dfile/dfile_in.c create mode 100644 src/communicate/dfile/dfile_info.c create mode 100644 src/communicate/dfile/dfile_init.c create mode 100644 src/communicate/dfile/dfile_insert.c create mode 100644 src/communicate/dfile/dfile_out.c create mode 100644 src/communicate/dfile/dfile_release.c create mode 100644 src/communicate/std/std_find.c create mode 100644 src/communicate/std/std_in.c create mode 100644 src/communicate/std/std_info.c create mode 100644 src/communicate/std/std_init.c create mode 100644 src/communicate/std/std_insert.c create mode 100644 src/communicate/std/std_out.c create mode 100644 src/communicate/std/std_relaese.c create mode 100644 src/communicate/stdb/stdb_in.c create mode 100644 src/communicate/stdb/stdb_init.c create mode 100644 src/communicate/stdb/stdb_out.c create mode 100644 src/communicate/stdb/stdb_release.c create mode 100644 src/communicate/stdc/stdc_in.c create mode 100644 src/communicate/stdc/stdc_info.c create mode 100644 src/communicate/stdc/stdc_init.c create mode 100644 src/communicate/stdc/stdc_out.c create mode 100644 src/communicate/stdc/stdc_release.c create mode 100644 src/communicate/stdcvt/stcvt_in.c create mode 100644 src/communicate/stdcvt/stdcvt_out.c diff --git a/include/block/block_expand.h b/include/block/block_expand.h index 5b33ca2..c1140a4 100644 --- a/include/block/block_expand.h +++ b/include/block/block_expand.h @@ -1,5 +1,5 @@ -#ifndef BLOCK_EXPAND_H -#define BLOCK_EXPAND_H +#ifndef block_expand_h +#define block_expand_h #endif /* block_expand_h */ diff --git a/include/block/block_print.h b/include/block/block_print.h new file mode 100644 index 0000000..f92e524 --- /dev/null +++ b/include/block/block_print.h @@ -0,0 +1,5 @@ +#ifndef block_print_h +#define block_print_h + + +#endif /* block_print_h */ diff --git a/include/block/block_type.h b/include/block/block_type.h index 074c4c2..8b47b61 100644 --- a/include/block/block_type.h +++ b/include/block/block_type.h @@ -11,12 +11,13 @@ */ typedef struct block{ uint64_t size; + uint64_t m_size; uint32_t carve; void *data; #ifdef id_enable SID *s_id;//栈节点的ID #endif -} SNode; +} Block; #endif /* block_type_h */ diff --git a/include/communicate/communicate.h b/include/communicate/communicate.h index 4136b86..ab7be74 100644 --- a/include/communicate/communicate.h +++ b/include/communicate/communicate.h @@ -1,285 +1,7 @@ #ifndef communicate_h #define communicate_h -/* - *文件头信息的管理及操作的结构 - */ -typedef struct file_head{ - char head_test[18];//数据文件头部的验证信息 - uint32_t data_num;//数据文件中的标准数据结构的数目 -}F_HEAD; - -/* - *数据文件的管理及操作的结构 - */ -typedef struct data_file{ - FILE *fp;//数据文件 - F_HEAD *pf_head;//数据文件头 - List *pf_stdlst;//数据文件的标志数据结构的储存链表 -}D_FILE; - -/* - *标准数据结构的管理及操作的结构 - */ -typedef struct standard_data_blocks{ - uint16_t type;//数据块的类型 - uint32_t location;//数据块在数据文件中的定位 - char *sid;//数据块的ID - _Bool if_data;//数据块是否赋值 - unsigned int blocks_num;//数据块字节大小 - char *buff;//指向数据块储存值内存空间的指针 -}STD_BLOCKS; - -/* - *标准数据结构中数据块的连接关系的管理及操作的结构 - */ -typedef struct standard_data_connection{ - uint32_t location;//数据块链接关系结构在文件中的定位 - char *f_sid;//前一个数据块的ID - char *s_sid;//后一个数据块的ID -}STD_CTN; - -/* - *标准数据结构头的管理及操作的结构 - */ -typedef struct standard_data_head{ - uint32_t data_blk_num;//数据块的数目 - uint32_t data_ctn_num;//数据块链接关系结构的数目 -}STD_HEAD; - -/* - *标准数据结构的管理及操作的结构 - */ -typedef struct standard_data{ - SID *s_id;//标准数据结构的ID - int read_data;//标准数据结构是否已经读取完整 - uint16_t type;//标准数据结构所对应的类型 - uint32_t size;//标准数据结构在数据文件中的大小 - uint32_t location;//标准数据结构的头在数据文件中的定位 - _Bool lock;//标准数据文件是否被锁住 - List *pd_blocklst;//数据块储存链表 - List *pd_ctnlst;//数据块连接关系结构的储存链表 -}STD_DATA; - -/* - *消息的管理及操作的结构 - */ -typedef struct message{ - SID *p_sid;//消息的ID - time_t time;//消息的产生时间 - char titile[16];//消息标题 - unsigned long size;//消息的大小 - char content[0];//消息的正文 -}MSG; - - - - -/************************************************ - 相关结构体初始化: 初始化相关结构体有关函数 - ************************************************/ - -/* - *以写的方式初始化数据文件管理结构 - *参数: route指示数据文件路径 - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern D_FILE *initDataFileForWrite(char *route); - -/* - *以读的方式初始化数据文件管理结构 - *参数: route指示数据文件路径 - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern D_FILE *initDataFileForRead(char *route); - -/* - *初始化数据块管理结构 - *参数: type指示数据块储存数据的数据类型,data_size指示数据块储存数据的大小 - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size); - -/* - *初始化数据块链接关系管理结构 - *参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID. - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid); - -/* - *初始化标准数据结构管理结构 - *参数: type指示标准数据结构所储存的数据结构的数据类型, s_id指示所储存的数据结构的ID, - 若s_id为NULL,则另外分配一个ID.为了方便管理,标准数据结构必须有ID. - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern STD_DATA *initStandardData(uint16_t type, SID *s_id); - - - - - -/************************************************ - 相关结构体的组织: 组织相关结构体有关函数 - ************************************************/ - -/* - *为数据块添加数据 - *参数: data为指向所添加数据所在内存空间的指针 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data); - -/* - *为数据文件添加标准数据结构 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); - -/* - *为标准数据结构添加数据块 - *参数: type指示所添加数据的数据类型, data为指向所添加数据所在内存空间的指针, data_size指示所添加数据的大小 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size); - -/* - *为标准数据结构添加数据块链接关系结构体 - *参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID. - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); - - - - - -/************************************************ - 数据文件管理结构的整体写入与读出: 对数据文件管理结构的操作 - ************************************************/ - -/* - *将数据文件管理结构写入到相关数据文件中,以储存. - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int dataFileWriteIn(D_FILE *p_dfile); - -/* - *将相关数据文件中的内容,读出到数据文件管理结构中,等待操作. - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int dataFileReadOut(D_FILE *p_dfile); - - - - - - - -/************************************************ - 相关结构的释放操作: 释放相关结构体所占内存空间的相关函数 - ************************************************/ - -/* - *释放数据块所占内存空间 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int releaseSTDBlocks(STD_BLOCKS *p_stdb); - -/* - *释放标准数据结构管理结构所占的内存空间 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int releaseStandardData(STD_DATA *p_std); - -/* - *释放数据块链接关系管理结构所占的内存空间 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int releaseSTDConnection(STD_CTN *p_stdc); - -/* - *释放数据文件管理结构所占的内存空间 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int releaseDFile(D_FILE *p_file); - - - - - -/************************************************ - 结构类型的转换: 其他数据结构与标准数据结构的转换相关函数 - ************************************************/ - -/* - *将链表转化为标准数据结构 - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern STD_DATA *listToSTD(List *); - -/* - *将标准数据结构转换成链表 - *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. - */ -extern List *standardDataToList(STD_DATA *); - -//STD_DATA *stackToSTD(Stack *); - -//STD_DATA *treeToSTD(Tree *); - - - - - -/************************************************ - 标准数据结构的随机存取: 标准数据结构的随机存取相关函数 - ************************************************/ - -/* - *读取数据文件的简略信息,为随机存取准备必要信息 - *说明: 该函数只会在数据文件管理结构中建立一个框架,不会读入实际的数据块以及数据块链接关系. - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int readDataFileInfo(D_FILE *p_dfile); - -/* - *读取数据文件中的特定标准数据结构 - *参数: p_std为指向框架中的相关标准数据所在内存空间的指针 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int readStandardData(D_FILE *p_dfile, STD_DATA *p_std); - -/* - *读取数据文件中的特定标准数据结构中的数据块 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int readSTDBlocks(STD_BLOCKS *p_stdb); - -/* - *读取文件头,检验文件是否为数据文件 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int checkIfDataFile(D_FILE *p_dfile); - -/* - *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构 - *返回: 处理成功则返回0,不成功则返回-1. - */ -extern int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); - - - - - -/************************************************ - 标准数据结构信息: 获取标准数据结构信息相关函数 - ************************************************/ - -/* - *打印标准数据结构信息 - */ -extern void printStandardData(void *value); +#include diff --git a/include/communicate/communicate_file.h b/include/communicate/communicate_file.h new file mode 100644 index 0000000..55514bd --- /dev/null +++ b/include/communicate/communicate_file.h @@ -0,0 +1,269 @@ +#ifndef communicate_file_h +#define communicate_file_h + +#include + +/************************************************ + 相关结构体初始化: 初始化相关结构体有关函数 + ************************************************/ + +/* + *以写的方式初始化数据文件管理结构 + *参数: route指示数据文件路径 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern D_FILE *initDataFileForWrite(char *route); + +/* + *以读的方式初始化数据文件管理结构 + *参数: route指示数据文件路径 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern D_FILE *initDataFileForRead(char *route); + +/* + *初始化数据块管理结构 + *参数: type指示数据块储存数据的数据类型,data_size指示数据块储存数据的大小 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size); + +/* + *初始化数据块链接关系管理结构 + *参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID. + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid); + +/* + *初始化标准数据结构管理结构 + *参数: type指示标准数据结构所储存的数据结构的数据类型, s_id指示所储存的数据结构的ID, + 若s_id为NULL,则另外分配一个ID.为了方便管理,标准数据结构必须有ID. + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_DATA *initStandardData(uint16_t type, SID *s_id); + + + + + +/************************************************ + 相关结构体的组织: 组织相关结构体有关函数 + ************************************************/ + +/* + *为数据块添加数据 + *参数: data为指向所添加数据所在内存空间的指针 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data); + +/* + *为数据文件添加标准数据结构 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std); + +/* + *为标准数据结构添加数据块 + *参数: type指示所添加数据的数据类型, data为指向所添加数据所在内存空间的指针, data_size指示所添加数据的大小 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size); + +/* + *为标准数据结构添加数据块链接关系结构体 + *参数: f_sid指示第一个数据块的SID,s_sid指示第二个数据块的SID. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid); + + + + + +/************************************************ + 数据文件管理结构的整体写入与读出: 对数据文件管理结构的操作 + ************************************************/ + +/* + *将数据文件管理结构写入到相关数据文件中,以储存. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataFileWriteIn(D_FILE *p_dfile); + +/* + *将相关数据文件中的内容,读出到数据文件管理结构中,等待操作. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int dataFileReadOut(D_FILE *p_dfile); + + + + + + + +/************************************************ + 相关结构的释放操作: 释放相关结构体所占内存空间的相关函数 + ************************************************/ + +/* + *释放数据块所占内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseSTDBlocks(STD_BLOCKS *p_stdb); + +/* + *释放标准数据结构管理结构所占的内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseStandardData(STD_DATA *p_std); + +/* + *释放数据块链接关系管理结构所占的内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseSTDConnection(STD_CTN *p_stdc); + +/* + *释放数据文件管理结构所占的内存空间 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int releaseDFile(D_FILE *p_file); + + + + + +/************************************************ + 结构类型的转换: 其他数据结构与标准数据结构的转换相关函数 + ************************************************/ + +/* + *将链表转化为标准数据结构 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern STD_DATA *listToSTD(List *); + +/* + *将标准数据结构转换成链表 + *返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL. + */ +extern List *standardDataToList(STD_DATA *); + +//STD_DATA *stackToSTD(Stack *); + +//STD_DATA *treeToSTD(Tree *); + + + + + +/************************************************ + 标准数据结构的随机存取: 标准数据结构的随机存取相关函数 + ************************************************/ + +/* + *读取数据文件的简略信息,为随机存取准备必要信息 + *说明: 该函数只会在数据文件管理结构中建立一个框架,不会读入实际的数据块以及数据块链接关系. + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int readDataFileInfo(D_FILE *p_dfile); + +/* + *读取数据文件中的特定标准数据结构 + *参数: p_std为指向框架中的相关标准数据所在内存空间的指针 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int readStandardData(D_FILE *p_dfile, STD_DATA *p_std); + +/* + *读取数据文件中的特定标准数据结构中的数据块 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int readSTDBlocks(STD_BLOCKS *p_stdb); + +/* + *读取文件头,检验文件是否为数据文件 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int checkIfDataFile(D_FILE *p_dfile); + +/* + *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构 + *返回: 处理成功则返回0,不成功则返回-1. + */ +extern int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid); + + + + + +/************************************************ + 标准数据结构信息: 获取标准数据结构信息相关函数 + ************************************************/ + +/* + *打印标准数据结构信息 + */ +extern void printStandardData(void *value); + +/* + *计算标准数据结构在文件中占用的空间,以字节为单位. + */ +uint32_t calStandardData(STD_DATA *p_std); + + + + +/************************************************ + 相关回调函数声明 + ************************************************/ + +/* + *数据文件管理结构中标准数据结构管理结构的简略信息的写入函数 + */ +__CALLBACK_STATE(StandardDataInfoWrite); + +/* + *数据文件管理结构中标准数据结构管理结构的内容的写入函数 + */ +__CALLBACK_STATE(StandardDataWrite); + +/* + *标准数据结构管理结构中的数据块链接关系管理结构的写入函数 + */ +__CALLBACK_STATE(StandardDConnectionWrite); + +/* + *标准数据结构管理结构中的数据块管理结构的写入函数 + */ +__CALLBACK_STATE(StandardDBlockWrite); + +/* + *数据文件管理结构的读出函数的回调函数声明 + */ +__CALLBACK_STATE(dataFileReadOut); + +/* + *计算数据块链接关系在文件中的大小 + */ +__CALLBACK_STATE(calStandardDataCTN); + +/* + *计算数据块在文件中的大小 + */ +__CALLBACK_STATE(calStandardDataBLK); + +/* + *将标准数据结构转换成链表的回调函数 + */ +__CALLBACK_STATE(StandardDataToList); + +/* + *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数 + */ +__CALLBACK_STATE(findStandardDataBySid); + +#endif /* communicate_file_h */ diff --git a/include/communicate/communicate_type.h b/include/communicate/communicate_type.h new file mode 100644 index 0000000..37697ca --- /dev/null +++ b/include/communicate/communicate_type.h @@ -0,0 +1,77 @@ +#ifndef communicate_type_h +#define communicate_type_h + +#include + +/* + *文件头信息的管理及操作的结构 + */ +typedef struct file_head{ + char head_test[18];//数据文件头部的验证信息 + uint32_t data_num;//数据文件中的标准数据结构的数目 +}F_HEAD; + +/* + *数据文件的管理及操作的结构 + */ +typedef struct data_file{ + FILE *fp;//数据文件 + F_HEAD *pf_head;//数据文件头 + List *pf_stdlst;//数据文件的标志数据结构的储存链表 +}D_FILE; + +/* + *标准数据结构的管理及操作的结构 + */ +typedef struct standard_data_blocks{ + uint16_t type;//数据块的类型 + uint32_t location;//数据块在数据文件中的定位 + char *sid;//数据块的ID + _Bool if_data;//数据块是否赋值 + unsigned int blocks_num;//数据块字节大小 + char *buff;//指向数据块储存值内存空间的指针 +}STD_BLOCKS; + +/* + *标准数据结构中数据块的连接关系的管理及操作的结构 + */ +typedef struct standard_data_connection{ + uint32_t location;//数据块链接关系结构在文件中的定位 + char *f_sid;//前一个数据块的ID + char *s_sid;//后一个数据块的ID +}STD_CTN; + +/* + *标准数据结构头的管理及操作的结构 + */ +typedef struct standard_data_head{ + uint32_t data_blk_num;//数据块的数目 + uint32_t data_ctn_num;//数据块链接关系结构的数目 +}STD_HEAD; + +/* + *标准数据结构的管理及操作的结构 + */ +typedef struct standard_data{ + SID *s_id;//标准数据结构的ID + int read_data;//标准数据结构是否已经读取完整 + uint16_t type;//标准数据结构所对应的类型 + uint32_t size;//标准数据结构在数据文件中的大小 + uint32_t location;//标准数据结构的头在数据文件中的定位 + _Bool lock;//标准数据文件是否被锁住 + List *pd_blocklst;//数据块储存链表 + List *pd_ctnlst;//数据块连接关系结构的储存链表 +}STD_DATA; + +/* + *消息的管理及操作的结构 + */ +typedef struct message{ + SID *p_sid;//消息的ID + time_t time;//消息的产生时间 + char titile[16];//消息标题 + unsigned long size;//消息的大小 + char content[0];//消息的正文 +}MSG; + +#endif /* communicate_type_h */ diff --git a/include/list/list_expand_1.h b/include/list/list_expand_1.h index a8e4028..ea4d002 100644 --- a/include/list/list_expand_1.h +++ b/include/list/list_expand_1.h @@ -166,12 +166,12 @@ /* *若快速声明回调函数则使用该宏 *参数: name为回调函数名.*/ -#define __CALLBACK_STATE(name) static List *_do##name(unsigned int, void *, List *) +#define __CALLBACK_STATE(name) List *_do##name(unsigned int, void *, List *) /* *若快速定义回调函数则使用该宏 *参数: name为回调函数名.*/ -#define __CALLBACK_DEFINE(name) static List *_do##name(unsigned int type, void *value, List *expand_resources) +#define __CALLBACK_DEFINE(name) List *_do##name(unsigned int type, void *value, List *expand_resources) /* *若传递回调函数指针则使用该宏 diff --git a/src/communicate/communicate.c b/src/communicate/communicate.c index 6966348..d97bf39 100644 --- a/src/communicate/communicate.c +++ b/src/communicate/communicate.c @@ -5,330 +5,8 @@ #include #include #include +#include -/* - *计算标准数据结构在文件中占用的空间,以字节为单位. - */ -static uint32_t calStandardData(STD_DATA *p_std); - -/* - *数据文件管理结构中标准数据结构管理结构的简略信息的写入函数 - */ -__CALLBACK_STATE(StandardDataInfoWrite); - -/* - *数据文件管理结构中标准数据结构管理结构的内容的写入函数 - */ -__CALLBACK_STATE(StandardDataWrite); - -/* - *标准数据结构管理结构中的数据块链接关系管理结构的写入函数 - */ -__CALLBACK_STATE(StandardDConnectionWrite); - -/* - *标准数据结构管理结构中的数据块管理结构的写入函数 - */ -__CALLBACK_STATE(StandardDBlockWrite); - -/* - *数据文件管理结构的读出函数的回调函数声明 - */ -__CALLBACK_STATE(dataFileReadOut); - -/* - *计算数据块链接关系在文件中的大小 - */ -__CALLBACK_STATE(calStandardDataCTN); - -/* - *计算数据块在文件中的大小 - */ -__CALLBACK_STATE(calStandardDataBLK); - -/* - *将标准数据结构转换成链表的回调函数 - */ -__CALLBACK_STATE(StandardDataToList); - -/* - *通过标准数据结构的ID,在数据文件中读入特定的标准数据结构函数的回调函数 - */ -__CALLBACK_STATE(findStandardDataBySid); - - - -STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){ - STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); - if(p_sid != NULL){ - p_stdb->sid = s_idToASCIIString(p_sid); - } - else p_stdb->sid = NULL; - p_stdb->if_data = 0; - p_stdb->location = 0; - uint32_t blocks_num = (uint32_t)(data_size/sizeof(char)); - p_stdb->blocks_num = blocks_num; - p_stdb->type = type; - p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num); - return p_stdb; -} - -int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data){ - char *t_data = (char *)data; - /*unsigned int data_size = sizeof(data);*/ - for(int i = 0; i < p_stdb->blocks_num; i++){ - p_stdb->buff[i] = t_data[i]; - } - p_stdb->if_data = 1; - return 0; -} - -STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){ - STD_CTN *p_stdc = (STD_CTN *)malloc(sizeof(STD_CTN)); - p_stdc->f_sid = s_idToASCIIString(f_sid); - p_stdc->s_sid = s_idToASCIIString(s_sid); - p_stdc->location = 0; - return p_stdc; -} - -STD_DATA *initStandardData(uint16_t type, SID *s_id){ - STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA)); - p_std->pd_blocklst = initList(0); - p_std->pd_ctnlst = initList(0); - p_std->lock = 0; - p_std->type = type; - p_std->size = 0; - p_std->location = 0; - p_std->read_data = 0; - - if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2); - else p_std->s_id = copyS_id(s_id); - setSidToASCIIString(p_std->s_id); - return p_std; -} - -int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){ - if (p_std->lock) return -1; - STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size); - dataForStandardDBlock(p_stdb, data); - insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb,0)); - return 0; -} - -int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){ - if (p_std->lock) return -1; - STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid); - insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb,0)); - return 0; -} - -D_FILE *initDataFileForWrite(char *route){ - D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE)); - p_dfile->fp = fopen(route, "wb"); - p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); - strcpy(p_dfile->pf_head->head_test,"ZESTDLIB_STDDFILE"); - p_dfile->pf_head->data_num = 0; - p_dfile->pf_stdlst = initList(0); - return p_dfile; -} - -D_FILE *initDataFileForRead(char *route){ - D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE)); - p_dfile->fp = fopen(route, "rb"); - p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); - p_dfile->pf_head->data_num = 0; - p_dfile->pf_stdlst = initList(0); - return p_dfile; -} - -int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ - insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0)); - p_dfile->pf_head->data_num = (uint32_t)p_dfile->pf_stdlst->length; - return 0; -} - -int dataFileWriteIn(D_FILE *p_dfile){ - - fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp); - fwrite(&p_dfile->pf_head->data_num, sizeof(uint32_t), 1, p_dfile->fp); - fwrite("STDINFO", sizeof(char), 8, p_dfile->fp); - listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataInfoWrite), __SEND_ARG("%p", p_dfile->fp)); - fwrite("STDLST", sizeof(char), 7, p_dfile->fp); - listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataWrite), __SEND_ARG("%p", p_dfile->fp)); - return 0; -} - -__CALLBACK_DEFINE(StandardDataInfoWrite){ - FILE *fp = __ARGS_P(0, FILE); - STD_DATA *p_std = __VALUE(STD_DATA *); - fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp); - fwrite(&p_std->type, sizeof(uint16_t), 1, fp); - uint32_t std_size = calStandardData(p_std); - p_std->size = std_size; - fwrite(&std_size, sizeof(uint32_t), 1, fp); - return __CRETURN__; -} - -__CALLBACK_DEFINE(StandardDataWrite){ - FILE *fp = __ARGS_P(0, FILE); - STD_DATA *p_std = __VALUE(STD_DATA *); - fwrite("STD", sizeof(char), 4, fp); - fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp); - fwrite(&p_std->pd_ctnlst->length, sizeof(uint32_t), 1, fp); - fwrite(&p_std->pd_blocklst->length, sizeof(uint32_t), 1, fp); - listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(StandardDConnectionWrite), __SEND_ARG("%p", fp)); - listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDBlockWrite), __SEND_ARG("%p", fp)); - return __CRETURN__; -} - -__CALLBACK_DEFINE(StandardDConnectionWrite){ - FILE *fp = __ARGS_P(0, FILE); - STD_CTN *p_stdc = __VALUE(STD_CTN *); - fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp); - fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp); - return __CRETURN__; -} - -__CALLBACK_DEFINE(StandardDBlockWrite){ - STD_BLOCKS *p_stdb = value; - FILE *fp = __ARGS_P(0, FILE); - unsigned long blocks_num = p_stdb->blocks_num; - int if_sid = 0; - if(p_stdb->sid != NULL){ - if_sid = 1; - fwrite(&if_sid, sizeof(int), 1, fp); - fwrite(p_stdb->sid, sizeof(char), SID_LEN, fp); - } - else{ - fwrite(&if_sid, sizeof(int), 1, fp); - } - fwrite(&p_stdb->type, sizeof(uint16_t), 1, fp); - fwrite(&blocks_num, sizeof(uint32_t), 1, fp); - fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp); - return __CRETURN__; -} - -STD_DATA *listToSTD(List *p_list){ - Node *p_node = p_list->head; - STD_DATA *p_std = NULL; - if (p_list->s_id != NULL){ - p_std = initStandardData(LIST,p_list->s_id); - } - else p_std = initStandardData(LIST, NULL); - while (p_node != NULL) { - if(p_node->type == HOLE) continue; - uint32_t data_size = 0; - if(p_node->type == INT) data_size = sizeof(int); - else if (p_node->type == DOUBLE) data_size = sizeof(double); - else if (p_node->type == STRING) data_size = (uint32_t)strlen((char *)p_node->value) + 1; - else data_size = sizeof(void *); - standardDataAddBlock(p_std, p_node->s_id, p_node->type, p_node->value, data_size); - p_node = p_node->next; - } - return p_std; -} - -int dataFileReadOut(D_FILE *p_dfile){ - if(!readDataFileInfo(p_dfile)){ - listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(dataFileReadOut), __SEND_ARG("%p", p_dfile)); - - } - return -1; -} - -__CALLBACK_DEFINE(dataFileReadOut){ - D_FILE *p_dfile = __ARGS_P(0, D_FILE); - readStandardData(p_dfile, __VALUE(STD_DATA *)); - return __CRETURN__; -} - -int releaseSTDConnection(STD_CTN *p_stdc){ - free(p_stdc->f_sid); - free(p_stdc->s_sid); - free(p_stdc); - return 0; -} - -int releaseSTDBlocks(STD_BLOCKS *p_stdb){ - free(p_stdb->buff); - free(p_stdb->sid); - free(p_stdb); - return 0; -} - -int releaseStandardData(STD_DATA *p_std){ - releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks); - releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection); - freeS_id(p_std->s_id); - free(p_std); - return 0; -} - -int releaseDFile(D_FILE *p_dfile){ - releaseListForCustom(p_dfile->pf_stdlst, (int (*)(void *))releaseStandardData); - fclose(p_dfile->fp); - free(p_dfile->pf_head); - free(p_dfile); - return 0; -} - -List *standardDataToList(STD_DATA *p_std){ - List *p_list = initList(0); - listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDataToList), __SEND_ARG("%p", p_list)); - return p_list; -} - -__CALLBACK_DEFINE(StandardDataToList){ - List *p_list = __ARGS_P(0, List); - STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *); - Node *p_node = initNode(0); - p_node->s_id = setS_idWithString(p_stdb->sid); - p_node->type = p_stdb->type; - p_node->value = malloc(sizeof(p_stdb->blocks_num)); - memcpy(p_node->value, p_stdb->buff, sizeof(p_stdb->blocks_num)); - insertInTail(p_list, p_node); - return __CRETURN__; -} - -uint32_t calStandardData(STD_DATA *p_std){ - List *rtn_lst = NULL; - uint32_t size = 4 + sizeof(unsigned long long) * 2; - if(p_std->s_id != NULL) size += SID_LEN * sizeof(char); - rtn_lst = listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(calStandardDataCTN), __SEND_ARG("%d", size)); - if(rtn_lst != NULL){ - size = __RTN_ARGS(rtn_lst, 0, uint32_t); - releaseList(rtn_lst); - } - rtn_lst = listThrough(p_std->pd_blocklst, __CALLBACK_CALL(calStandardDataBLK), __SEND_ARG("%d", size)); - if(rtn_lst != NULL){ - size = __RTN_ARGS(rtn_lst, 0, uint32_t); - releaseList(rtn_lst); - } - return size; -} - -__CALLBACK_DEFINE(calStandardDataCTN){ - uint32_t size = __ARGS(0, uint32_t); - size += 64; - //unsigned long long temp = __NOW_INDEX; - if(__NOW_INDEX == __LIST_LEN - 1){ - __RETURN("%ull", size); - } - return __CRETURN__; -} - -__CALLBACK_DEFINE(calStandardDataBLK){ - uint32_t size = __ARGS(0, uint32_t); - STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *); - if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int32_t); - else size += sizeof(int32_t); - size += p_stdb->blocks_num + sizeof(uint16_t) + sizeof(uint32_t); - //unsigned long long temp = __NOW_INDEX; - if(__NOW_INDEX == __LIST_LEN - 1){ - return __RETURN("%ull", size); - } - return __CRETURN__; -} MSG *createMessage(char *title, void *data, unsigned long data_size){ MSG *p_msg = malloc(sizeof(MSG) + data_size); @@ -372,112 +50,3 @@ MSG *createMessage(char *title, void *data, unsigned long data_size){ close(client_sockfd); return -1; }*/ - -int readDataFileInfo(D_FILE *p_dfile){ - if(checkIfDataFile(p_dfile)){ - uint32_t std_num = 0,std_size; - uint16_t std_type = VOID; - char info_begin[INFO_TEST_LEN], s_id[SID_LEN]; - uint32_t location = 0; - fread(&std_num, sizeof(uint32_t), 1, p_dfile->fp); - fread(info_begin, sizeof(char),INFO_TEST_LEN,p_dfile->fp); - location += INFO_TEST_LEN + sizeof(uint32_t) + FILE_TSET_LEN; - if(!strcmp(info_begin, "STDINFO")){ - location += std_num * 45 + 7; - for(int i = 0; i < std_num; i++){ - fread(s_id, sizeof(char), SID_LEN, p_dfile->fp); - fread(&std_type, sizeof(uint16_t), 1, p_dfile->fp); - fread(&std_size, sizeof(uint32_t), 1, p_dfile->fp); - SID *temp_sid = setS_idWithString(s_id); - STD_DATA *p_std = initStandardData(std_type,temp_sid); - freeS_id(temp_sid); - p_std->size = std_size; - p_std->type = std_type; - p_std->location = location; - dataFileAddStandardData(p_dfile, p_std); - location += std_size; - } - } - } - return 0; -} - -int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){ - char s_id[SID_LEN],std_text[STD_TEXT_LEN]; - fseek(p_dfile->fp, p_std->location, SEEK_SET); - fread(std_text, sizeof(char), STD_TEXT_LEN, p_dfile->fp); - if(strcmp(std_text, "STD")) return -1; - fread(s_id, sizeof(char), SID_LEN, p_dfile->fp); - - if(!strcmp(s_id, p_std->s_id->decrypt_str)){ - uint32_t ctn_num = 0, blk_num = 0; - fread(&ctn_num, sizeof(uint32_t), 1, p_dfile->fp); - fread(&blk_num, sizeof(uint32_t), 1, p_dfile->fp); - for(int i = 0; i < ctn_num; i++){ - SID *fs_id = NULL, *ss_id = NULL; - char t_sid[SID_LEN]; - fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); - fs_id = setS_idWithString(t_sid); - fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); - ss_id = setS_idWithString(t_sid); - standardDataAddConnection(p_std, fs_id, ss_id); - freeS_id(fs_id); - freeS_id(ss_id); - } - for(int i = 0; i < blk_num; i++){ - int if_sid = 0; - uint16_t type = VOID; - uint32_t blk_size = 0; - char t_sid[SID_LEN]; - fread(&if_sid, sizeof(int32_t), 1, p_dfile->fp); - if(if_sid){ - fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); - } - fread(&type, sizeof(int32_t), 1, p_dfile->fp); - fread(&blk_size, sizeof(uint32_t), 1, p_dfile->fp); - char *buff = malloc(sizeof(char) * blk_size); - fread(buff, sizeof(char), blk_size, p_dfile->fp); - SID *sb_sid = NULL; - if (if_sid) setS_idWithString(t_sid); - standardDataAddBlock(p_std, sb_sid, type, buff, blk_size); - free(buff); - freeS_id(sb_sid); - } - } - p_std->read_data = 1; - return 0; -} - -int checkIfDataFile(D_FILE *p_dfile){ - char test_info[FILE_TSET_LEN]; - fread(test_info, sizeof(char), FILE_TSET_LEN, p_dfile->fp); - strcpy(p_dfile->pf_head->head_test, test_info); - if(!strcmp(test_info, "ZESTDLIB_STDDFILE"))return 1; - return 0; -} - -void printStandardData(void *value){ - STD_DATA *p_std = (STD_DATA *)value; - printf("SID:%s\n",p_std->s_id->decrypt_str); - printf("Loaction:%u\n",p_std->location); - printf("Size:%u\n",p_std->size); - printf("Ctn number:%llu\n",p_std->pd_ctnlst->length); - printf("Blk number:%llu\n",p_std->pd_blocklst->length); -} - -int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid){ - List *rtn = listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(findStandardDataBySid), __SEND_ARG("%p", p_sid)); - //STD_DATA *p_std = __RTN_ARGS_P(rtn, 0, STD_DATA); - releaseList(rtn); - //if(p_std != NULL) readStandardData(p_dfile, p_std); - return 0; -} - -__CALLBACK_DEFINE(findStandardDataBySid){ - SID *t_sid = __ARGS_P(0, SID); - STD_DATA *p_std = __VALUE(STD_DATA *); - if(simFitS_id(p_std->s_id, t_sid)){ - return __RETURN("%p", p_std); - } - return __CRETURN__; -} diff --git a/src/communicate/dfile/dfile_in.c b/src/communicate/dfile/dfile_in.c new file mode 100644 index 0000000..5a37eb8 --- /dev/null +++ b/src/communicate/dfile/dfile_in.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + + +int dataFileReadOut(D_FILE *p_dfile){ + if(!readDataFileInfo(p_dfile)){ + listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(dataFileReadOut), __SEND_ARG("%p", p_dfile)); + } + return -1; +} + +__CALLBACK_DEFINE(dataFileReadOut){ + D_FILE *p_dfile = __ARGS_P(0, D_FILE); + readStandardData(p_dfile, __VALUE(STD_DATA *)); + return __CRETURN__; +} + +int readDataFileInfo(D_FILE *p_dfile){ + if(checkIfDataFile(p_dfile)){ + uint32_t std_num = 0,std_size; + uint16_t std_type = VOID; + char info_begin[INFO_TEST_LEN], s_id[SID_LEN]; + uint32_t location = 0; + fread(&std_num, sizeof(uint32_t), 1, p_dfile->fp); + fread(info_begin, sizeof(char),INFO_TEST_LEN,p_dfile->fp); + location += INFO_TEST_LEN + sizeof(uint32_t) + FILE_TSET_LEN; + if(!strcmp(info_begin, "STDINFO")){ + location += std_num * 45 + 7; + for(int i = 0; i < std_num; i++){ + fread(s_id, sizeof(char), SID_LEN, p_dfile->fp); + fread(&std_type, sizeof(uint16_t), 1, p_dfile->fp); + fread(&std_size, sizeof(uint32_t), 1, p_dfile->fp); + SID *temp_sid = setS_idWithString(s_id); + STD_DATA *p_std = initStandardData(std_type,temp_sid); + freeS_id(temp_sid); + p_std->size = std_size; + p_std->type = std_type; + p_std->location = location; + dataFileAddStandardData(p_dfile, p_std); + location += std_size; + } + } + } + return 0; +} + diff --git a/src/communicate/dfile/dfile_info.c b/src/communicate/dfile/dfile_info.c new file mode 100644 index 0000000..6947f67 --- /dev/null +++ b/src/communicate/dfile/dfile_info.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +int checkIfDataFile(D_FILE *p_dfile){ + char test_info[FILE_TSET_LEN]; + fread(test_info, sizeof(char), FILE_TSET_LEN, p_dfile->fp); + strcpy(p_dfile->pf_head->head_test, test_info); + if(!strcmp(test_info, "ZESTDLIB_STDDFILE"))return 1; + return 0; +} diff --git a/src/communicate/dfile/dfile_init.c b/src/communicate/dfile/dfile_init.c new file mode 100644 index 0000000..48b2de3 --- /dev/null +++ b/src/communicate/dfile/dfile_init.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include + +D_FILE *initDataFileForWrite(char *route){ + D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE)); + p_dfile->fp = fopen(route, "wb"); + p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); + strcpy(p_dfile->pf_head->head_test,"ZESTDLIB_STDDFILE"); + p_dfile->pf_head->data_num = 0; + p_dfile->pf_stdlst = initList(0); + return p_dfile; +} + +D_FILE *initDataFileForRead(char *route){ + D_FILE *p_dfile = (D_FILE *)malloc(sizeof(D_FILE)); + p_dfile->fp = fopen(route, "rb"); + p_dfile->pf_head = (F_HEAD *)malloc(sizeof(F_HEAD)); + p_dfile->pf_head->data_num = 0; + p_dfile->pf_stdlst = initList(0); + return p_dfile; +} diff --git a/src/communicate/dfile/dfile_insert.c b/src/communicate/dfile/dfile_insert.c new file mode 100644 index 0000000..9e7752d --- /dev/null +++ b/src/communicate/dfile/dfile_insert.c @@ -0,0 +1,11 @@ +#include +#include +#include +#include +#include + +int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ + insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0)); + p_dfile->pf_head->data_num = (uint32_t)p_dfile->pf_stdlst->length; + return 0; +} diff --git a/src/communicate/dfile/dfile_out.c b/src/communicate/dfile/dfile_out.c new file mode 100644 index 0000000..4816511 --- /dev/null +++ b/src/communicate/dfile/dfile_out.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include +#include + +int dataFileWriteIn(D_FILE *p_dfile){ + fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp); + fwrite(&p_dfile->pf_head->data_num, sizeof(uint32_t), 1, p_dfile->fp); + fwrite("STDINFO", sizeof(char), 8, p_dfile->fp); + listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataInfoWrite), __SEND_ARG("%p", p_dfile->fp)); + fwrite("STDLST", sizeof(char), 7, p_dfile->fp); + listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(StandardDataWrite), __SEND_ARG("%p", p_dfile->fp)); + return 0; +} diff --git a/src/communicate/dfile/dfile_release.c b/src/communicate/dfile/dfile_release.c new file mode 100644 index 0000000..5e0ecf6 --- /dev/null +++ b/src/communicate/dfile/dfile_release.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +int releaseDFile(D_FILE *p_dfile){ + releaseListForCustom(p_dfile->pf_stdlst, (int (*)(void *))releaseStandardData); + fclose(p_dfile->fp); + free(p_dfile->pf_head); + free(p_dfile); + return 0; +} diff --git a/src/communicate/std/std_find.c b/src/communicate/std/std_find.c new file mode 100644 index 0000000..60493fe --- /dev/null +++ b/src/communicate/std/std_find.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include +#include + +__CALLBACK_DEFINE(findStandardDataBySid){ + SID *t_sid = __ARGS_P(0, SID); + STD_DATA *p_std = __VALUE(STD_DATA *); + if(simFitS_id(p_std->s_id, t_sid)){ + return __RETURN("%p", p_std); + } + return __CRETURN__; +} diff --git a/src/communicate/std/std_in.c b/src/communicate/std/std_in.c new file mode 100644 index 0000000..e903d61 --- /dev/null +++ b/src/communicate/std/std_in.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){ + char s_id[SID_LEN],std_text[STD_TEXT_LEN]; + fseek(p_dfile->fp, p_std->location, SEEK_SET); + fread(std_text, sizeof(char), STD_TEXT_LEN, p_dfile->fp); + if(strcmp(std_text, "STD")) return -1; + fread(s_id, sizeof(char), SID_LEN, p_dfile->fp); + + if(!strcmp(s_id, p_std->s_id->decrypt_str)){ + uint32_t ctn_num = 0, blk_num = 0; + fread(&ctn_num, sizeof(uint32_t), 1, p_dfile->fp); + fread(&blk_num, sizeof(uint32_t), 1, p_dfile->fp); + for(int i = 0; i < ctn_num; i++){ + SID *fs_id = NULL, *ss_id = NULL; + char t_sid[SID_LEN]; + fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); + fs_id = setS_idWithString(t_sid); + fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); + ss_id = setS_idWithString(t_sid); + standardDataAddConnection(p_std, fs_id, ss_id); + freeS_id(fs_id); + freeS_id(ss_id); + } + for(int i = 0; i < blk_num; i++){ + int if_sid = 0; + uint16_t type = VOID; + uint32_t blk_size = 0; + char t_sid[SID_LEN]; + fread(&if_sid, sizeof(int32_t), 1, p_dfile->fp); + if(if_sid){ + fread(t_sid, sizeof(char), SID_LEN, p_dfile->fp); + } + fread(&type, sizeof(int32_t), 1, p_dfile->fp); + fread(&blk_size, sizeof(uint32_t), 1, p_dfile->fp); + char *buff = malloc(sizeof(char) * blk_size); + fread(buff, sizeof(char), blk_size, p_dfile->fp); + SID *sb_sid = NULL; + if (if_sid) setS_idWithString(t_sid); + standardDataAddBlock(p_std, sb_sid, type, buff, blk_size); + free(buff); + freeS_id(sb_sid); + } + } + p_std->read_data = 1; + return 0; +} + +int readStandardDataBySid(D_FILE *p_dfile, SID *p_sid){ + List *rtn = listThrough(p_dfile->pf_stdlst, __CALLBACK_CALL(findStandardDataBySid), __SEND_ARG("%p", p_sid)); + //STD_DATA *p_std = __RTN_ARGS_P(rtn, 0, STD_DATA); + releaseList(rtn); + //if(p_std != NULL) readStandardData(p_dfile, p_std); + return 0; +} diff --git a/src/communicate/std/std_info.c b/src/communicate/std/std_info.c new file mode 100644 index 0000000..39bde49 --- /dev/null +++ b/src/communicate/std/std_info.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +uint32_t calStandardData(STD_DATA *p_std){ + List *rtn_lst = NULL; + uint32_t size = 4 + sizeof(unsigned long long) * 2; + if(p_std->s_id != NULL) size += SID_LEN * sizeof(char); + rtn_lst = listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(calStandardDataCTN), __SEND_ARG("%d", size)); + if(rtn_lst != NULL){ + size = __RTN_ARGS(rtn_lst, 0, uint32_t); + releaseList(rtn_lst); + } + rtn_lst = listThrough(p_std->pd_blocklst, __CALLBACK_CALL(calStandardDataBLK), __SEND_ARG("%d", size)); + if(rtn_lst != NULL){ + size = __RTN_ARGS(rtn_lst, 0, uint32_t); + releaseList(rtn_lst); + } + return size; +} + +__CALLBACK_DEFINE(calStandardDataBLK){ + uint32_t size = __ARGS(0, uint32_t); + STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *); + if(p_stdb->sid != NULL) size += SID_LEN + sizeof(int32_t); + else size += sizeof(int32_t); + size += p_stdb->blocks_num + sizeof(uint16_t) + sizeof(uint32_t); + //unsigned long long temp = __NOW_INDEX; + if(__NOW_INDEX == __LIST_LEN - 1){ + return __RETURN("%ull", size); + } + return __CRETURN__; +} + +void printStandardData(void *value){ + STD_DATA *p_std = (STD_DATA *)value; + printf("SID:%s\n",p_std->s_id->decrypt_str); + printf("Loaction:%u\n",p_std->location); + printf("Size:%u\n",p_std->size); + printf("Ctn number:%llu\n",p_std->pd_ctnlst->length); + printf("Blk number:%llu\n",p_std->pd_blocklst->length); +} diff --git a/src/communicate/std/std_init.c b/src/communicate/std/std_init.c new file mode 100644 index 0000000..3f44756 --- /dev/null +++ b/src/communicate/std/std_init.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include + +STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){ + STD_CTN *p_stdc = (STD_CTN *)malloc(sizeof(STD_CTN)); + p_stdc->f_sid = s_idToASCIIString(f_sid); + p_stdc->s_sid = s_idToASCIIString(s_sid); + p_stdc->location = 0; + return p_stdc; +} + +STD_DATA *initStandardData(uint16_t type, SID *s_id){ + STD_DATA *p_std = (STD_DATA *)malloc(sizeof(STD_DATA)); + p_std->pd_blocklst = initList(0); + p_std->pd_ctnlst = initList(0); + p_std->lock = 0; + p_std->type = type; + p_std->size = 0; + p_std->location = 0; + p_std->read_data = 0; + + if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2); + else p_std->s_id = copyS_id(s_id); + setSidToASCIIString(p_std->s_id); + return p_std; +} + + diff --git a/src/communicate/std/std_insert.c b/src/communicate/std/std_insert.c new file mode 100644 index 0000000..52d318a --- /dev/null +++ b/src/communicate/std/std_insert.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include + +int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){ + if (p_std->lock) return -1; + STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size); + dataForStandardDBlock(p_stdb, data); + insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb,0)); + return 0; +} + +int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){ + if (p_std->lock) return -1; + STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid); + insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb,0)); + return 0; +} diff --git a/src/communicate/std/std_out.c b/src/communicate/std/std_out.c new file mode 100644 index 0000000..88550a8 --- /dev/null +++ b/src/communicate/std/std_out.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + + +__CALLBACK_DEFINE(StandardDataInfoWrite){ + FILE *fp = __ARGS_P(0, FILE); + STD_DATA *p_std = __VALUE(STD_DATA *); + fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp); + fwrite(&p_std->type, sizeof(uint16_t), 1, fp); + uint32_t std_size = calStandardData(p_std); + p_std->size = std_size; + fwrite(&std_size, sizeof(uint32_t), 1, fp); + return __CRETURN__; +} + +__CALLBACK_DEFINE(StandardDataWrite){ + FILE *fp = __ARGS_P(0, FILE); + STD_DATA *p_std = __VALUE(STD_DATA *); + fwrite("STD", sizeof(char), 4, fp); + fwrite(p_std->s_id->decrypt_str, sizeof(char), SID_LEN, fp); + fwrite(&p_std->pd_ctnlst->length, sizeof(uint32_t), 1, fp); + fwrite(&p_std->pd_blocklst->length, sizeof(uint32_t), 1, fp); + listThrough(p_std->pd_ctnlst, __CALLBACK_CALL(StandardDConnectionWrite), __SEND_ARG("%p", fp)); + listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDBlockWrite), __SEND_ARG("%p", fp)); + return __CRETURN__; +} diff --git a/src/communicate/std/std_relaese.c b/src/communicate/std/std_relaese.c new file mode 100644 index 0000000..2fba775 --- /dev/null +++ b/src/communicate/std/std_relaese.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +int releaseStandardData(STD_DATA *p_std){ + releaseListForCustom(p_std->pd_blocklst, (int (*)(void *))releaseSTDBlocks); + releaseListForCustom(p_std->pd_ctnlst, (int (*)(void *))releaseSTDConnection); + freeS_id(p_std->s_id); + free(p_std); + return 0; +} diff --git a/src/communicate/stdb/stdb_in.c b/src/communicate/stdb/stdb_in.c new file mode 100644 index 0000000..a7f3bdb --- /dev/null +++ b/src/communicate/stdb/stdb_in.c @@ -0,0 +1,6 @@ +#include +#include +#include +#include +#include + diff --git a/src/communicate/stdb/stdb_init.c b/src/communicate/stdb/stdb_init.c new file mode 100644 index 0000000..f30f165 --- /dev/null +++ b/src/communicate/stdb/stdb_init.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){ + STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); + if(p_sid != NULL){ + p_stdb->sid = s_idToASCIIString(p_sid); + } + else p_stdb->sid = NULL; + p_stdb->if_data = 0; + p_stdb->location = 0; + uint32_t blocks_num = (uint32_t)(data_size/sizeof(char)); + p_stdb->blocks_num = blocks_num; + p_stdb->type = type; + p_stdb->buff = (char *)malloc(sizeof(char) * blocks_num); + return p_stdb; +} + +int dataForStandardDBlock(STD_BLOCKS *p_stdb,void *data){ + char *t_data = (char *)data; + /*unsigned int data_size = sizeof(data);*/ + for(int i = 0; i < p_stdb->blocks_num; i++){ + p_stdb->buff[i] = t_data[i]; + } + p_stdb->if_data = 1; + return 0; +} diff --git a/src/communicate/stdb/stdb_out.c b/src/communicate/stdb/stdb_out.c new file mode 100644 index 0000000..98d9df7 --- /dev/null +++ b/src/communicate/stdb/stdb_out.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include + +__CALLBACK_DEFINE(StandardDBlockWrite){ + STD_BLOCKS *p_stdb = value; + FILE *fp = __ARGS_P(0, FILE); + unsigned long blocks_num = p_stdb->blocks_num; + int if_sid = 0; + if(p_stdb->sid != NULL){ + if_sid = 1; + fwrite(&if_sid, sizeof(int), 1, fp); + fwrite(p_stdb->sid, sizeof(char), SID_LEN, fp); + } + else{ + fwrite(&if_sid, sizeof(int), 1, fp); + } + fwrite(&p_stdb->type, sizeof(uint16_t), 1, fp); + fwrite(&blocks_num, sizeof(uint32_t), 1, fp); + fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp); + return __CRETURN__; +} diff --git a/src/communicate/stdb/stdb_release.c b/src/communicate/stdb/stdb_release.c new file mode 100644 index 0000000..8072439 --- /dev/null +++ b/src/communicate/stdb/stdb_release.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include +#include + +int releaseSTDBlocks(STD_BLOCKS *p_stdb){ + free(p_stdb->buff); + free(p_stdb->sid); + free(p_stdb); + return 0; +} diff --git a/src/communicate/stdc/stdc_in.c b/src/communicate/stdc/stdc_in.c new file mode 100644 index 0000000..d7183ca --- /dev/null +++ b/src/communicate/stdc/stdc_in.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include +#include + + +__CALLBACK_DEFINE(StandardDConnectionWrite){ + FILE *fp = __ARGS_P(0, FILE); + STD_CTN *p_stdc = __VALUE(STD_CTN *); + fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp); + fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp); + return __CRETURN__; +} diff --git a/src/communicate/stdc/stdc_info.c b/src/communicate/stdc/stdc_info.c new file mode 100644 index 0000000..46fbe3a --- /dev/null +++ b/src/communicate/stdc/stdc_info.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include +#include + +__CALLBACK_DEFINE(calStandardDataCTN){ + uint32_t size = __ARGS(0, uint32_t); + size += 64; + //unsigned long long temp = __NOW_INDEX; + if(__NOW_INDEX == __LIST_LEN - 1){ + __RETURN("%ull", size); + } + return __CRETURN__; +} diff --git a/src/communicate/stdc/stdc_init.c b/src/communicate/stdc/stdc_init.c new file mode 100644 index 0000000..a7f3bdb --- /dev/null +++ b/src/communicate/stdc/stdc_init.c @@ -0,0 +1,6 @@ +#include +#include +#include +#include +#include + diff --git a/src/communicate/stdc/stdc_out.c b/src/communicate/stdc/stdc_out.c new file mode 100644 index 0000000..a7f3bdb --- /dev/null +++ b/src/communicate/stdc/stdc_out.c @@ -0,0 +1,6 @@ +#include +#include +#include +#include +#include + diff --git a/src/communicate/stdc/stdc_release.c b/src/communicate/stdc/stdc_release.c new file mode 100644 index 0000000..e743ef5 --- /dev/null +++ b/src/communicate/stdc/stdc_release.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include +#include + +int releaseSTDConnection(STD_CTN *p_stdc){ + free(p_stdc->f_sid); + free(p_stdc->s_sid); + free(p_stdc); + return 0; +} diff --git a/src/communicate/stdcvt/stcvt_in.c b/src/communicate/stdcvt/stcvt_in.c new file mode 100644 index 0000000..26d7699 --- /dev/null +++ b/src/communicate/stdcvt/stcvt_in.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +STD_DATA *listToSTD(List *p_list){ + Node *p_node = p_list->head; + STD_DATA *p_std = NULL; + if (p_list->s_id != NULL){ + p_std = initStandardData(LIST,p_list->s_id); + } + else p_std = initStandardData(LIST, NULL); + while (p_node != NULL) { + if(p_node->type == HOLE) continue; + uint32_t data_size = 0; + if(p_node->type == INT) data_size = sizeof(int); + else if (p_node->type == DOUBLE) data_size = sizeof(double); + else if (p_node->type == STRING) data_size = (uint32_t)strlen((char *)p_node->value) + 1; + else data_size = sizeof(void *); + standardDataAddBlock(p_std, p_node->s_id, p_node->type, p_node->value, data_size); + p_node = p_node->next; + } + return p_std; +} diff --git a/src/communicate/stdcvt/stdcvt_out.c b/src/communicate/stdcvt/stdcvt_out.c new file mode 100644 index 0000000..7d6276b --- /dev/null +++ b/src/communicate/stdcvt/stdcvt_out.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +List *standardDataToList(STD_DATA *p_std){ + List *p_list = initList(0); + listThrough(p_std->pd_blocklst, __CALLBACK_CALL(StandardDataToList), __SEND_ARG("%p", p_list)); + return p_list; +} + +__CALLBACK_DEFINE(StandardDataToList){ + List *p_list = __ARGS_P(0, List); + STD_BLOCKS *p_stdb = __VALUE(STD_BLOCKS *); + Node *p_node = initNode(0); + p_node->s_id = setS_idWithString(p_stdb->sid); + p_node->type = p_stdb->type; + p_node->value = malloc(sizeof(p_stdb->blocks_num)); + memcpy(p_node->value, p_stdb->buff, sizeof(p_stdb->blocks_num)); + insertInTail(p_list, p_node); + return __CRETURN__; +} From 8f934bfaa3a6d8e9a45d41592255703a3c2042de Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 12 Jan 2019 02:22:04 +0800 Subject: [PATCH 15/18] List aparted and created chain. --- include/{list/list_expand.h => chain/chain.h} | 99 ++++---- .../list_print.h => chain/chain_print.h} | 14 +- include/chain/chain_type.h | 16 ++ include/communicate/communicate_file.h | 4 +- include/communicate/communicate_type.h | 6 +- .../{list/list_expand_1.h => event/event.h} | 2 +- include/list/list_quick.h | 65 ----- include/list/list_type.h | 21 +- src/communicate/communicate.c | 7 +- src/communicate/dfile/dfile_in.c | 6 +- src/communicate/dfile/dfile_info.c | 6 +- src/communicate/dfile/dfile_init.c | 6 +- src/communicate/dfile/dfile_insert.c | 6 +- src/communicate/dfile/dfile_out.c | 6 +- src/communicate/dfile/dfile_release.c | 6 +- src/communicate/std/std_find.c | 6 +- src/communicate/std/std_in.c | 6 +- src/communicate/std/std_info.c | 6 +- src/communicate/std/std_init.c | 6 +- src/communicate/std/std_insert.c | 6 +- src/communicate/std/std_out.c | 6 +- src/communicate/std/std_relaese.c | 6 +- src/communicate/stdb/stdb_in.c | 6 +- src/communicate/stdb/stdb_init.c | 6 +- src/communicate/stdb/stdb_out.c | 6 +- src/communicate/stdb/stdb_release.c | 6 +- src/communicate/stdc/stdc_in.c | 6 +- src/communicate/stdc/stdc_info.c | 6 +- src/communicate/stdc/stdc_init.c | 6 +- src/communicate/stdc/stdc_out.c | 6 +- src/communicate/stdc/stdc_release.c | 6 +- src/communicate/stdcvt/stcvt_in.c | 6 +- src/communicate/stdcvt/stdcvt_out.c | 6 +- .../chain/chain_calculate.c} | 5 +- .../chain/chain_complex.c} | 20 +- .../chain/chain_find.c} | 58 ++--- .../chain/chain_get.c} | 30 +-- .../chain/chain_node.c} | 3 +- src/datastruct/chain/chain_print.c | 179 +++++++++++++ .../chain/chain_sort.c} | 27 +- .../chain/chain_update.c} | 13 +- src/{ => datastruct}/graph/graph.c | 0 src/{ => datastruct}/graph/graph.h | 0 src/{ => datastruct}/tree/tree.c | 0 src/{ => datastruct}/tree/tree_expand.c | 0 src/{ => datastruct}/tree/tree_expand.h | 0 .../event_callback.c} | 13 +- src/list/list_insert.c | 82 ------ src/list/list_quick.c | 237 ------------------ src/list/list_simple.c | 67 ----- src/list/list_simple_node.c | 41 --- src/{ => memory}/block/block.c | 0 src/{ => memory}/block/block_expand.c | 0 src/{ => memory}/list/list_copy.c | 8 - src/{ => memory}/list/list_find.c | 1 - src/{ => memory}/list/list_info.c | 0 src/{ => memory}/list/list_init.c | 7 - src/memory/list/list_insert.c | 52 ++++ src/{ => memory}/list/list_print.c | 2 - src/{ => memory}/list/list_release.c | 13 - src/{ => memory}/list/list_remove.c | 55 +--- src/{ => memory}/list/list_replace.c | 23 -- src/{ => memory}/list/safe_mode.c | 2 +- test/test.c | 36 --- test/test.h | 9 +- 65 files changed, 459 insertions(+), 902 deletions(-) rename include/{list/list_expand.h => chain/chain.h} (74%) rename include/{list/list_print.h => chain/chain_print.h} (74%) create mode 100644 include/chain/chain_type.h rename include/{list/list_expand_1.h => event/event.h} (99%) delete mode 100644 include/list/list_quick.h rename src/{list/list_expand_calculate.c => datastruct/chain/chain_calculate.c} (86%) rename src/{list/list_expand_complex.c => datastruct/chain/chain_complex.c} (86%) rename src/{list/list_expand_find.c => datastruct/chain/chain_find.c} (76%) rename src/{list/list_expand_get.c => datastruct/chain/chain_get.c} (67%) rename src/{list/list_expand_node.c => datastruct/chain/chain_node.c} (98%) create mode 100644 src/datastruct/chain/chain_print.c rename src/{list/list_sort.c => datastruct/chain/chain_sort.c} (65%) rename src/{list/list_expand_update.c => datastruct/chain/chain_update.c} (82%) rename src/{ => datastruct}/graph/graph.c (100%) rename src/{ => datastruct}/graph/graph.h (100%) rename src/{ => datastruct}/tree/tree.c (100%) rename src/{ => datastruct}/tree/tree_expand.c (100%) rename src/{ => datastruct}/tree/tree_expand.h (100%) rename src/{list/list_expand_callback.c => event/event_callback.c} (92%) delete mode 100644 src/list/list_insert.c delete mode 100644 src/list/list_quick.c delete mode 100644 src/list/list_simple.c delete mode 100644 src/list/list_simple_node.c rename src/{ => memory}/block/block.c (100%) rename src/{ => memory}/block/block_expand.c (100%) rename src/{ => memory}/list/list_copy.c (86%) rename src/{ => memory}/list/list_find.c (99%) rename src/{ => memory}/list/list_info.c (100%) rename src/{ => memory}/list/list_init.c (91%) create mode 100644 src/memory/list/list_insert.c rename src/{ => memory}/list/list_print.c (98%) rename src/{ => memory}/list/list_release.c (88%) rename src/{ => memory}/list/list_remove.c (52%) rename src/{ => memory}/list/list_replace.c (58%) rename src/{ => memory}/list/safe_mode.c (98%) 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 From dd929e2ccb0fb0b76ddd4bda251f2e054e348da7 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 12 Jan 2019 02:28:26 +0800 Subject: [PATCH 16/18] Done. --- src/datastruct/chain/chain_node.c | 24 ++++++++++++------------ src/event/event_callback.c | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/datastruct/chain/chain_node.c b/src/datastruct/chain/chain_node.c index 25e501e..18b1110 100644 --- a/src/datastruct/chain/chain_node.c +++ b/src/datastruct/chain/chain_node.c @@ -9,8 +9,8 @@ @param if_sid 新的节点有无id @return 返回指向新节点的指针 */ -Node *nodeWithInt(int m_int, _Bool if_sid) { - Node *p_node; +CNode *nodeWithInt(int m_int, _Bool if_sid) { + CNode *p_node; int *p_int = (int *)malloc(sizeof(int)); if(p_int == NULL){ return NULL; @@ -29,8 +29,8 @@ Node *nodeWithInt(int m_int, _Bool if_sid) { @param if_sid 新的节点有无id @return 返回指向新节点的指针 */ -Node *nodeWithUInt(uint32_t m_uint, _Bool if_sid){ - Node *p_node; +CNode *nodeWithUInt(uint32_t m_uint, _Bool if_sid){ + CNode *p_node; unsigned int *pu_int = (uint32_t *)malloc(sizeof(uint32_t)); if(pu_int == NULL){ return NULL; @@ -49,8 +49,8 @@ Node *nodeWithUInt(uint32_t m_uint, _Bool if_sid){ @param if_sid 新的节点有无id @return 返回指向新节点的指针 */ -Node *nodeWithULLInt(uint64_t m_ullint, _Bool if_sid) { - Node *p_node; +CNode *nodeWithULLInt(uint64_t m_ullint, _Bool if_sid) { + CNode *p_node; unsigned long long *p_ullint = (uint64_t *)malloc(sizeof(uint64_t)); if(p_ullint == NULL){ return NULL; @@ -69,8 +69,8 @@ Node *nodeWithULLInt(uint64_t m_ullint, _Bool if_sid) { @param if_sid 新的节点有无id @return 返回指向新节点的指针 */ -Node *nodeWithDouble(double m_double, _Bool if_sid) { - Node *p_node; +CNode *nodeWithDouble(double m_double, _Bool if_sid) { + CNode *p_node; double *p_double = (double *)malloc(sizeof(double)); if(p_double == NULL){ return NULL; @@ -89,8 +89,8 @@ Node *nodeWithDouble(double m_double, _Bool if_sid) { @param if_sid 新的节点有无id @return 返回指向新节点的指针 */ -Node *nodeWithString(const char *m_string, _Bool if_sid) { - Node *p_node; +CNode *nodeWithString(const char *m_string, _Bool if_sid) { + CNode *p_node; char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1)); if(p_string == NULL){ return NULL; @@ -109,8 +109,8 @@ Node *nodeWithString(const char *m_string, _Bool if_sid) { @param if_sid 新的节点有无id @return 返回指向新节点的指针 */ -Node *nodeWithPointer(const void *m_pointer, _Bool if_sid) { - Node *p_node = initNode(if_sid); +CNode *nodeWithPointer(const void *m_pointer, _Bool if_sid) { + CNode *p_node = initNode(if_sid); initMallocValueForNode(p_node, POINTER, m_pointer); return p_node; } diff --git a/src/event/event_callback.c b/src/event/event_callback.c index 24ba9ad..4a554a8 100644 --- a/src/event/event_callback.c +++ b/src/event/event_callback.c @@ -60,6 +60,7 @@ uint64_t getInfoForListThrough(Chain *expand_resources, int type){ return *((uint64_t *)p_node->value); } + /** 回调宏相关函数,构造回调函数的返回参数列表 From 52806be37421e09a2e760b3ecd47d083d9d2f575 Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 12 Jan 2019 08:37:35 +0800 Subject: [PATCH 17/18] Update README.md README --- README.md | 76 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 720dd88..b9d8cc4 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,62 @@ # ZE-Standard-Libraries -### --我们需要更快更方便的基于C语言的软件工程 +## 概要说明文档 +### 梗概 +该库提供了C语言环境下的内存管理、高级数据结构的使用、网络传输、文件储存、子程序管理、回调机制、错误管理的一套完整的解决方案,用于加快基于C语言的软件的开发进程,并为基于网络的分布式软件系统的开发提供了新的且简便的思路和方式。 -## 简介 -该函数库用于提供一些基础的数据结构的操作、运算、储存的函数,旨在加快基于C语言的软件工程的构建速度。运用该函数库提供的操作函数,可以省去工程中遇到的大量繁复的的高级数据结构的建构操作以及内存储存管理操作。 +### 详细梗概 +该库以模块化的方式来组织,主要模块包括内存管理模块、高级数据结构模块、文件储存模块、网络传输模块、子程序管理模块、回调机制实现模块、错误管理模块、在主要模块还会被分为几个小模块。模块之间有对应的依赖关系。 -## 特性 -- 函数库提供高级数据结构实体以及配套的多样的操作函数,开发者得以主要注意力集中在主要的功能实现上。 -- 函数库提供相关函数,可以对高级数据结构快速进行基于文件的储存和基于网络的传输等工作。 -- 函数库中构建的高级数据结构有唯一的识别码,很方便可以进行查找,替换操作。 -- 函数库还提供工程的错误管理功能,使得开发者可以及时定位错误,或者让程序自动储存错误或者警告消息至文件。 +#### 内存管理模块 +该库以内存管理模块为基础,通过两种内存管理结构,对于储存在内存中的数据进行组织、操作。该模块的子模块主要分为链式内存管理,块式内存管理。链式内存管理对于内存中离散的数据进行组织和管理;块式内存管理对于内存中的整块数据进行管理。这两个子模块会分别实现链式和块式的内存管理的管理结构及相关操作。该模块的第三个子模块是内存泄露管理模块,该模块对于已经分配的内存空间进行全面地监控,及时地完全地释放不需要的内存空间。内存泄漏管理对于长期运行的软件系统来说至关重要。链式和块式内存管理具体要实现的基本操作函数有:初始化类函数、赋值类函数、复制类函数、插入类函数、删除类函数、查询类函数、释放类函数。 -## 分类 -该函数库主要提供以下基本数据结构操作、运算和储存函数: -- 链表 list -- 词典 dict -- 树 tree -- 图 graph -- 栈 stack -- 信息 message -## 代码风格 -本函数库秉承着可视性、稳定性与扩展性优先的原则,将在基本框架不变的情况下不断进行的优化。 +#### 高级数据结构模块 +高级数据结构模块是对于内存管理模块的一次封装和抽象,它依赖于内存管理模块所提供的链式内存和块式内存管理结构和相关操作方法,运用相关方法来实现高级数据结构及其基本操作和算法。这些高级数据结构包括:目录树、二叉树、堆、栈、队列、有向图、无向图、链表、字典、字符串。通过高级数据模块,使得库能够更加快速地对于实际问题进行建模,更加有效率的解决实际问题。高级数据结构的子模块包含:基本操作子模块和算法子模块。前者完成了对于高级数据结构的基本操作:初始化数据结构、插入数据、删除数据、更新数据;后者将提供高级数据结构常用的高级算法:查找算法、排序算法、优化算法、转换算法。 + +#### 文件储存模块 +文件储存模块依赖内存管理模块、回调机制模块和高级数据结构模块,该模块实现将内存数据管理结构与高级数据结构的信息及其中储存的数据储存到到文件中。该模块中定义的文件管理结构分为两类:关系型文件管理结构,非关系型文件管理结构。这两个结构的区别是是否记录所储存信息之间的关系。前者将有专门的数据结构来储存所储存的数据之间的联系,后者按照块的形式来叠放数据。模块内部将专门实现这两个数据管理结构写入文件、从文件读出的操作方法。并且,将实现各个高级数据结构与文件管理结构之间的转化。这样,能够直接将高级数据结构转化为文件管理结构,从而储存到文件中。或者,将文件中的数据读出,独处的数据在内存中的表现形式为对应的文件管理结构,而后再将文件管理结构转化为对应的高级数据结构。模块将实现对于这两种结构的操作方法:初始化,转化,写入,读取,释放。 + +#### 网络传输模块 +网路传输模块依赖内存管理模块、回调机制模块、高级数据结构模块和文件储存模块,此模块主要提供将高级数据结构转化为文件信息管理结构,文件管理结构转化为网络信息块管理结构,将信息分块进行传输。对于简单的字符信息,该模块也提供网络消息管理结构,通过该结构能够在一台计算机和另外一台计算机之间传递字符串消息。模块将实现对于这两种结构的操作方法:初始化、转化、赋值、传输、释放。 + +#### 回调机制模块 +回调机制模块依赖内存管理模块和高级数据结构,该模块实现一种方法调用机制,将实现回调函数的注册、传参、返回值传参的标准化宏与相关支撑函数。高级模块中的相关方法,通过使用以上的宏和函数,中能够以更加标准的、更加优雅的方法来实现相关功能。这也使得,事件机制的运用能够更加便捷有效,从而跨计算机之间的函数调用与传参成为可能。 + +#### 错误管理模块 +错误管理模块依赖内存管理模块和回调机制模块,该模块提供程序输出信息的分类:严重错误、错误、警告、提示。该模块将实现错误的处理函数的注册,在严重错误或者错误出现的情况下,根据开发者通过该模块的错误处理函数的注册信息,调用相应的错误处理函数并提供关键信息来辅助错误修复。该模块将提供相应的管理结构与方法来建立程序中的相关信息的日志文件,并且提供更加方便的方法来管理与更新相应的日志文件,实现程序输出信息的更加规范的清晰地产生与显示。 + +#### 子程序管理模块 +该模块依赖以上的所有模块,该模块也为该库的最高级的部分。该模块提供子程序的注册,调用,传输以及依赖关系的管理。子程序是一个独立的软件系统的所有功能的一部分,具有相对的独立性。一个程序的子程序可以储存在相同的计算机上,也可以储存在不同的计算机上,子程序之间不论储存的地方在何处,只要能够通过内存或者网络的方式访问到,则可以进行传参和调用。位置信息的记录与子程序的调用由相应的管理结构与操作方法来实现。对于一个要由多个子程序之间协调合作来完成的复杂任务的情景,该模块将通过子程序依赖关系管理结构及其方法来进行相应的系统性的有序调用。对于一个大任务中两个不互为依赖的过程,在允许的情况下模块将进行并行调用。通过子程序的传输方法,子程序能够更加方便地通过网络在计算机之间进行转移。总之,通过该模块,实现了一个独立的软件系统在不同的计算机中储存并且运行在不同计算机的内存中却可以虚拟出在同一计算机中储存运行的效果,能够并行执行软件系统中的某些功能,也可以让软件系统的设计者随时根据具体情况来转移子程序。 + +### 通信模块 +由于实际原因,网络传输模块与文件储存模块合为通信模块。 + +### 目录结构管理方式 +- src:源文件 + - memory:内存管理模块 + - list 链式内存管理 + - block 块式内存管理 + - communicate:通信模块 + - datastruct:高级数据结构 + - event:回调机制模块 + - error:错误管理模块 + - subfunc:子程序管理模块 +- include:头文件 + - memory:内存管理模块 + - file:文件储存模块 + - network:网络传输模块 + - chain:链表 + - event:回调机制模块 + - list 链式内存管理 + - tree 目录树 + - error:错误管理模块 +- subfunc:子程序管理模块 +- type.h:全局信息头文件 +- document:文档 +- info:工程说明及计划文档 +- raw design:模块概要设计文档 +- design:模块详细设计文档 +- test:测试方案及数据文档 +- test:不同平台下的测试程序文件 +- unix +- windows +- bin:编译后的二进制文件 From 1116412c0a7bdd08a1094909e51a1d1cc473404b Mon Sep 17 00:00:00 2001 From: Saturneic Date: Sat, 12 Jan 2019 08:54:05 +0800 Subject: [PATCH 18/18] Fixed. --- README.md | 16 +-- include/chain/chain.h | 147 +++++++++++++++++++++++- include/chain/chain_print.h | 6 +- include/chain/chain_type.h | 4 +- include/event/event.h | 153 +------------------------ include/list/list_simple.h | 79 ------------- include/list/list_type.h | 12 +- src/datastruct/chain/chain_calculate.c | 2 +- src/event/event_callback.c | 10 +- src/memory/list/list_copy.c | 12 +- src/memory/list/list_find.c | 18 +-- src/memory/list/list_info.c | 12 +- src/memory/list/list_init.c | 18 +-- src/memory/list/list_insert.c | 18 +-- src/memory/list/safe_mode.c | 1 - 15 files changed, 209 insertions(+), 299 deletions(-) delete mode 100644 include/list/list_simple.h diff --git a/README.md b/README.md index b9d8cc4..947b1f5 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ - list 链式内存管理 - tree 目录树 - error:错误管理模块 -- subfunc:子程序管理模块 -- type.h:全局信息头文件 + - subfunc:子程序管理模块 + - type.h:全局信息头文件 - document:文档 -- info:工程说明及计划文档 -- raw design:模块概要设计文档 -- design:模块详细设计文档 -- test:测试方案及数据文档 + - info:工程说明及计划文档 + - raw design:模块概要设计文档 + - design:模块详细设计文档 + - test:测试方案及数据文档 - test:不同平台下的测试程序文件 -- unix -- windows + - unix + - windows - bin:编译后的二进制文件 diff --git a/include/chain/chain.h b/include/chain/chain.h index 540707f..2e26ba0 100644 --- a/include/chain/chain.h +++ b/include/chain/chain.h @@ -2,7 +2,7 @@ #define chain_h #include -#include +#include /************************************************ *节点的快速初始化: 为新节点分配内存空间, @@ -285,4 +285,149 @@ extern CNode *findByStringForNode(Chain *, char *); extern CNode *findByPointerForNode(Chain *, void *); + + +/************************************************ + *节点快速初始化相关宏,提供函数名较为简单的调用方式 + ************************************************/ + +/**** + *不带ID模块相关宏 + */ + +/*直接获取一个以整型值初始化的节点不带ID的缩略*/ +#define lni(cn) nodeWithInt(cn,0) + +/*直接获取一个以无符号整型值初始化的不带ID节点的缩略*/ +#define lnu(cn) nodeWithUInt(cn,0) + +/*直接获取一个以无符号长整形值初始化的节点的缩略*/ +#define lnull(cn) nodeWithULLInt(cn,0) + +/*直接获取一个以浮点值初始化的不带ID节点的缩略*/ +#define lnd(cn) nodeWithDouble(cn,0) + +/*直接获取一个以字符串值初始化的不带ID节点的缩略*/ +#define lns(cn) nodeWithString(cn,0) + +/*直接获取一个以指针值初始化的不带ID节点的缩略*/ +#define lnp(cn) nodeWithPointer(cn,0) + +/**** + *带ID模块的相关宏 + */ + +/*直接获取一个以整型值初始化的带ID节点的缩略*/ +#define lsni(cn) nodeWithInt(cn,1) + +/*直接获取一个以浮点值初始化的带ID节点的缩略*/ +#define lsnd(cn) nodeWithDouble(cn,1) + +/*直接获取一个以字符串值初始化的带ID节点的缩略*/ +#define lsns(cn) nodeWithString(cn,1) + +/*直接获取一个以指针值初始化的节点的缩略*/ +#define lsnp(cn) nodeWithPointer(cn,1) + + + + +/************************************************ + *链表快速插入相关宏 + ************************************************/ + +/**** + *尾部相关 + */ + +/*在链表尾部直接加入一个已经用整型值初始化的不带ID的节点*/ +#define lisrti(chain, cn) insertInTail(chain, lni(cn)); + +/*在链表尾部直接加入一个已经用浮点值初始化的不带ID的节点*/ +#define lisrtd(chain, cn) insertInTail(chain, lnd(cn)); + +/*在链表尾部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ +#define lisrtu(chain, cn) insertInTail(chain, lnu(cn)); + +/*在链表尾部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ +#define lisrtull(chain, cn) insertInTail(chain, lnull(cn)); + +/*在链表尾部直接加入一个已经用指针值初始化的不带ID的节点*/ +#define lisrtp(chain, cn) insertInTail(chain, lnp(cn)); + +/*在链表尾部直接加入一个已经用字符串值初始化的不带ID的节点*/ +#define lisrts(chain, cn) insertInTail(chain, lns(cn)); + +/**** + *头部相关 + */ + +/*在链表头部直接加入一个已经用整型值初始化的不带ID的节点*/ +#define lisrhi(chain, cn) insertInHead(chain, lni(cn)); + +/*在链表头部直接加入一个已经用浮点值初始化的不带ID的节点*/ +#define lisrhd(chain, cn) insertInHead(chain, lnd(cn)); + +/*在链表头部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ +#define lisrhu(chain, cn) insertInHead(chain, lnu(cn)); + +/*在链表头部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ +#define lisrhull(chain, cn) insertInHead(chain, lnull(cn)); + +/*在链表头部直接加入一个已经用指针值初始化的不带ID的节点*/ +#define lisrhp(chain, cn) insertInHead(chain, lnp(cn)); + +/*在链表头部直接加入一个已经用字符串值初始化的不带ID的节点*/ +#define lisrhs(chain, cn) insertInHead(chain, lns(cn)); + + + + +/************************************************ + *节点快速获得储存值相关宏 + ************************************************/ + +/*快速获得指针类型的节点所储存的值*/ +#define lidxp(chain, cn) getByPointerForNode(findByIndexForNode(chain, cn)) + +/*快速获得整型类型的节点所储存的值*/ +#define lidxi(chain, cn) getByIntForNode(findByIndexForNode(chain, cn)) + +/*快速获得浮点类型的节点所储存的值*/ +#define lidxd(chain, cn) getByDoubleForNode(findByIndexForNode(chain, cn)) + +/*快速获得字符串类型的节点所储存的值*/ +#define lidxs(chain, cn) getByStringForNode(findByIndexForNode(chain, cn)) + +/*快速获得无符号长整型类型的节点所储存的值*/ +#define lupdull(chain,cn,value) updateValueWithULLIntForNode(findByIndexForNode(chain, cn),value) + + + + +/************************************************ + *其他快速操作相关宏 + ************************************************/ + +/*通过节点的序号直接得到它的值*/ +#define lidxvle(chain,cn) (findByIndexForNode(chain, cn)->value) + +/*通过节点序号直接移除节点*/ +#define lrmvidx(chain,cn) removeByNode(chain, findByIndexForNode(chain, cn) + +/*从列表头移除节点的缩略*/ +#define lpoph(chain) popFromHead(chain) + +/*从列表尾移除节点的缩略*/ +#define lpopt(chain) popFromTail(chain) + +/*通过节点的ID直接获得节点的值*/ +#define lfndsid(chain,sid) (findByIdForNode(chain,sid)->value) + +/*创建一个不带ID的链表的缩略*/ +#define lstns() initList(0); + +/*创建一个带有ID的链表缩略*/ +#define lstn() initList(1); + #endif /* chain_h */ diff --git a/include/chain/chain_print.h b/include/chain/chain_print.h index a353241..d5e5bc7 100644 --- a/include/chain/chain_print.h +++ b/include/chain/chain_print.h @@ -1,5 +1,5 @@ -#ifndef list_print_h -#define list_print_h +#ifndef chain_print_h +#define chain_print_h #include #include @@ -39,4 +39,4 @@ __CALLBACK_STATE(printListForCustom); void printNode(CNode *p_node); -#endif /* list_print_h */ +#endif /* chain_h */ diff --git a/include/chain/chain_type.h b/include/chain/chain_type.h index 51acbb7..a826571 100644 --- a/include/chain/chain_type.h +++ b/include/chain/chain_type.h @@ -3,12 +3,12 @@ #include -/* +/** *节点的管理及操作的结构 */ typedef struct Node CNode; -/* +/** *链表的管理及操作的结构 */ typedef struct List Chain; diff --git a/include/event/event.h b/include/event/event.h index f2c00ed..f796350 100644 --- a/include/event/event.h +++ b/include/event/event.h @@ -1,155 +1,8 @@ -#ifndef list_expand_1_h -#define list_expand_1_h +#ifndef event_h +#define event_h #include -/************************************************ - *节点快速初始化相关宏,提供函数名较为简单的调用方式 - ************************************************/ - -/**** - *不带ID模块相关宏 - */ - -/*直接获取一个以整型值初始化的节点不带ID的缩略*/ -#define lni(x) nodeWithInt(x,0) - -/*直接获取一个以无符号整型值初始化的不带ID节点的缩略*/ -#define lnu(x) nodeWithUInt(x,0) - -/*直接获取一个以无符号长整形值初始化的节点的缩略*/ -#define lnull(x) nodeWithULLInt(x,0) - -/*直接获取一个以浮点值初始化的不带ID节点的缩略*/ -#define lnd(x) nodeWithDouble(x,0) - -/*直接获取一个以字符串值初始化的不带ID节点的缩略*/ -#define lns(x) nodeWithString(x,0) - -/*直接获取一个以指针值初始化的不带ID节点的缩略*/ -#define lnp(x) nodeWithPointer(x,0) - -/**** - *带ID模块的相关宏 - */ - -/*直接获取一个以整型值初始化的带ID节点的缩略*/ -#define lsni(x) nodeWithInt(x,1) - -/*直接获取一个以浮点值初始化的带ID节点的缩略*/ -#define lsnd(x) nodeWithDouble(x,1) - -/*直接获取一个以字符串值初始化的带ID节点的缩略*/ -#define lsns(x) nodeWithString(x,1) - -/*直接获取一个以指针值初始化的节点的缩略*/ -#define lsnp(x) nodeWithPointer(x,1) - - - - -/************************************************ - *链表快速插入相关宏 - ************************************************/ - -/**** - *尾部相关 - */ - -/*在链表尾部直接加入一个已经用整型值初始化的不带ID的节点*/ -#define lisrti(list, x) insertInTail(list, lni(x)); - -/*在链表尾部直接加入一个已经用浮点值初始化的不带ID的节点*/ -#define lisrtd(list, x) insertInTail(list, lnd(x)); - -/*在链表尾部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ -#define lisrtu(list, x) insertInTail(list, lnu(x)); - -/*在链表尾部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ -#define lisrtull(list, x) insertInTail(list, lnull(x)); - -/*在链表尾部直接加入一个已经用指针值初始化的不带ID的节点*/ -#define lisrtp(list, x) insertInTail(list, lnp(x)); - -/*在链表尾部直接加入一个已经用字符串值初始化的不带ID的节点*/ -#define lisrts(list, x) insertInTail(list, lns(x)); - -/**** - *头部相关 - */ - -/*在链表头部直接加入一个已经用整型值初始化的不带ID的节点*/ -#define lisrhi(list, x) insertInHead(list, lni(x)); - -/*在链表头部直接加入一个已经用浮点值初始化的不带ID的节点*/ -#define lisrhd(list, x) insertInHead(list, lnd(x)); - -/*在链表头部直接加入一个已经用无符号整型值初始化的不带ID的节点*/ -#define lisrhu(list, x) insertInHead(list, lnu(x)); - -/*在链表头部直接加入一个已经用无符号长整型值初始化的不带ID的节点*/ -#define lisrhull(list, x) insertInHead(list, lnull(x)); - -/*在链表头部直接加入一个已经用指针值初始化的不带ID的节点*/ -#define lisrhp(list, x) insertInHead(list, lnp(x)); - -/*在链表头部直接加入一个已经用字符串值初始化的不带ID的节点*/ -#define lisrhs(list, x) insertInHead(list, lns(x)); - - - - -/************************************************ - *节点快速获得储存值相关宏 - ************************************************/ - -/*快速获得指针类型的节点所储存的值*/ -#define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x)) - -/*快速获得整型类型的节点所储存的值*/ -#define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x)) - -/*快速获得浮点类型的节点所储存的值*/ -#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x)) - -/*快速获得字符串类型的节点所储存的值*/ -#define lidxs(list, x) getByStringForNode(findByIndexForNode(list, x)) - -/*快速获得无符号长整型类型的节点所储存的值*/ -#define lupdull(list,x,value) updateValueWithULLIntForNode(findByIndexForNode(list, x),value) - - - - -/************************************************ - *其他快速操作相关宏 - ************************************************/ - -/*通过节点的序号直接得到它的值*/ -#define lidxvle(list,x) (findByIndexForNode(list, x)->value) - -/*通过节点序号直接移除节点*/ -#define lrmvidx(list,x) removeByNode(list, findByIndexForNode(list, x) - -/*从列表头移除节点的缩略*/ -#define lpoph(list) popFromHead(list) - -/*从列表尾移除节点的缩略*/ -#define lpopt(list) popFromTail(list) - -/*通过节点的ID直接获得节点的值*/ -#define lfndsid(list,sid) (findByIdForNode(list,sid)->value) - -/*创建一个不带ID的链表的缩略*/ -#define lstns() initList(0); - -/*创建一个带有ID的链表缩略*/ -#define lstn() initList(1); - -#endif /* list_expand_1_h */ - - - /************************************************ *回调函数的便捷操作相关宏 ************************************************/ @@ -226,3 +79,5 @@ *若继续遍历则使用该宏 */ #define __CRETURN__ newCReturn() + +#endif /* event_h */ diff --git a/include/list/list_simple.h b/include/list/list_simple.h deleted file mode 100644 index 37f250c..0000000 --- a/include/list/list_simple.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef list_simple_h -#define list_simple_h - -#include - - -/************************************************ - *单向节点的快速初始化: 为新节点分配内存空间, - * 并使用输入值对其进行初始化. - ************************************************/ - -/* - *为新单向节点获取内存空间, 并使用整型值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithInt(int); - -/* - *为新单向节点获取内存空间, 并使用无符号整型值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithUInt(unsigned int); - -/* - *为新单向节点获取内存空间, 并使用浮点值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithDouble(double); - -/* - *为新单向节点获取内存空间, 并使用字符串值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithString(const char *); - -/* - *为新单向节点获取内存空间, 并使用指针值初始化新单向节点 - *返回: 若成功则返回指向新单向节点的指针,若失败函数返回NULL.*/ -extern s_Node *s_nodeWithPointer(const void *); - - -/* - *初始化单向链表节点,该种类节点可以与普通储存在List结构中. - *单向链表的引入主要在于对于简单问题提供更小开销的解决方案.但相应的操作函数较少,不如一般链表方便. - *返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/ -extern s_Node *s_initNode(void); - -/*在单项链表的头部插入一个节点 - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int s_insertInHead(List *p_list, s_Node *s_p_node); - -/* - *在单项链表的尾部插入一个节点 - *返回: 若成功函数返回0,若失败函数返回-1.*/ -extern int s_insertInTail(List *p_list, s_Node *s_p_node); - -/* - *释放单向节点所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseNode(s_Node *s_p_node); - -/* - *释放单向链表所占的内存空间 - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseList(List *p_list); - -/* - *自定义释放单向链表所占的内存空间 - *参数: func是一个函数指针,它指向的函数现在每次释放节点时调用, - * 接收储存在节点中的值的指针,释放用户自定义的结构体的所占用内存. - * 回调函数返回0代表释放成功,返回-1代表释放失败. - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseListForCustom(List *p_list, int (*func)(void *)); - -/* - *自定义释放单向节点所占的内存空间 - *参数: func是一个函数指针,它指向的函数现在每次释放单项节点时调用, - * 接收储存在单项节点中的值得指针,释放用户自定义的结构体的所占用内存. - * 回调函数返回0代表释放成功,返回-1代表释放失败. - *返回: 如果成功返回0, 失败则返回-1.*/ -extern int s_releaseNodeForCustom(s_Node *s_p_node, int (*func)(void *)); - -#endif /* list_simple_h */ diff --git a/include/list/list_type.h b/include/list/list_type.h index fcd1188..2bb2295 100644 --- a/include/list/list_type.h +++ b/include/list/list_type.h @@ -6,24 +6,24 @@ #endif /* - *节点的管理及操作的结构 + *链式结构节点的管理及操作的结构 */ typedef struct Node{ unsigned int type;//类型 void *value;//值指针 - struct Node *next;//指向下一个节点 - struct Node *last;//指向上一个节点 + struct Node *next;//指向下一个链式结构节点 + struct Node *last;//指向上一个链式结构节点 #ifdef id_enable SID *s_id; #endif } Node; /* - *链表的管理及操作的结构 + *链式结构的管理及操作的结构 */ typedef struct List{ - Node *head;//指向第一个节点 - Node *tail;//指向最后一个节点 + Node *head;//指向第一个链式结构节点 + Node *tail;//指向最后一个链式结构节点 uint64_t length; #ifdef id_enable SID *s_id; diff --git a/src/datastruct/chain/chain_calculate.c b/src/datastruct/chain/chain_calculate.c index 00e9466..64a66d3 100644 --- a/src/datastruct/chain/chain_calculate.c +++ b/src/datastruct/chain/chain_calculate.c @@ -9,7 +9,7 @@ @return 以字节为单位返回链表及链表内包含的节点所占的内存空间 */ uint64_t calListMemory(Chain * p_list){ - Node *p_node = p_list->head; + CNode *p_node = p_list->head; uint64_t nodes_size = 0LL; uint64_t list_size = sizeof(p_list); while(p_node != NULL){ diff --git a/src/event/event_callback.c b/src/event/event_callback.c index 4a554a8..a703024 100644 --- a/src/event/event_callback.c +++ b/src/event/event_callback.c @@ -105,13 +105,9 @@ Chain *newReturn(int if_status ,int status, char *argc, ...){ lisrtull(p_list, va_arg(args, unsigned long long)); count += 2; } - else{ - count++; - } - } - else{ - lisrtu(p_list, va_arg(args, unsigned int)); + else count++; } + else lisrtu(p_list, va_arg(args, unsigned int)); break; default: break; @@ -130,6 +126,6 @@ Chain *newReturn(int if_status ,int status, char *argc, ...){ @return 指向构造的参数列表的指针 */ -Chain *newCReturn(void){ +inline Chain *newCReturn(void){ return newReturn(1, 0, NULL); } diff --git a/src/memory/list/list_copy.c b/src/memory/list/list_copy.c index 4588fd3..2dc950e 100644 --- a/src/memory/list/list_copy.c +++ b/src/memory/list/list_copy.c @@ -3,10 +3,10 @@ /** - 以一个已存在的节点为模板创建一个相同的新的节点 + 以一个已存在的链式结构节点为模板创建一个相同的新的链式结构节点 - @param p_node 指向作为模板的节点的指针 - @return 返回指向新的节点的指针 + @param p_node 指向作为模板的链式结构节点的指针 + @return 返回指向新的链式结构节点的指针 */ Node *copyNode(Node *p_node) { Node *t_node = NULL; @@ -25,10 +25,10 @@ Node *copyNode(Node *p_node) { /** - 根据已存在的链表创建一个相同的新的链表 + 根据已存在的链式结构创建一个相同的新的链式结构 - @param p_list 指向作为模板的链表的指针 - @return 返回指向新链表的指针 + @param p_list 指向作为模板的链式结构的指针 + @return 返回指向新链式结构的指针 */ List *copyList(List *p_list) { Node *p_node; diff --git a/src/memory/list/list_find.c b/src/memory/list/list_find.c index 34c7a90..360c462 100644 --- a/src/memory/list/list_find.c +++ b/src/memory/list/list_find.c @@ -4,11 +4,11 @@ //如果ID模块可能启用则编译以下代码 #ifdef id_enable /** - 通过ID查找链表中符合条件的第一个节点 + 通过ID查找链式结构中符合条件的第一个链式结构节点 - @param p_list 指向目标链表的指针 + @param p_list 指向目标链式结构的指针 @param s_id ID值 - @return 成功返回指向符合条件的节点的指针,不成功则返回NULL + @return 成功返回指向符合条件的链式结构节点的指针,不成功则返回NULL */ Node *findByIdForNode(List *p_list, SID * s_id) { Node *ph_node = p_list->head; @@ -39,12 +39,12 @@ Node *findByIdForNode(List *p_list, SID * s_id) { /** - 通过值来查找链表中符合条件的第一个节点 + 通过值来查找链式结构中符合条件的第一个链式结构节点 - @param p_list 指向目标链表的指针 + @param p_list 指向目标链式结构的指针 @param type 值的类型 @param value 值 - @return 成功返回指向符合条件的节点的指针,不成功则返回NULL + @return 成功返回指向符合条件的链式结构节点的指针,不成功则返回NULL */ Node *findByValue(List *p_list, uint type, const void *value) { Node *p_node = p_list->head; @@ -82,12 +82,12 @@ Node *findByValue(List *p_list, uint type, const void *value) { } /** - 通过值来查找链表中符合条件的所有节点 + 通过值来查找链式结构中符合条件的所有链式结构节点 - @param p_list 指向目标链表的指针 + @param p_list 指向目标链式结构的指针 @param type 值的类型 @param value 值 - @return 返回含有所有符合条件的节点的重组链表 + @return 返回含有所有符合条件的链式结构节点的重组链式结构 */ List *mply_findByValue(List *p_list, unsigned int type, const void *value) { List *f_list = initList(0); diff --git a/src/memory/list/list_info.c b/src/memory/list/list_info.c index 2404b22..bf70e4a 100644 --- a/src/memory/list/list_info.c +++ b/src/memory/list/list_info.c @@ -3,20 +3,20 @@ /** - 返回链表的长度 + 返回链式结构的长度 - @param p_list 指向目标链表的指针 - @return 返回目标链表的长度 + @param p_list 指向目标链式结构的指针 + @return 返回目标链式结构的长度 */ uint64_t len(List *p_list) { return p_list->length; } /** - 检查链表是否为空 + 检查链式结构是否为空 - @param p_list 指向目标链表的指针 - @return 目标链表为空返回1,不为空返回0 + @param p_list 指向目标链式结构的指针 + @return 目标链式结构为空返回1,不为空返回0 */ int isListEmpty(List *p_list) { if (p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty. diff --git a/src/memory/list/list_init.c b/src/memory/list/list_init.c index 0747e4d..db4bfab 100644 --- a/src/memory/list/list_init.c +++ b/src/memory/list/list_init.c @@ -3,10 +3,10 @@ /** - 创建一个新的节点,并为其分配内存空间 + 创建一个新的链式结构节点,并为其分配内存空间 - @param if_sid 新的节点是否带ID - @return 返回指向新的节点的内存地址指针 + @param if_sid 新的链式结构节点是否带ID + @return 返回指向新的链式结构节点的内存地址指针 */ #ifdef id_enable Node *initNode(_Bool if_sid) @@ -27,7 +27,7 @@ Node *initNode(void) p_node->next = NULL; p_node->last = NULL; p_node->type = VOID; -// 链表内存安全模式相关操作 +// 链式结构内存安全模式相关操作 if (if_safeModeForNode) { if_safeModeForNode = 0; prec_node = initNode(0); @@ -39,10 +39,10 @@ Node *initNode(void) } /** - 创建一个新的链表,并为其分配内存空间 + 创建一个新的链式结构,并为其分配内存空间 - @param if_sid 新的链表是否带ID - @return 返回指向新的链表的内存地址指针 + @param if_sid 新的链式结构是否带ID + @return 返回指向新的链式结构的内存地址指针 */ #ifdef id_enable List *initList(_Bool if_sid) @@ -73,9 +73,9 @@ List *initList(void) } /** - 为新的节点设定初始值 + 为新的链式结构节点设定初始值 - @param p_node 指向目标节点的指针 + @param p_node 指向目标链式结构节点的指针 @param type 值得类型 @param p_value 指向目标值的内存空间的指针 @return 执行成功则返回0 diff --git a/src/memory/list/list_insert.c b/src/memory/list/list_insert.c index 72c76a4..a38ef2b 100644 --- a/src/memory/list/list_insert.c +++ b/src/memory/list/list_insert.c @@ -2,10 +2,10 @@ #include /** - 在链表的头部插入节点 + 在链式结构的头部插入链式结构节点 - @param p_list 指向目标链表的指针 - @param p_node 指向目标节点的指针 + @param p_list 指向目标链式结构的指针 + @param p_node 指向目标链式结构节点的指针 @return 函数执行成功返回0 */ int insertInHead(List *p_list, Node *p_node) { @@ -24,19 +24,13 @@ int insertInHead(List *p_list, Node *p_node) { } /** - 在链表的尾部插入节点 + 在链式结构的尾部插入链式结构节点 - @param p_list 指向目标链表的指针 - @param p_node 指向目标节点的指针 + @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; diff --git a/src/memory/list/safe_mode.c b/src/memory/list/safe_mode.c index a682699..a5abe1a 100644 --- a/src/memory/list/safe_mode.c +++ b/src/memory/list/safe_mode.c @@ -1,6 +1,5 @@ #include #include -#include static int if_safeModeForNode = 0; static List *node_list = NULL;