List aparted and created chain.
This commit is contained in:
parent
14ec30b0be
commit
8f934bfaa3
@ -1,8 +1,8 @@
|
|||||||
#ifndef list_expand_h
|
#ifndef chain_h
|
||||||
#define list_expand_h
|
#define chain_h
|
||||||
|
|
||||||
#include <list/list_type.h>
|
|
||||||
|
|
||||||
|
#include <chain/chain_type.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
|
||||||
/************************************************
|
/************************************************
|
||||||
*节点的快速初始化: 为新节点分配内存空间,
|
*节点的快速初始化: 为新节点分配内存空间,
|
||||||
@ -13,37 +13,37 @@
|
|||||||
*为新节点获取内存空间, 并使用整型值初始化新节点
|
*为新节点获取内存空间, 并使用整型值初始化新节点
|
||||||
*参数if_sid指示函数是否为节点获取ID
|
*参数if_sid指示函数是否为节点获取ID
|
||||||
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
||||||
extern Node *nodeWithInt(int, _Bool if_sid);
|
extern CNode *nodeWithInt(int, _Bool if_sid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*为新节点获取内存空间, 并使用无符号整型值初始化新节点
|
*为新节点获取内存空间, 并使用无符号整型值初始化新节点
|
||||||
*参数if_sid指示函数是否为节点获取ID
|
*参数if_sid指示函数是否为节点获取ID
|
||||||
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
||||||
extern Node *nodeWithUInt(unsigned int, _Bool if_sid);
|
extern CNode *nodeWithUInt(unsigned int, _Bool if_sid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*为新节点获取内存空间, 并使用无符号长整型值初始化新节点
|
*为新节点获取内存空间, 并使用无符号长整型值初始化新节点
|
||||||
*参数if_sid指示函数是否为节点获取ID
|
*参数if_sid指示函数是否为节点获取ID
|
||||||
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
||||||
extern Node *nodeWithULLInt(unsigned long long, _Bool if_sid);
|
extern CNode *nodeWithULLInt(unsigned long long, _Bool if_sid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*为新节点获取内存空间, 并使用浮点值初始化新节点
|
*为新节点获取内存空间, 并使用浮点值初始化新节点
|
||||||
*参数if_sid指示函数是否为节点获取ID
|
*参数if_sid指示函数是否为节点获取ID
|
||||||
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
||||||
extern Node *nodeWithDouble(double, _Bool if_sid);
|
extern CNode *nodeWithDouble(double, _Bool if_sid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*为新节点获取内存空间, 并使用字符串值初始化新节点
|
*为新节点获取内存空间, 并使用字符串值初始化新节点
|
||||||
*参数if_sid指示函数是否为节点获取ID
|
*参数if_sid指示函数是否为节点获取ID
|
||||||
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
||||||
extern Node *nodeWithString(const char *, _Bool if_sid);
|
extern CNode *nodeWithString(const char *, _Bool if_sid);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*为新节点获取内存空间, 并使用指针值初始化新节点
|
*为新节点获取内存空间, 并使用指针值初始化新节点
|
||||||
*参数if_sid指示函数是否为节点获取ID
|
*参数if_sid指示函数是否为节点获取ID
|
||||||
*返回: 若成功则返回指向新节点的指针,若失败函数返回NULL.*/
|
*返回: 若成功则返回指向新节点的指针,若失败函数返回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.*/
|
*返回: 若成功指向新嵌套节点的指针,若失败函数返回NULL.*/
|
||||||
extern Node *nodeWithComplex(void);
|
extern CNode *nodeWithComplex(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的值初始化嵌套节点
|
*用输入的值初始化嵌套节点
|
||||||
*参数: type指明所输入值的类型,value为指向所输入值的内存空间的指针
|
*参数: type指明所输入值的类型,value为指向所输入值的内存空间的指针
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int addValueForComplex(Node *, int type, void *value);
|
extern int addValueForComplex(CNode *, int type, void *value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的整型值初始化嵌套节点
|
*用输入的整型值初始化嵌套节点
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int addIntForComplex(Node *, int);
|
extern int addIntForComplex(CNode *, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的浮点值初始化嵌套节点
|
*用输入的浮点值初始化嵌套节点
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int addDoubleForComplex(Node *, double);
|
extern int addDoubleForComplex(CNode *, double);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的字符串初始化嵌套节点
|
*用输入的字符串初始化嵌套节点
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int addStringForComplex(Node *, char *);
|
extern int addStringForComplex(CNode *, char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的指针值初始化嵌套节点
|
*用输入的指针值初始化嵌套节点
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int addPointerForComplex(Node *, void *);
|
extern int addPointerForComplex(CNode *, void *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -94,27 +94,27 @@ extern int addPointerForComplex(Node *, void *);
|
|||||||
/*
|
/*
|
||||||
*用输入的整型值更新节点中的值
|
*用输入的整型值更新节点中的值
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int updateValueWithIntForNode(Node *,int);
|
extern int updateValueWithIntForNode(CNode *,int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的无符号长整型值更新节点中的值
|
*用输入的无符号长整型值更新节点中的值
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int updateValueWithULLIntForNode(Node *, uint64_t);
|
extern int updateValueWithULLIntForNode(CNode *, uint64_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的浮点值更新节点中的值
|
*用输入的浮点值更新节点中的值
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int updateValueWithDoubleForNode(Node *,double);
|
extern int updateValueWithDoubleForNode(CNode *,double);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的字符串值更新节点中的值
|
*用输入的字符串值更新节点中的值
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int updateValueWithStringForNode(Node *,char *);
|
extern int updateValueWithStringForNode(CNode *,char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*用输入的指针值更新节点中的值
|
*用输入的指针值更新节点中的值
|
||||||
*返回: 若成功则返回0,若失败函数返回-1.*/
|
*返回: 若成功则返回0,若失败函数返回-1.*/
|
||||||
extern int updateValueWithPointerForNode(Node *,void *);
|
extern int updateValueWithPointerForNode(CNode *,void *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -126,22 +126,22 @@ extern int updateValueWithPointerForNode(Node *,void *);
|
|||||||
/*
|
/*
|
||||||
*通过输入的整型值,查找链表中多个含有该值的节点
|
*通过输入的整型值,查找链表中多个含有该值的节点
|
||||||
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
||||||
List *mply_findByIntForNode(List*, int);
|
Chain *mply_findByIntForNode(Chain*, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过输入的浮点值,查找链表中多个含有该值的节点
|
*通过输入的浮点值,查找链表中多个含有该值的节点
|
||||||
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
||||||
List *mply_findByDoubleForNode(List*, double);
|
Chain *mply_findByDoubleForNode(Chain*, double);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过输入的字符串值,查找链表中多个含有该值的节点
|
*通过输入的字符串值,查找链表中多个含有该值的节点
|
||||||
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
||||||
List *mply_findByStringForNode(List*, char *);
|
Chain *mply_findByStringForNode(Chain*, char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过输入的指针值,查找链表中多个含有该值的节点
|
*通过输入的指针值,查找链表中多个含有该值的节点
|
||||||
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
*返回: 若成功则返回一个储存由这些指向这些节点指针组成的链表,若失败函数返回NULL.*/
|
||||||
List *mply_findByPointerForNode(List*, void *);
|
Chain *mply_findByPointerForNode(Chain*, void *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -158,22 +158,22 @@ List *mply_findByPointerForNode(List*, void *);
|
|||||||
然后进行相关操作,并返回一个链表,其中包含返回状态,若有,也可以包含想要传递给母函数的值
|
然后进行相关操作,并返回一个链表,其中包含返回状态,若有,也可以包含想要传递给母函数的值
|
||||||
expand_resources为一个链表,储存母函数想要传递给回调函数的值
|
expand_resources为一个链表,储存母函数想要传递给回调函数的值
|
||||||
*返回: 如果回调函数有需要返回给母函数的值,则返回包含这些值的链表,否则返回NULL.*/
|
*返回: 如果回调函数有需要返回给母函数的值,则返回包含这些值的链表,否则返回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.*/
|
*返回: 如果链表为空返回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*/
|
*返回: 如果成功返回指向该节点的指针,如果失败则返回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相同.
|
*注意: 源节点与新节点ID相同.
|
||||||
*返回: 若成功函数返回指向新节点的指针,若失败则返回NULL*/
|
*返回: 若成功函数返回指向新节点的指针,若失败则返回NULL*/
|
||||||
extern Node *copyNode(Node *);
|
extern CNode *copyNode(CNode *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*链表的复制,复制将会为新链表重新分配内存,并将源链表的所有节点复制.
|
*链表的复制,复制将会为新链表重新分配内存,并将源链表的所有节点复制.
|
||||||
*注意: 源链表与新链表ID相同.
|
*注意: 源链表与新链表ID相同.
|
||||||
*返回: 若成功函数返回指向新链表的指针,若失败则返回NULL*/
|
*返回: 若成功函数返回指向新链表的指针,若失败则返回NULL*/
|
||||||
List *copyList(List *p_list);
|
Chain *copyList(Chain *p_list);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过序号查找相关的单个节点
|
*通过序号查找相关的单个节点
|
||||||
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
||||||
extern Node *findByIndexForNode(List *, unsigned long long);
|
extern CNode *findByIndexForNode(Chain *, unsigned long long);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过整型值查找储存该值的单个节点
|
*通过整型值查找储存该值的单个节点
|
||||||
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
||||||
extern Node *findByIntForNode(List *, int);
|
extern CNode *findByIntForNode(Chain *, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过浮点值查找储存该值的单个节点
|
*通过浮点值查找储存该值的单个节点
|
||||||
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
||||||
extern Node *findByDoubleForNode(List *, double);
|
extern CNode *findByDoubleForNode(Chain *, double);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过字符串中查找储存该值的单个节点.
|
*通过字符串中查找储存该值的单个节点.
|
||||||
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
||||||
extern Node *findByStringForNode(List *, char *);
|
extern CNode *findByStringForNode(Chain *, char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*通过指针值查找储存该值的单个节点.
|
*通过指针值查找储存该值的单个节点.
|
||||||
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
*返回: 如果成功返回指向该节点的指针,如果失败则返回NULL.*/
|
||||||
extern Node *findByPointerForNode(List *, void *);
|
extern CNode *findByPointerForNode(Chain *, void *);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#endif /* chain_h */
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef list_print_h
|
#ifndef list_print_h
|
||||||
#define list_print_h
|
#define list_print_h
|
||||||
|
|
||||||
#include <list/list_type.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand_1.h>
|
#include <event/event.h>
|
||||||
|
|
||||||
/************************************************
|
/************************************************
|
||||||
*链表或节点的输出: 格式化输出链表或节点的属性
|
*链表或节点的输出: 格式化输出链表或节点的属性
|
||||||
@ -11,22 +11,22 @@
|
|||||||
/*
|
/*
|
||||||
*输出链表及其中节点的相关信息
|
*输出链表及其中节点的相关信息
|
||||||
*参数: priority为每行输出信息前的空格数除以4*/
|
*参数: priority为每行输出信息前的空格数除以4*/
|
||||||
void printListInfo(List *p_list,int priority);
|
void printListInfo(Chain *p_list,int priority);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*输出节点中的相关信息
|
*输出节点中的相关信息
|
||||||
*参数: priority为每行输出信息前的空格数乘以4*/
|
*参数: priority为每行输出信息前的空格数乘以4*/
|
||||||
void printNodeInfo(Node *p_node,int priority);
|
void printNodeInfo(CNode *p_node,int priority);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*输出链表及其中节点的相关信息
|
*输出链表及其中节点的相关信息
|
||||||
*/
|
*/
|
||||||
void printList(List *);
|
void printList(Chain *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*自定义输出链表及其中节点的相关信息
|
*自定义输出链表及其中节点的相关信息
|
||||||
*参数: func为一个函数指针, 指向函数的职能在于输出节点中的用户自定义结构的相关信息*/
|
*参数: func为一个函数指针, 指向函数的职能在于输出节点中的用户自定义结构的相关信息*/
|
||||||
void printListForCustom(List *p_list,void (*func)(void *value));
|
void printListForCustom(Chain *p_list,void (*func)(void *value));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*printListForCustom函数的回调函数
|
*printListForCustom函数的回调函数
|
||||||
@ -36,7 +36,7 @@ __CALLBACK_STATE(printListForCustom);
|
|||||||
/*
|
/*
|
||||||
*输出节点中的相关信息
|
*输出节点中的相关信息
|
||||||
*/
|
*/
|
||||||
void printNode(Node *p_node);
|
void printNode(CNode *p_node);
|
||||||
|
|
||||||
|
|
||||||
#endif /* list_print_h */
|
#endif /* list_print_h */
|
16
include/chain/chain_type.h
Normal file
16
include/chain/chain_type.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef chain_type_h
|
||||||
|
#define chain_type_h
|
||||||
|
|
||||||
|
#include <list/list_type.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
*节点的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct Node CNode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*链表的管理及操作的结构
|
||||||
|
*/
|
||||||
|
typedef struct List Chain;
|
||||||
|
|
||||||
|
#endif /* chain_type_h */
|
@ -144,13 +144,13 @@ extern int releaseDFile(D_FILE *p_file);
|
|||||||
*将链表转化为标准数据结构
|
*将链表转化为标准数据结构
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
*/
|
*/
|
||||||
extern STD_DATA *listToSTD(List *);
|
extern STD_DATA *listToSTD(Chain *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*将标准数据结构转换成链表
|
*将标准数据结构转换成链表
|
||||||
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
*返回: 处理成功则返回指向相关结构体所在内存空间的指针,不成功则返回NULL.
|
||||||
*/
|
*/
|
||||||
extern List *standardDataToList(STD_DATA *);
|
extern Chain *standardDataToList(STD_DATA *);
|
||||||
|
|
||||||
//STD_DATA *stackToSTD(Stack *);
|
//STD_DATA *stackToSTD(Stack *);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ typedef struct file_head{
|
|||||||
typedef struct data_file{
|
typedef struct data_file{
|
||||||
FILE *fp;//数据文件
|
FILE *fp;//数据文件
|
||||||
F_HEAD *pf_head;//数据文件头
|
F_HEAD *pf_head;//数据文件头
|
||||||
List *pf_stdlst;//数据文件的标志数据结构的储存链表
|
Chain *pf_stdlst;//数据文件的标志数据结构的储存链表
|
||||||
}D_FILE;
|
}D_FILE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -59,8 +59,8 @@ typedef struct standard_data{
|
|||||||
uint32_t size;//标准数据结构在数据文件中的大小
|
uint32_t size;//标准数据结构在数据文件中的大小
|
||||||
uint32_t location;//标准数据结构的头在数据文件中的定位
|
uint32_t location;//标准数据结构的头在数据文件中的定位
|
||||||
_Bool lock;//标准数据文件是否被锁住
|
_Bool lock;//标准数据文件是否被锁住
|
||||||
List *pd_blocklst;//数据块储存链表
|
Chain *pd_blocklst;//数据块储存链表
|
||||||
List *pd_ctnlst;//数据块连接关系结构的储存链表
|
Chain *pd_ctnlst;//数据块连接关系结构的储存链表
|
||||||
}STD_DATA;
|
}STD_DATA;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef list_expand_1_h
|
#ifndef list_expand_1_h
|
||||||
#define list_expand_1_h
|
#define list_expand_1_h
|
||||||
|
|
||||||
#include <list/list_expand.h>
|
#include <chain/chain.h>
|
||||||
|
|
||||||
/************************************************
|
/************************************************
|
||||||
*节点快速初始化相关宏,提供函数名较为简单的调用方式
|
*节点快速初始化相关宏,提供函数名较为简单的调用方式
|
@ -1,65 +0,0 @@
|
|||||||
#ifndef list_quick_h
|
|
||||||
#define list_quick_h
|
|
||||||
|
|
||||||
#include <list/list_type.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
*长链表模式下链表缓存块的记录结构
|
|
||||||
*/
|
|
||||||
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 */
|
|
@ -9,9 +9,6 @@
|
|||||||
*节点的管理及操作的结构
|
*节点的管理及操作的结构
|
||||||
*/
|
*/
|
||||||
typedef struct Node{
|
typedef struct Node{
|
||||||
#ifdef list_quick_enable
|
|
||||||
unsigned long long f_number;//长链表模式下,分派的数组节点编号
|
|
||||||
#endif
|
|
||||||
unsigned int type;//类型
|
unsigned int type;//类型
|
||||||
void *value;//值指针
|
void *value;//值指针
|
||||||
struct Node *next;//指向下一个节点
|
struct Node *next;//指向下一个节点
|
||||||
@ -21,29 +18,13 @@ typedef struct Node{
|
|||||||
#endif
|
#endif
|
||||||
} Node;
|
} Node;
|
||||||
|
|
||||||
/*
|
|
||||||
*单向节点的管理及操作的结构
|
|
||||||
*/
|
|
||||||
typedef struct simple_Node{
|
|
||||||
void *value;//值指针
|
|
||||||
struct simple_Node *next;//指向下一个节点
|
|
||||||
}s_Node;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*链表的管理及操作的结构
|
*链表的管理及操作的结构
|
||||||
*/
|
*/
|
||||||
typedef struct List{
|
typedef struct List{
|
||||||
Node *head;//指向第一个节点
|
Node *head;//指向第一个节点
|
||||||
Node *tail;//指向最后一个节点
|
Node *tail;//指向最后一个节点
|
||||||
#ifdef list_simple_h
|
uint64_t length;
|
||||||
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
|
#ifdef id_enable
|
||||||
SID *s_id;
|
SID *s_id;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list_type.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int checkIfDataFile(D_FILE *p_dfile){
|
int checkIfDataFile(D_FILE *p_dfile){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
D_FILE *initDataFileForWrite(char *route){
|
D_FILE *initDataFileForWrite(char *route){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
|
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int dataFileWriteIn(D_FILE *p_dfile){
|
int dataFileWriteIn(D_FILE *p_dfile){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int releaseDFile(D_FILE *p_dfile){
|
int releaseDFile(D_FILE *p_dfile){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
__CALLBACK_DEFINE(findStandardDataBySid){
|
__CALLBACK_DEFINE(findStandardDataBySid){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){
|
int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
uint32_t calStandardData(STD_DATA *p_std){
|
uint32_t calStandardData(STD_DATA *p_std){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){
|
STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){
|
int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int releaseStandardData(STD_DATA *p_std){
|
int releaseStandardData(STD_DATA *p_std){
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){
|
STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
__CALLBACK_DEFINE(StandardDBlockWrite){
|
__CALLBACK_DEFINE(StandardDBlockWrite){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int releaseSTDBlocks(STD_BLOCKS *p_stdb){
|
int releaseSTDBlocks(STD_BLOCKS *p_stdb){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
__CALLBACK_DEFINE(calStandardDataCTN){
|
__CALLBACK_DEFINE(calStandardDataCTN){
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
int releaseSTDConnection(STD_CTN *p_stdc){
|
int releaseSTDConnection(STD_CTN *p_stdc){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
STD_DATA *listToSTD(List *p_list){
|
STD_DATA *listToSTD(List *p_list){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
#include <communicate/communicate_file.h>
|
#include <communicate/communicate_file.h>
|
||||||
|
|
||||||
List *standardDataToList(STD_DATA *p_std){
|
List *standardDataToList(STD_DATA *p_std){
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list_type.h>
|
#include <chain/chain_type.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
计算链表占用的内存空间大小,以字节为单位输出。
|
计算链表占用的内存空间大小,以字节为单位输出。
|
||||||
@ -7,7 +8,7 @@
|
|||||||
@param p_list 指向目标链表的指针
|
@param p_list 指向目标链表的指针
|
||||||
@return 以字节为单位返回链表及链表内包含的节点所占的内存空间
|
@return 以字节为单位返回链表及链表内包含的节点所占的内存空间
|
||||||
*/
|
*/
|
||||||
uint64_t calListMemory(List * p_list){
|
uint64_t calListMemory(Chain * p_list){
|
||||||
Node *p_node = p_list->head;
|
Node *p_node = p_list->head;
|
||||||
uint64_t nodes_size = 0LL;
|
uint64_t nodes_size = 0LL;
|
||||||
uint64_t list_size = sizeof(p_list);
|
uint64_t list_size = sizeof(p_list);
|
@ -1,14 +1,14 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
创建一个新的且内容为链表的节点
|
创建一个新的且内容为链表的节点
|
||||||
|
|
||||||
@return 返回指向新节点的指针
|
@return 返回指向新节点的指针
|
||||||
*/
|
*/
|
||||||
Node *nodeWithComplex(void) {
|
CNode *nodeWithComplex(void) {
|
||||||
Node *p_node = initNode(0);
|
CNode *p_node = initNode(0);
|
||||||
p_node->type = LIST;
|
p_node->type = LIST;
|
||||||
p_node->value = initList(0);
|
p_node->value = initList(0);
|
||||||
return p_node;
|
return p_node;
|
||||||
@ -23,9 +23,9 @@ Node *nodeWithComplex(void) {
|
|||||||
@param value 指向该内容所在内存的指针
|
@param value 指向该内容所在内存的指针
|
||||||
@return 操作成功则返回一个非负整数
|
@return 操作成功则返回一个非负整数
|
||||||
*/
|
*/
|
||||||
int addValueForComplex(Node * p_node, int type, void *value) {
|
int addValueForComplex(CNode * p_node, int type, void *value) {
|
||||||
List *c_list;
|
List *c_list;
|
||||||
Node *c_node;
|
CNode *c_node;
|
||||||
if (p_node->type == LIST) {
|
if (p_node->type == LIST) {
|
||||||
c_list = (List *)p_node->value;
|
c_list = (List *)p_node->value;
|
||||||
c_node = initNode(0);
|
c_node = initNode(0);
|
||||||
@ -44,7 +44,7 @@ int addValueForComplex(Node * p_node, int type, void *value) {
|
|||||||
@param temp 相应的整型值
|
@param temp 相应的整型值
|
||||||
@return 操作成功则返回非负整数
|
@return 操作成功则返回非负整数
|
||||||
*/
|
*/
|
||||||
int addIntForComplex(Node *p_node, int temp) {
|
int addIntForComplex(CNode *p_node, int temp) {
|
||||||
if (p_node->type == LIST) {
|
if (p_node->type == LIST) {
|
||||||
int *p_temp = (int *)malloc(sizeof(int));
|
int *p_temp = (int *)malloc(sizeof(int));
|
||||||
if(p_temp == NULL){
|
if(p_temp == NULL){
|
||||||
@ -65,7 +65,7 @@ int addIntForComplex(Node *p_node, int temp) {
|
|||||||
@param temp 相应的双精度浮点值
|
@param temp 相应的双精度浮点值
|
||||||
@return 操作成功则返回非负整数
|
@return 操作成功则返回非负整数
|
||||||
*/
|
*/
|
||||||
int addDoubleForComplex(Node *p_node, double temp) {
|
int addDoubleForComplex(CNode *p_node, double temp) {
|
||||||
if (p_node->type == LIST) {
|
if (p_node->type == LIST) {
|
||||||
double *p_temp = (double *)malloc(sizeof(double));
|
double *p_temp = (double *)malloc(sizeof(double));
|
||||||
if(p_temp == NULL){
|
if(p_temp == NULL){
|
||||||
@ -86,7 +86,7 @@ int addDoubleForComplex(Node *p_node, double temp) {
|
|||||||
@param temp 相应的字符数组
|
@param temp 相应的字符数组
|
||||||
@return 操作成功则返回非负整数
|
@return 操作成功则返回非负整数
|
||||||
*/
|
*/
|
||||||
int addStringForComplex(Node *p_node, char *temp) {
|
int addStringForComplex(CNode *p_node, char *temp) {
|
||||||
if (p_node->type == LIST) {
|
if (p_node->type == LIST) {
|
||||||
char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1));
|
char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1));
|
||||||
if(p_temp == NULL){
|
if(p_temp == NULL){
|
||||||
@ -107,7 +107,7 @@ int addStringForComplex(Node *p_node, char *temp) {
|
|||||||
@param temp 相应的指针
|
@param temp 相应的指针
|
||||||
@return 操作成功则返回非负整数
|
@return 操作成功则返回非负整数
|
||||||
*/
|
*/
|
||||||
int addPointerForComplex(Node *p_node, void *temp) {
|
int addPointerForComplex(CNode *p_node, void *temp) {
|
||||||
if (p_node->type == LIST) {
|
if (p_node->type == LIST) {
|
||||||
addValueForComplex(p_node, POINTER, temp);
|
addValueForComplex(p_node, POINTER, temp);
|
||||||
return 0;
|
return 0;
|
@ -1,10 +1,5 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
//长链表模式可能启用则包含以下头文件
|
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,8 +9,8 @@
|
|||||||
@param target 目标节点中储存的整型值
|
@param target 目标节点中储存的整型值
|
||||||
@return 返回指向目标节点的指针
|
@return 返回指向目标节点的指针
|
||||||
*/
|
*/
|
||||||
Node *findByIntForNode(List *p_list, int target) {
|
CNode *findByIntForNode(Chain *p_list, int target) {
|
||||||
Node *t_node;
|
CNode *t_node;
|
||||||
int *p_target = (int *)malloc(sizeof(int));
|
int *p_target = (int *)malloc(sizeof(int));
|
||||||
*p_target = target;
|
*p_target = target;
|
||||||
t_node = findByValue(p_list, INT, p_target);
|
t_node = findByValue(p_list, INT, p_target);
|
||||||
@ -30,8 +25,8 @@ Node *findByIntForNode(List *p_list, int target) {
|
|||||||
@param target 目标节点中储存的双精度浮点值
|
@param target 目标节点中储存的双精度浮点值
|
||||||
@return 返回指向目标节点的指针
|
@return 返回指向目标节点的指针
|
||||||
*/
|
*/
|
||||||
Node *findByDoubleForNode(List *p_list, double target) {
|
CNode *findByDoubleForNode(Chain *p_list, double target) {
|
||||||
Node *t_node;
|
CNode *t_node;
|
||||||
double *p_target = (double *)malloc(sizeof(double));
|
double *p_target = (double *)malloc(sizeof(double));
|
||||||
*p_target = target;
|
*p_target = target;
|
||||||
t_node = findByValue(p_list, DOUBLE, p_target);
|
t_node = findByValue(p_list, DOUBLE, p_target);
|
||||||
@ -46,8 +41,8 @@ Node *findByDoubleForNode(List *p_list, double target) {
|
|||||||
@param target 目标节点中储存的字符数组值
|
@param target 目标节点中储存的字符数组值
|
||||||
@return 返回指向目标节点的指针
|
@return 返回指向目标节点的指针
|
||||||
*/
|
*/
|
||||||
Node *findByStringForNode(List *p_list, char *target) {
|
CNode *findByStringForNode(Chain *p_list, char *target) {
|
||||||
Node *t_node;
|
CNode *t_node;
|
||||||
char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1));
|
char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1));
|
||||||
strcpy(p_temp, target);
|
strcpy(p_temp, target);
|
||||||
t_node = findByValue(p_list, STRING, p_temp);
|
t_node = findByValue(p_list, STRING, p_temp);
|
||||||
@ -63,8 +58,8 @@ Node *findByStringForNode(List *p_list, char *target) {
|
|||||||
@param target 目标节点中储存的字符指针值
|
@param target 目标节点中储存的字符指针值
|
||||||
@return 返回指向目标节点的指针
|
@return 返回指向目标节点的指针
|
||||||
*/
|
*/
|
||||||
Node *findByPointerForNode(List *p_list, void *target) {
|
CNode *findByPointerForNode(Chain *p_list, void *target) {
|
||||||
Node *t_node = findByValue(p_list, POINTER, target);
|
CNode *t_node = findByValue(p_list, POINTER, target);
|
||||||
return t_node;
|
return t_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,12 +71,12 @@ Node *findByPointerForNode(List *p_list, void *target) {
|
|||||||
@param temp 目标节点中储存的整型值
|
@param temp 目标节点中储存的整型值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@return 返回包含所有符合条件的节点的新的重组链表
|
||||||
*/
|
*/
|
||||||
List *mply_findByInt(List* p_list, int temp) {
|
Chain *mply_findByInt(Chain* p_list, int temp) {
|
||||||
int *p_temp = (int *)malloc(sizeof(int));
|
int *p_temp = (int *)malloc(sizeof(int));
|
||||||
if(p_temp == NULL){
|
if(p_temp == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
List *t_list;
|
Chain *t_list;
|
||||||
*p_temp = temp;
|
*p_temp = temp;
|
||||||
t_list = mply_findByValue(p_list, INT, (void *)p_temp);
|
t_list = mply_findByValue(p_list, INT, (void *)p_temp);
|
||||||
free(p_temp);
|
free(p_temp);
|
||||||
@ -95,8 +90,8 @@ List *mply_findByInt(List* p_list, int temp) {
|
|||||||
@param temp 目标节点中储存的双精度浮点值
|
@param temp 目标节点中储存的双精度浮点值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@return 返回包含所有符合条件的节点的新的重组链表
|
||||||
*/
|
*/
|
||||||
List *mply_findByDouble(List* p_list, double temp) {
|
Chain *mply_findByDouble(Chain* p_list, double temp) {
|
||||||
List *t_list;
|
Chain *t_list;
|
||||||
double *p_temp = (double *)malloc(sizeof(double));
|
double *p_temp = (double *)malloc(sizeof(double));
|
||||||
if(p_temp == NULL){
|
if(p_temp == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -114,8 +109,8 @@ List *mply_findByDouble(List* p_list, double temp) {
|
|||||||
@param temp 目标节点中储存的字符串值
|
@param temp 目标节点中储存的字符串值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@return 返回包含所有符合条件的节点的新的重组链表
|
||||||
*/
|
*/
|
||||||
List *mply_findByString(List* p_list, char *temp) {
|
Chain *mply_findByString(Chain* p_list, char *temp) {
|
||||||
List *t_list;
|
Chain *t_list;
|
||||||
char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1));
|
char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1));
|
||||||
if(p_temp == NULL){
|
if(p_temp == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -134,8 +129,8 @@ List *mply_findByString(List* p_list, char *temp) {
|
|||||||
@param temp 目标节点中储存的指针值
|
@param temp 目标节点中储存的指针值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@return 返回包含所有符合条件的节点的新的重组链表
|
||||||
*/
|
*/
|
||||||
List *mply_findByPointer(List* p_list, void *temp) {
|
Chain *mply_findByPointer(Chain* p_list, void *temp) {
|
||||||
List *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp);
|
Chain *t_list = mply_findByValue(p_list, DOUBLE, (void *)temp);
|
||||||
return t_list;
|
return t_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +142,7 @@ List *mply_findByPointer(List* p_list, void *temp) {
|
|||||||
@param temp 目标节点中储存的整型值
|
@param temp 目标节点中储存的整型值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@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);
|
return mply_findByInt(p_list, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +153,7 @@ inline List *mply_findByIntForNode(List* p_list, int temp) {
|
|||||||
@param temp 目标节点中储存的双精度浮点值
|
@param temp 目标节点中储存的双精度浮点值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@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);
|
return mply_findByDouble(p_list, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +164,7 @@ inline List *mply_findByDoubleForNode(List* p_list, double temp) {
|
|||||||
@param temp 目标节点中储存的字符串值
|
@param temp 目标节点中储存的字符串值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@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);
|
return mply_findByString(p_list, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +175,7 @@ inline List *mply_findByStringForNode(List* p_list, char *temp) {
|
|||||||
@param temp 目标节点中储存的指针值
|
@param temp 目标节点中储存的指针值
|
||||||
@return 返回包含所有符合条件的节点的新的重组链表
|
@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);
|
return mply_findByPointer(p_list, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,16 +187,9 @@ inline List *mply_findByPointerForNode(List* p_list, void *temp) {
|
|||||||
@param m_index 序号位置
|
@param m_index 序号位置
|
||||||
@return 返回指向符合条件的链表的指针
|
@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;
|
if(p_list == NULL) return NULL;
|
||||||
//当长链表模式可能启用时编译以下语句
|
CNode *p_node = p_list->head;
|
||||||
#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;
|
unsigned long long i;
|
||||||
for (i = 0; i < m_index; i++) {
|
for (i = 0; i < m_index; i++) {
|
||||||
p_node = p_node->next;
|
p_node = p_node->next;
|
@ -1,10 +1,6 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
//长链表模式可能启用则包含以下头文件
|
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
直接获取储存整型数据的节点的值
|
直接获取储存整型数据的节点的值
|
||||||
@ -12,7 +8,7 @@
|
|||||||
@param p_node 指向目标节点的指针
|
@param p_node 指向目标节点的指针
|
||||||
@return 成功则返回对应整型值,失败返回0
|
@return 成功则返回对应整型值,失败返回0
|
||||||
*/
|
*/
|
||||||
int getByIntForNode(Node *p_node) {
|
int getByIntForNode(CNode *p_node) {
|
||||||
if (p_node->type == INT) return *(int *)(p_node->value);
|
if (p_node->type == INT) return *(int *)(p_node->value);
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
@ -24,7 +20,7 @@ int getByIntForNode(Node *p_node) {
|
|||||||
@param p_node 指向目标节点的指针
|
@param p_node 指向目标节点的指针
|
||||||
@return 成功则返回对应无符号整型值,失败返回0
|
@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);
|
if (p_node->type == UINT) return *(unsigned int *)(p_node->value);
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
@ -35,7 +31,7 @@ unsigned int getByUIntForNode(Node *p_node){
|
|||||||
@param p_node 指向目标节点的指针
|
@param p_node 指向目标节点的指针
|
||||||
@return 返回节点中储存的字符串
|
@return 返回节点中储存的字符串
|
||||||
*/
|
*/
|
||||||
char *getByStringForNode(Node *p_node) {
|
char *getByStringForNode(CNode *p_node) {
|
||||||
if (p_node->type == STRING) return (char *)(p_node->value);
|
if (p_node->type == STRING) return (char *)(p_node->value);
|
||||||
else return NULL;
|
else return NULL;
|
||||||
}
|
}
|
||||||
@ -46,7 +42,7 @@ char *getByStringForNode(Node *p_node) {
|
|||||||
@param p_node 指向目标节点的指针
|
@param p_node 指向目标节点的指针
|
||||||
@return 返回节点中储存的双精度浮点值
|
@return 返回节点中储存的双精度浮点值
|
||||||
*/
|
*/
|
||||||
double getByDoubleForNode(Node *p_node) {
|
double getByDoubleForNode(CNode *p_node) {
|
||||||
if (p_node->type == DOUBLE) return *(double *)(p_node->value);
|
if (p_node->type == DOUBLE) return *(double *)(p_node->value);
|
||||||
else return -1.0;
|
else return -1.0;
|
||||||
}
|
}
|
||||||
@ -57,7 +53,7 @@ double getByDoubleForNode(Node *p_node) {
|
|||||||
@param p_node 指向目标节点的指针
|
@param p_node 指向目标节点的指针
|
||||||
@return 返回节点中储存的指针值
|
@return 返回节点中储存的指针值
|
||||||
*/
|
*/
|
||||||
void *getByPointerForNode(Node *p_node) {
|
void *getByPointerForNode(CNode *p_node) {
|
||||||
return (void *)(p_node->value);
|
return (void *)(p_node->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,16 +65,8 @@ void *getByPointerForNode(Node *p_node) {
|
|||||||
@param p_node 指向目标节点的指针
|
@param p_node 指向目标节点的指针
|
||||||
@return 成功返回相应排列序号,失败则会返回0
|
@return 成功返回相应排列序号,失败则会返回0
|
||||||
*/
|
*/
|
||||||
unsigned long long getIndexByNode(List *p_list, Node *p_node) {
|
unsigned long long getIndexByNode(Chain *p_list, CNode *p_node) {
|
||||||
// 长链表模式可能启用则编译以下代码
|
register CNode *t_node = p_list->head;
|
||||||
#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;
|
register unsigned long long index = 0;
|
||||||
while (t_node != NULL) {
|
while (t_node != NULL) {
|
||||||
// id模块可能启用的时候则编译以下代码
|
// id模块可能启用的时候则编译以下代码
|
@ -1,6 +1,5 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
179
src/datastruct/chain/chain_print.c
Normal file
179
src/datastruct/chain/chain_print.c
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
#include <type.h>
|
||||||
|
#include <chain/chain.h>
|
||||||
|
#include <chain/chain_print.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
打印链表及链表中节点的相关数据
|
||||||
|
|
||||||
|
@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__;
|
||||||
|
}
|
@ -1,15 +1,11 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*内部函数: 通过节点中的值查找相关多个节点.
|
*内部函数: 通过节点中的值查找相关多个节点.
|
||||||
*参数: type指明相关值的类型;value为指向储存相关值的内存的指针.
|
*参数: type指明相关值的类型;value为指向储存相关值的内存的指针.
|
||||||
*返回: 如果成功返回0,如果失败则返回-1.*/
|
*返回: 如果成功返回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 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。
|
@param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。
|
||||||
@return 成功进行操作则返回0
|
@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;
|
unsigned long long target_index = begin;
|
||||||
register Node *t_node = findByIndexForNode(p_list, target_index);
|
register CNode *t_node = findByIndexForNode(p_list, target_index);
|
||||||
register Node *i_node = NULL, *j_node = NULL;
|
register CNode *i_node = NULL, *j_node = NULL;
|
||||||
|
|
||||||
register unsigned long long i = end,j = begin;
|
register unsigned long long i = end,j = begin;
|
||||||
for(; i >= begin; i--){
|
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(end - begin > 3){
|
||||||
if(t_node->f_number - begin > 2)
|
if(getIndexForNode(p_list, t_node) - begin > 2)
|
||||||
sortList(p_list, begin, t_node->f_number, func);
|
sortList(p_list, begin, getIndexForNode(p_list, t_node), func);
|
||||||
if(end - t_node->f_number > 2)
|
if(end - getIndexForNode(p_list, t_node) > 2)
|
||||||
sortList(p_list, t_node->f_number, end, func);
|
sortList(p_list, getIndexForNode(p_list, t_node), end, func);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -59,10 +55,7 @@ static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node
|
|||||||
@param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。
|
@param func 指向判断条件的函数的函数指针,接受两个指向相关节点的指针,比较他们的大小并返回正负值。
|
||||||
@return 成功进行操作则返回0
|
@return 成功进行操作则返回0
|
||||||
*/
|
*/
|
||||||
int sortListForCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)){
|
int sortListForCustom(Chain *p_list, int(*func)(CNode *f_node, CNode *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);
|
sortList(p_list, 0, p_list->length-1, func);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,7 +9,7 @@
|
|||||||
@param value 整型值
|
@param value 整型值
|
||||||
@return 操作成功则返回0
|
@return 操作成功则返回0
|
||||||
*/
|
*/
|
||||||
int updateValueWithIntForNode(Node *p_node,int value){
|
int updateValueWithIntForNode(CNode *p_node,int value){
|
||||||
int *p_value = (int *)malloc(sizeof(int));
|
int *p_value = (int *)malloc(sizeof(int));
|
||||||
if(p_value == NULL){
|
if(p_value == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
@ -29,7 +28,7 @@ int updateValueWithIntForNode(Node *p_node,int value){
|
|||||||
@param value 无符号长整型值
|
@param value 无符号长整型值
|
||||||
@return 操作成功则返回0
|
@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));
|
uint64_t *p_value = (uint64_t *)malloc(sizeof(uint64_t));
|
||||||
if(p_value == NULL){
|
if(p_value == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
@ -48,7 +47,7 @@ int updateValueWithULLIntForNode(Node *p_node, uint64_t value){
|
|||||||
@param value 双精度浮点值
|
@param value 双精度浮点值
|
||||||
@return 操作成功则返回0
|
@return 操作成功则返回0
|
||||||
*/
|
*/
|
||||||
int updateValueWithDoubleForNode(Node *p_node, double value){
|
int updateValueWithDoubleForNode(CNode *p_node, double value){
|
||||||
double *p_value = (double *)malloc(sizeof(double));
|
double *p_value = (double *)malloc(sizeof(double));
|
||||||
if(p_value == NULL){
|
if(p_value == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
@ -67,7 +66,7 @@ int updateValueWithDoubleForNode(Node *p_node, double value){
|
|||||||
@param string 字符串值
|
@param string 字符串值
|
||||||
@return 操作成功则返回0
|
@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);
|
char *p_value = (char *)malloc(sizeof(strlen(string)) + 1);
|
||||||
if(p_value == NULL){
|
if(p_value == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
@ -86,7 +85,7 @@ int updateValueWithStringForNode(Node *p_node, char *string){
|
|||||||
@param pointer 指针值
|
@param pointer 指针值
|
||||||
@return 操作成功则返回0
|
@return 操作成功则返回0
|
||||||
*/
|
*/
|
||||||
int updateValueWithPointerForNode(Node *p_node, void *pointer){
|
int updateValueWithPointerForNode(CNode *p_node, void *pointer){
|
||||||
free(p_node->value);
|
free(p_node->value);
|
||||||
p_node->value = pointer;
|
p_node->value = pointer;
|
||||||
return 0;
|
return 0;
|
@ -1,7 +1,6 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +11,7 @@
|
|||||||
@param p_func 指向回调函数的指针
|
@param p_func 指向回调函数的指针
|
||||||
@return 返回参数链表
|
@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;
|
Node *p_node = p_list->head;
|
||||||
List *m_rtnlst = NULL;
|
List *m_rtnlst = NULL;
|
||||||
uint64_t index = 0;
|
uint64_t index = 0;
|
||||||
@ -51,7 +50,7 @@ List *listThrough(List *p_list, List *(*p_func)(uint32_t, void *, List *), List
|
|||||||
@param type 模式
|
@param type 模式
|
||||||
@return 返回需要获取的数据
|
@return 返回需要获取的数据
|
||||||
*/
|
*/
|
||||||
uint64_t getInfoForListThrough(List *expand_resources, int type){
|
uint64_t getInfoForListThrough(Chain *expand_resources, int type){
|
||||||
Node *p_node = NULL;
|
Node *p_node = NULL;
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
p_node = findByIndexForNode(expand_resources, expand_resources->length-1);
|
p_node = findByIndexForNode(expand_resources, expand_resources->length-1);
|
||||||
@ -70,7 +69,7 @@ uint64_t getInfoForListThrough(List *expand_resources, int type){
|
|||||||
@param ... 参数
|
@param ... 参数
|
||||||
@return 指向构造的参数列表的指针
|
@return 指向构造的参数列表的指针
|
||||||
*/
|
*/
|
||||||
List *newReturn(int if_status ,int status, char *argc, ...){
|
Chain *newReturn(int if_status ,int status, char *argc, ...){
|
||||||
List *p_list = initList(0);
|
List *p_list = initList(0);
|
||||||
if(if_status){
|
if(if_status){
|
||||||
lisrti(p_list, status);
|
lisrti(p_list, status);
|
||||||
@ -130,6 +129,6 @@ List *newReturn(int if_status ,int status, char *argc, ...){
|
|||||||
|
|
||||||
@return 指向构造的参数列表的指针
|
@return 指向构造的参数列表的指针
|
||||||
*/
|
*/
|
||||||
List *newCReturn(void){
|
Chain *newCReturn(void){
|
||||||
return newReturn(1, 0, NULL);
|
return newReturn(1, 0, NULL);
|
||||||
}
|
}
|
@ -1,82 +0,0 @@
|
|||||||
#include <type.h>
|
|
||||||
#include <list/list.h>
|
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#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;
|
|
||||||
}
|
|
@ -1,237 +0,0 @@
|
|||||||
#include <type.h>
|
|
||||||
#include <list/list.h>
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#include <list/list_expand.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
#include <type.h>
|
|
||||||
#include <list/list_simple.h>
|
|
||||||
#include <list/list_type.h>
|
|
||||||
#include <list/list.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
#include <type.h>
|
|
||||||
#include <list/list.h>
|
|
||||||
#include <list/list_simple.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -20,9 +20,6 @@ Node *copyNode(Node *p_node) {
|
|||||||
t_node->next = p_node->next;
|
t_node->next = p_node->next;
|
||||||
t_node->type = p_node->type;
|
t_node->type = p_node->type;
|
||||||
t_node->value = p_node->value;
|
t_node->value = p_node->value;
|
||||||
#ifdef list_quick_enable
|
|
||||||
t_node->f_number = p_node->f_number;
|
|
||||||
#endif
|
|
||||||
return t_node;
|
return t_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,11 +40,6 @@ List *copyList(List *p_list) {
|
|||||||
#endif
|
#endif
|
||||||
t_list->head = p_list->head;
|
t_list->head = p_list->head;
|
||||||
t_list->tail = p_list->tail;
|
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;
|
t_list->length = p_list->length;
|
||||||
if(p_list->head != NULL && p_list->tail != NULL){
|
if(p_list->head != NULL && p_list->tail != NULL){
|
||||||
p_node = p_list->head;
|
p_node = p_list->head;
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
//如果ID模块可能启用则编译以下代码
|
//如果ID模块可能启用则编译以下代码
|
||||||
#ifdef id_enable
|
#ifdef id_enable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
通过ID查找链表中符合条件的第一个节点
|
通过ID查找链表中符合条件的第一个节点
|
||||||
|
|
@ -27,7 +27,6 @@ Node *initNode(void)
|
|||||||
p_node->next = NULL;
|
p_node->next = NULL;
|
||||||
p_node->last = NULL;
|
p_node->last = NULL;
|
||||||
p_node->type = VOID;
|
p_node->type = VOID;
|
||||||
p_node->f_number = 0;
|
|
||||||
// 链表内存安全模式相关操作
|
// 链表内存安全模式相关操作
|
||||||
if (if_safeModeForNode) {
|
if (if_safeModeForNode) {
|
||||||
if_safeModeForNode = 0;
|
if_safeModeForNode = 0;
|
||||||
@ -63,12 +62,6 @@ List *initList(void)
|
|||||||
#endif
|
#endif
|
||||||
p_list->head = NULL;
|
p_list->head = NULL;
|
||||||
p_list->tail = 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 (if_safeModeForNode) {
|
||||||
if_safeModeForNode = 0;
|
if_safeModeForNode = 0;
|
||||||
p_node = initNode(0);
|
p_node = initNode(0);
|
52
src/memory/list/list_insert.c
Normal file
52
src/memory/list/list_insert.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <type.h>
|
||||||
|
#include <list/list.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
在链表的头部插入节点
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <list/list.h>
|
||||||
#include <list/list_expand.h>
|
|
||||||
#include <list/list_print.h>
|
#include <list/list_print.h>
|
||||||
#include <list/list_expand_1.h>
|
|
||||||
|
|
||||||
#ifdef id_enable
|
#ifdef id_enable
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
@ -1,8 +1,5 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <list/list.h>
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int releaseNode(Node *p_node) {
|
int releaseNode(Node *p_node) {
|
||||||
if (if_safeModeForNode == 1) {
|
if (if_safeModeForNode == 1) {
|
||||||
@ -19,7 +16,6 @@ int releaseNode(Node *p_node) {
|
|||||||
}
|
}
|
||||||
p_node->value = NULL;
|
p_node->value = NULL;
|
||||||
}
|
}
|
||||||
p_node->f_number = 0;
|
|
||||||
p_node->last = NULL;
|
p_node->last = NULL;
|
||||||
p_node->next = NULL;
|
p_node->next = NULL;
|
||||||
p_node->type = VOID;
|
p_node->type = VOID;
|
||||||
@ -60,12 +56,6 @@ int releaseList(List *p_list) {
|
|||||||
p_list->head = NULL;
|
p_list->head = NULL;
|
||||||
p_list->tail = NULL;
|
p_list->tail = NULL;
|
||||||
p_list->length = 0;
|
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);
|
free(p_list);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -113,9 +103,6 @@ int releaseListForCustom(List *p_list, int (*func)(void *)){
|
|||||||
p_list->length = 0;
|
p_list->length = 0;
|
||||||
#ifdef id_enable
|
#ifdef id_enable
|
||||||
if (p_list->s_id != NULL) freeS_id(p_list->s_id);
|
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
|
#endif
|
||||||
free(p_list);
|
free(p_list);
|
||||||
return 0;
|
return 0;
|
@ -1,8 +1,5 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <list/list.h>
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef id_enable
|
#ifdef id_enable
|
||||||
int removeById(List *p_list, SID *s_id) {
|
int removeById(List *p_list, SID *s_id) {
|
||||||
@ -48,23 +45,8 @@ int removeByNode(List *p_list, Node *p_node) {
|
|||||||
popFromTail(p_list);
|
popFromTail(p_list);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(p_list->p_lq == NULL){
|
|
||||||
p_node->last->next = p_node->next;
|
p_node->last->next = p_node->next;
|
||||||
p_node->next->last = p_node->last;
|
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;
|
p_list->length -= 1;
|
||||||
return 0;//not find
|
return 0;//not find
|
||||||
}
|
}
|
||||||
@ -73,27 +55,6 @@ Node *popFromHead(List *p_list) {
|
|||||||
if (isListEmpty(p_list))
|
if (isListEmpty(p_list))
|
||||||
return NULL;
|
return NULL;
|
||||||
Node *p_node = p_list->head;
|
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;
|
//Node *tmp = p_list->head;
|
||||||
p_list->head->next->last = NULL;
|
p_list->head->next->last = NULL;
|
||||||
p_list->head = p_list->head->next;
|
p_list->head = p_list->head->next;
|
||||||
@ -111,18 +72,6 @@ Node *popFromTail(List *p_list) {
|
|||||||
if (isListEmpty(p_list))
|
if (isListEmpty(p_list))
|
||||||
return NULL;
|
return NULL;
|
||||||
else {
|
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;
|
//Node *tmp = p_list->tail;
|
||||||
p_list->tail->last->next = NULL;
|
p_list->tail->last->next = NULL;
|
||||||
p_list->tail = p_list->tail->last;
|
p_list->tail = p_list->tail->last;
|
@ -1,8 +1,5 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <list/list.h>
|
||||||
#ifdef list_quick_enable
|
|
||||||
#include <list/list_quick.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int replaceNode(List *p_list, Node *pt_node, Node *p_node){
|
int replaceNode(List *p_list, Node *pt_node, Node *p_node){
|
||||||
p_node->next = pt_node->next;
|
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;
|
else p_list->head = p_node;
|
||||||
if(p_list->tail != pt_node) pt_node->next->last = p_node;
|
if(p_list->tail != pt_node) pt_node->next->last = p_node;
|
||||||
else p_list->tail = 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +26,5 @@ int exchangeNode(List *p_list, Node *f_node, Node *s_node){
|
|||||||
f_node->last = s_node->last;
|
f_node->last = s_node->last;
|
||||||
s_node->next = fn_node;
|
s_node->next = fn_node;
|
||||||
s_node->last = fl_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;
|
return 0;
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <list/list.h>
|
#include <list/list.h>
|
||||||
#include <list/list_quick.h>
|
#include <chain/chain_quick.h>
|
||||||
|
|
||||||
static int if_safeModeForNode = 0;
|
static int if_safeModeForNode = 0;
|
||||||
static List *node_list = NULL;
|
static List *node_list = NULL;
|
36
test/test.c
36
test/test.c
@ -47,44 +47,8 @@ int list(void) {
|
|||||||
return 0;
|
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) {
|
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){
|
while(1){
|
||||||
List *p_list = initList(0);
|
List *p_list = initList(0);
|
||||||
for(int i = 0; i < 65535; i++){
|
for(int i = 0; i < 65535; i++){
|
||||||
|
@ -5,15 +5,12 @@
|
|||||||
|
|
||||||
#include <type.h>
|
#include <type.h>
|
||||||
#include <id/id.h>
|
#include <id/id.h>
|
||||||
#include <list/list.h>
|
#include <chain/chain.h>
|
||||||
#include <list/list_expand.h>
|
#include <event/event.h>
|
||||||
#include <list/list_expand_1.h>
|
#include <communicate/communicate_file.h>
|
||||||
#include <list/list_quick.h>
|
|
||||||
#include <communicate/communicate.h>
|
|
||||||
|
|
||||||
int stack(void);
|
int stack(void);
|
||||||
int list(void);
|
int list(void);
|
||||||
int tree(void);
|
int tree(void);
|
||||||
int time_avg(void);
|
|
||||||
|
|
||||||
#endif // TEST_H
|
#endif // TEST_H
|
||||||
|
Loading…
Reference in New Issue
Block a user