List aparted and created chain.

This commit is contained in:
Saturneic 2019-01-12 02:22:04 +08:00
parent 14ec30b0be
commit 8f934bfaa3
65 changed files with 459 additions and 902 deletions

View File

@ -1,8 +1,8 @@
#ifndef list_expand_h
#define list_expand_h
#include <list/list_type.h>
#ifndef chain_h
#define chain_h
#include <chain/chain_type.h>
#include <list/list.h>
/************************************************
*: ,
@ -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 *);
@ -158,22 +158,22 @@ List *mply_findByPointerForNode(List*, void *);
,,,,
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 */

View File

@ -1,8 +1,8 @@
#ifndef list_print_h
#define list_print_h
#include <list/list_type.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
/************************************************
*:
@ -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 */

View 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 */

View File

@ -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 *);

View File

@ -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;
/*

View File

@ -1,7 +1,7 @@
#ifndef list_expand_1_h
#define list_expand_1_h
#include <list/list_expand.h>
#include <chain/chain.h>
/************************************************
*,

View File

@ -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 */

View File

@ -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

View File

@ -1,10 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list_type.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <communicate/communicate.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int checkIfDataFile(D_FILE *p_dfile){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
D_FILE *initDataFileForWrite(char *route){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int dataFileWriteIn(D_FILE *p_dfile){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int releaseDFile(D_FILE *p_dfile){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
__CALLBACK_DEFINE(findStandardDataBySid){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
uint32_t calStandardData(STD_DATA *p_std){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
STD_CTN *initStandardDConnection(SID *f_sid, SID *s_sid){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,uint16_t type, void *data, uint32_t data_size){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int releaseStandardData(STD_DATA *p_std){

View File

@ -1,6 +1,6 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
STD_BLOCKS *initStandardDBlocks(SID *p_sid, uint16_t type, uint32_t data_size){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
__CALLBACK_DEFINE(StandardDBlockWrite){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int releaseSTDBlocks(STD_BLOCKS *p_stdb){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
__CALLBACK_DEFINE(calStandardDataCTN){

View File

@ -1,6 +1,6 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,6 +1,6 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int releaseSTDConnection(STD_CTN *p_stdc){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
STD_DATA *listToSTD(List *p_list){

View File

@ -1,7 +1,7 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
List *standardDataToList(STD_DATA *p_std){

View File

@ -1,5 +1,6 @@
#include <type.h>
#include <list/list_type.h>
#include <chain/chain_type.h>
/**
@ -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);

View File

@ -1,14 +1,14 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <chain/chain.h>
/**
@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;

View File

@ -1,10 +1,5 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
//长链表模式可能启用则包含以下头文件
#ifdef list_quick_enable
#include <list/list_quick.h>
#endif
#include <chain/chain.h>
/**
@ -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;

View File

@ -1,10 +1,6 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
//长链表模式可能启用则包含以下头文件
#ifdef list_quick_enable
#include <list/list_quick.h>
#endif
#include <chain/chain.h>
/**
@ -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模块可能启用的时候则编译以下代码

View File

@ -1,6 +1,5 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <chain/chain.h>
/**

View 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__;
}

View File

@ -1,15 +1,11 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
#ifdef list_quick_enable
#include <list/list_quick.h>
#endif
#include <chain/chain.h>
/*
*: .
*: 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;
}

View File

@ -1,6 +1,5 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <chain/chain.h>
/**
@ -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;

View File

@ -1,7 +1,6 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <chain/chain.h>
#include <event/event.h>
/**
@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -3,7 +3,6 @@
//如果ID模块可能启用则编译以下代码
#ifdef id_enable
/**
ID查找链表中符合条件的第一个节点

View File

@ -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);

View 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;
}

View File

@ -1,8 +1,6 @@
#include <type.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_print.h>
#include <list/list_expand_1.h>
#ifdef id_enable
#include <id/id.h>

View File

@ -1,8 +1,5 @@
#include <type.h>
#include <list/list.h>
#ifdef list_quick_enable
#include <list/list_quick.h>
#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;

View File

@ -1,8 +1,5 @@
#include <type.h>
#include <list/list.h>
#ifdef list_quick_enable
#include <list/list_quick.h>
#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_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;

View File

@ -1,8 +1,5 @@
#include <type.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){
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;
}

View File

@ -1,6 +1,6 @@
#include <type.h>
#include <list/list.h>
#include <list/list_quick.h>
#include <chain/chain_quick.h>
static int if_safeModeForNode = 0;
static List *node_list = NULL;

View File

@ -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++){

View File

@ -5,15 +5,12 @@
#include <type.h>
#include <id/id.h>
#include <list/list.h>
#include <list/list_expand.h>
#include <list/list_expand_1.h>
#include <list/list_quick.h>
#include <communicate/communicate.h>
#include <chain/chain.h>
#include <event/event.h>
#include <communicate/communicate_file.h>
int stack(void);
int list(void);
int tree(void);
int time_avg(void);
#endif // TEST_H