This commit is contained in:
Saturneic 2018-08-17 16:58:15 +08:00
parent e07f325672
commit 6a00c6bead
11 changed files with 612 additions and 253 deletions

View File

@ -386,7 +386,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "240" startingLineNumber = "240"
endingLineNumber = "240" endingLineNumber = "240"
landmarkName = "freeSidRaw" landmarkName = "freeS_id"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
@ -498,7 +498,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "239" startingLineNumber = "239"
endingLineNumber = "239" endingLineNumber = "239"
landmarkName = "freeSidRaw" landmarkName = "freeS_id"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
@ -518,38 +518,6 @@
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "test.c"
timestampString = "555310052.790392"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "88"
endingLineNumber = "88"
landmarkName = "main"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "test.c"
timestampString = "555310052.790665"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "90"
endingLineNumber = "90"
landmarkName = "main"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
@ -562,23 +530,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "83" startingLineNumber = "83"
endingLineNumber = "83" endingLineNumber = "83"
landmarkName = "s_findByIndexForNode" landmarkName = "findByIndexForNode"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "test.c"
timestampString = "555310052.790953"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "92"
endingLineNumber = "92"
landmarkName = "main"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
@ -598,22 +550,6 @@
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "communicate/communicate.c"
timestampString = "555310052.791289"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "137"
endingLineNumber = "137"
landmarkName = "_doStandardDConnectionWrite"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
@ -641,9 +577,7 @@
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "100" startingLineNumber = "100"
endingLineNumber = "100" endingLineNumber = "100">
landmarkName = "main"
landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
@ -674,7 +608,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "118" startingLineNumber = "118"
endingLineNumber = "118" endingLineNumber = "118"
landmarkName = "_doStandardDataWrite" landmarkName = "_doStandardDataInfoWrite"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
@ -866,8 +800,8 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "43" startingLineNumber = "43"
endingLineNumber = "43" endingLineNumber = "43"
landmarkName = "standardDataAddBlock" landmarkName = "unknown"
landmarkType = "9"> landmarkType = "0">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
@ -902,22 +836,6 @@
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "communicate/communicate.c"
timestampString = "555310052.792913"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "223"
endingLineNumber = "223"
landmarkName = "dataFileReadOut"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
@ -950,22 +868,6 @@
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "communicate/communicate.c"
timestampString = "555310052.793045"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "226"
endingLineNumber = "226"
landmarkName = "dataFileReadOut"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
@ -993,9 +895,7 @@
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "99" startingLineNumber = "99"
endingLineNumber = "99" endingLineNumber = "99">
landmarkName = "main"
landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
@ -1010,8 +910,8 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "266" startingLineNumber = "266"
endingLineNumber = "266" endingLineNumber = "266"
landmarkName = "releaseDFile" landmarkName = "unknown"
landmarkType = "9"> landmarkType = "0">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy <BreakpointProxy
@ -1026,7 +926,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "270" startingLineNumber = "270"
endingLineNumber = "270" endingLineNumber = "270"
landmarkName = "releaseDFile" landmarkName = "releaseSTDBlocks"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
@ -1042,7 +942,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "267" startingLineNumber = "267"
endingLineNumber = "267" endingLineNumber = "267"
landmarkName = "releaseDFile" landmarkName = "releaseSTDBlocks"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
@ -1058,7 +958,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "508" startingLineNumber = "508"
endingLineNumber = "508" endingLineNumber = "508"
landmarkName = "releaseNodeForCustom" landmarkName = "copyNode"
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>

View File

@ -2,7 +2,10 @@
STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size){ STD_BLOCKS *initStandardDBlocks(SID *p_sid, unsigned int type, unsigned long long data_size){
STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS)); STD_BLOCKS *p_stdb = (STD_BLOCKS *)malloc(sizeof(STD_BLOCKS));
if(p_sid != NULL){
p_stdb->sid = s_idToASCIIString(p_sid); p_stdb->sid = s_idToASCIIString(p_sid);
}
else p_stdb->sid = NULL;
p_stdb->if_data = 0; p_stdb->if_data = 0;
unsigned int blocks_num = (unsigned int)(data_size/sizeof(char)); unsigned int blocks_num = (unsigned int)(data_size/sizeof(char));
p_stdb->blocks_num = blocks_num; p_stdb->blocks_num = blocks_num;
@ -42,14 +45,14 @@ int standardDataAddBlock(STD_DATA *p_std, SID *p_sid ,unsigned int type, void *d
if (p_std->lock) return -1; if (p_std->lock) return -1;
STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size); STD_BLOCKS *p_stdb = initStandardDBlocks(p_sid, type,data_size);
dataForStandardDBlock(p_stdb, data); dataForStandardDBlock(p_stdb, data);
insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb)); insertInTail(p_std->pd_blocklst, nodeWithPointer(p_stdb,0));
return 0; return 0;
} }
int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){ int standardDataAddConnection(STD_DATA *p_std, SID *f_sid, SID *s_sid){
if (p_std->lock) return -1; if (p_std->lock) return -1;
STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid); STD_CTN *p_stdb = initStandardDConnection(f_sid, s_sid);
insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb)); insertInTail(p_std->pd_ctnlst, nodeWithPointer(p_stdb,0));
return 0; return 0;
} }
@ -73,7 +76,7 @@ D_FILE *initDataFileForRead(char *route){
} }
int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){ int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std)); insertInTail(p_dfile->pf_stdlst, nodeWithPointer(p_std,0));
p_dfile->pf_head->data_num = p_dfile->pf_stdlst->length; p_dfile->pf_head->data_num = p_dfile->pf_stdlst->length;
return 0; return 0;
} }
@ -83,7 +86,7 @@ int dataFileWriteIn(D_FILE *p_dfile){
fwrite(&p_dfile->pf_head->data_num, sizeof(unsigned long long), 1, p_dfile->fp); fwrite(&p_dfile->pf_head->data_num, sizeof(unsigned long long), 1, p_dfile->fp);
fwrite("HEAD_END", sizeof(char), 9, p_dfile->fp); fwrite("HEAD_END", sizeof(char), 9, p_dfile->fp);
List *er_list = initList(0); List *er_list = initList(0);
insertInTail(er_list, nodeWithPointer(p_dfile->fp)); insertInTail(er_list, nodeWithPointer(p_dfile->fp,0));
/*fwrite("STDINFO", sizeof(char), 8, p_dfile->fp); /*fwrite("STDINFO", sizeof(char), 8, p_dfile->fp);
listThrough(p_dfile->pf_stdlst, _doStandardDataInfoWrite, er_list);*/ listThrough(p_dfile->pf_stdlst, _doStandardDataInfoWrite, er_list);*/
/*fwrite("STDLST", sizeof(char), 7, p_dfile->fp);*/ /*fwrite("STDLST", sizeof(char), 7, p_dfile->fp);*/
@ -91,14 +94,23 @@ int dataFileWriteIn(D_FILE *p_dfile){
releaseList(er_list); releaseList(er_list);
return 0; return 0;
} }
List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){ List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0); List *p_rtnlst = initList(0);
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
STD_DATA *p_std = value; STD_DATA *p_std = value;
insertInTail(p_rtnlst, nodeWithInt(0)); insertInTail(p_rtnlst, nodeWithInt(0,0));
int if_sid = 0;
if(p_std->s_id != NULL){
if_sid = 1;
char *string_sid = s_idToASCIIString(p_std->s_id); char *string_sid = s_idToASCIIString(p_std->s_id);
fwrite(string_sid, sizeof(char), DEEPER_LEN, fp); fwrite(&if_sid, sizeof(int), 1, fp);
fwrite(string_sid, sizeof(char), SID_LEN, fp);
free(string_sid); free(string_sid);
}
else{
fwrite(&if_sid, sizeof(int), 1, fp);
}
fwrite(&p_std->type, sizeof(unsigned long), 1, fp); fwrite(&p_std->type, sizeof(unsigned long), 1, fp);
fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp); fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp);
fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp); fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp);
@ -108,48 +120,45 @@ List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list){
List *_doStandardDataWrite(unsigned int type, void *value, List *er_list){ List *_doStandardDataWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0); List *p_rtnlst = initList(0);
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
insertInTail(p_rtnlst, nodeWithInt(0)); insertInTail(p_rtnlst, nodeWithInt(0,0));
STD_DATA *p_std = value; STD_DATA *p_std = value;
List *erc_list = initList(0); List *erc_list = initList(0);
insertInTail(erc_list, nodeWithPointer(fp)); insertInTail(erc_list, nodeWithPointer(fp,0));
fwrite("STD", sizeof(char), 4, fp); fwrite("STD", sizeof(char), 4, fp);
char *string_sid = s_idToASCIIString(p_std->s_id);
unsigned long sid_len = strlen(string_sid) + 1;
fwrite(&sid_len, sizeof(unsigned long), 1, fp);
char *sid_w = s_idToASCIIString(p_std->s_id);
fwrite(sid_w, sizeof(char), sid_len, fp);
fwrite(&p_std->type, sizeof(unsigned int), 1, fp); fwrite(&p_std->type, sizeof(unsigned int), 1, fp);
fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp); fwrite(&p_std->pd_ctnlst->length, sizeof(unsigned long long), 1, fp);
fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp); fwrite(&p_std->pd_blocklst->length, sizeof(unsigned long long), 1, fp);
listThrough(p_std->pd_ctnlst, _doStandardDConnectionWrite, erc_list); listThrough(p_std->pd_ctnlst, _doStandardDConnectionWrite, erc_list);
listThrough(p_std->pd_blocklst, _doStandardDBlockWrite, erc_list); listThrough(p_std->pd_blocklst, _doStandardDBlockWrite, erc_list);
releaseList(erc_list); releaseList(erc_list);
free(sid_w);
free(string_sid);
return p_rtnlst; return p_rtnlst;
} }
List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list){ List *_doStandardDConnectionWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0); List *p_rtnlst = initList(0);
insertInTail(p_rtnlst, nodeWithInt(0)); insertInTail(p_rtnlst, nodeWithInt(0,0));
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
STD_CTN *p_stdc = value; STD_CTN *p_stdc = value;
unsigned long fsid_len = strlen(p_stdc->f_sid) + 1, ssid_len = strlen(p_stdc->s_sid)+1; fwrite(p_stdc->f_sid, sizeof(char), SID_LEN, fp);
fwrite(&fsid_len, sizeof(unsigned long), 1, fp); fwrite(p_stdc->s_sid, sizeof(char), SID_LEN, fp);
fwrite(p_stdc->f_sid, sizeof(char), fsid_len, fp);
fwrite(&ssid_len, sizeof(unsigned long), 1, fp);
fwrite(p_stdc->s_sid, sizeof(char), ssid_len, fp);
return p_rtnlst; return p_rtnlst;
} }
List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){
List *p_rtnlst = initList(0); List *p_rtnlst = initList(0);
insertInTail(p_rtnlst, nodeWithInt(0)); insertInTail(p_rtnlst, nodeWithInt(0,0));
STD_BLOCKS *p_stdb = value; STD_BLOCKS *p_stdb = value;
FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0)); FILE *fp = getByPointerForNode(findByIndexForNode(er_list, 0));
unsigned long sid_len = strlen(p_stdb->sid)+1, blocks_num = p_stdb->blocks_num; unsigned long blocks_num = p_stdb->blocks_num;
fwrite(&sid_len, sizeof(unsigned long), 1, fp); int if_sid = 0;
fwrite(p_stdb->sid, sizeof(char), sid_len, fp); if(p_stdb->sid != NULL){
if_sid = 1;
fwrite(&if_sid, sizeof(int), 1, fp);
fwrite(p_stdb->sid, sizeof(char), SID_LEN, fp);
}
else{
fwrite(&if_sid, sizeof(int), 1, fp);
}
fwrite(&p_stdb->type, sizeof(unsigned int), 1, fp); fwrite(&p_stdb->type, sizeof(unsigned int), 1, fp);
fwrite(&blocks_num, sizeof(unsigned long), 1, fp); fwrite(&blocks_num, sizeof(unsigned long), 1, fp);
fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp); fwrite(p_stdb->buff, sizeof(char), p_stdb->blocks_num, fp);
@ -159,8 +168,9 @@ List *_doStandardDBlockWrite(unsigned int type, void *value, List *er_list){
STD_DATA *listToSTD(List *p_list){ STD_DATA *listToSTD(List *p_list){
STD_DATA *p_std = initStandardData(LIST); STD_DATA *p_std = initStandardData(LIST);
Node *p_node = p_list->head; Node *p_node = p_list->head;
if (p_list->s_id != NULL) p_std->s_id = p_list->s_id; if (p_list->s_id != NULL) p_std->s_id = copyS_id(p_list->s_id);
while (p_node != NULL) { while (p_node != NULL) {
if(p_node->type == HOLE) continue;
unsigned long long data_size = 0; unsigned long long data_size = 0;
if(p_node->type == INT) data_size = sizeof(int); if(p_node->type == INT) data_size = sizeof(int);
else if (p_node->type == DOUBLE) data_size = sizeof(double); else if (p_node->type == DOUBLE) data_size = sizeof(double);
@ -186,26 +196,28 @@ int dataFileReadOut(D_FILE *p_dfile){
char std_test_info[4]; char std_test_info[4];
fread(std_test_info, sizeof(char), 4, p_dfile->fp); fread(std_test_info, sizeof(char), 4, p_dfile->fp);
if(!strcmp(std_test_info, "STD")){ if(!strcmp(std_test_info, "STD")){
unsigned long long sid_len = 0, ctn_num = 0, blk_num = 0; unsigned long long ctn_num = 0, blk_num = 0;
int if_sid = 0;
unsigned int type = 0; unsigned int type = 0;
fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); fread(&if_sid, sizeof(int), 1, p_dfile->fp);
char *string_sid = (char *)malloc(sizeof(char) * sid_len); char *string_sid = NULL;
fread(string_sid, sizeof(char), sid_len, p_dfile->fp); if(if_sid){
string_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(string_sid, sizeof(char), SID_LEN, p_dfile->fp);
}
fread(&type, sizeof(unsigned int), 1, p_dfile->fp); fread(&type, sizeof(unsigned int), 1, p_dfile->fp);
STD_DATA *p_std = initStandardData(type); STD_DATA *p_std = initStandardData(type);
freeS_id(p_std->s_id); freeS_id(p_std->s_id);
p_std->s_id = asciiStringToS_id(string_sid); p_std->s_id = asciiStringToS_id(string_sid);
dataFileAddStandardData(p_dfile, p_std); dataFileAddStandardData(p_dfile, p_std);
free(string_sid); if(string_sid != NULL) free(string_sid);
fread(&ctn_num, sizeof(unsigned long long), 1, p_dfile->fp); fread(&ctn_num, sizeof(unsigned long long), 1, p_dfile->fp);
fread(&blk_num, sizeof(unsigned long long), 1, p_dfile->fp); fread(&blk_num, sizeof(unsigned long long), 1, p_dfile->fp);
for(int j = 0; j < ctn_num; j++){ for(int j = 0; j < ctn_num; j++){
fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); char *fstring_sid = (char *)malloc(sizeof(char) * SID_LEN);
char *fstring_sid = (char *)malloc(sizeof(char) * sid_len); fread(fstring_sid, sizeof(char), SID_LEN, p_dfile->fp);
fread(fstring_sid, sizeof(char), sid_len, p_dfile->fp); char *sstring_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); fread(sstring_sid, sizeof(char), SID_LEN, p_dfile->fp);
char *sstring_sid = (char *)malloc(sizeof(char) * sid_len);
fread(sstring_sid, sizeof(char), sid_len, p_dfile->fp);
SID *fs_id = asciiStringToS_id(fstring_sid), *ss_id = asciiStringToS_id(sstring_sid); SID *fs_id = asciiStringToS_id(fstring_sid), *ss_id = asciiStringToS_id(sstring_sid);
standardDataAddConnection(p_std, fs_id,ss_id); standardDataAddConnection(p_std, fs_id,ss_id);
freeS_id(fs_id); freeS_id(fs_id);
@ -214,9 +226,12 @@ int dataFileReadOut(D_FILE *p_dfile){
free(sstring_sid); free(sstring_sid);
} }
for(int k = 0; k < blk_num; k++){ for(int k = 0; k < blk_num; k++){
fread(&sid_len, sizeof(unsigned long), 1, p_dfile->fp); fread(&if_sid, sizeof(int), 1, p_dfile->fp);
char *string_sid = (char *)malloc(sizeof(char) * sid_len); char *string_sid = NULL;
fread(string_sid, sizeof(char), sid_len, p_dfile->fp); if(if_sid){
string_sid = (char *)malloc(sizeof(char) * SID_LEN);
fread(string_sid, sizeof(char), SID_LEN, p_dfile->fp);
}
unsigned long blk_len = 0; unsigned long blk_len = 0;
fread(&blk_len, sizeof(unsigned long), 1, p_dfile->fp); fread(&blk_len, sizeof(unsigned long), 1, p_dfile->fp);
char *content = (char *)malloc(sizeof(char) * blk_len); char *content = (char *)malloc(sizeof(char) * blk_len);
@ -226,7 +241,7 @@ int dataFileReadOut(D_FILE *p_dfile){
fread(&type, sizeof(unsigned int), 1, p_dfile->fp); fread(&type, sizeof(unsigned int), 1, p_dfile->fp);
standardDataAddBlock(p_std, s_id, type, content, blk_len); standardDataAddBlock(p_std, s_id, type, content, blk_len);
freeS_id(s_id); freeS_id(s_id);
free(string_sid); if(string_sid != NULL) free(string_sid);
free(content); free(content);
} }
return 0; return 0;
@ -274,14 +289,14 @@ int releaseDFile(D_FILE *p_dfile){
List *standardDataToList(STD_DATA *p_std){ List *standardDataToList(STD_DATA *p_std){
List *p_list = initList(0); List *p_list = initList(0);
List *er_list = initList(0); List *er_list = initList(0);
insertInTail(er_list, nodeWithPointer(er_list)); insertInTail(er_list, nodeWithPointer(er_list,0));
listThrough(p_std->pd_blocklst, _doStandardDataToList, er_list); listThrough(p_std->pd_blocklst, _doStandardDataToList, er_list);
return p_list; return p_list;
} }
List *_doStandardDataToList(unsigned int type, void *value, List *er_list){ List *_doStandardDataToList(unsigned int type, void *value, List *er_list){
List *rtn_list = initList(0); List *rtn_list = initList(0);
insertInTail(rtn_list, nodeWithInt(0)); insertInTail(rtn_list, nodeWithInt(0,0));
List *p_list = getByPointerForNode(findByIndexForNode(er_list, 0)); List *p_list = getByPointerForNode(findByIndexForNode(er_list, 0));
STD_BLOCKS *p_stdb = value; STD_BLOCKS *p_stdb = value;
Node *p_node = initNode(0); Node *p_node = initNode(0);
@ -293,6 +308,18 @@ List *_doStandardDataToList(unsigned int type, void *value, List *er_list){
return rtn_list; return rtn_list;
} }
unsigned long calStandardData(STD_DATA *p_std){
unsigned long size = sizeof(unsigned int) + 9;
if(p_std->s_id != NULL) size += 32;
listThrough(p_std->pd_ctnlst, CALLBACK_CALL(calStandardDataCTN), SEND_ARG("%d", size));
return 0;
}
CALLBACK_DEFINE(calStandardDataCTN){
return C_RETURN;
}
MSG *createMessage(char *title, void *data, unsigned long data_size){ MSG *createMessage(char *title, void *data, unsigned long data_size){
MSG *p_msg = malloc(sizeof(MSG) + data_size); MSG *p_msg = malloc(sizeof(MSG) + data_size);
p_msg->p_sid = getS_id(MESSAGE, 1); p_msg->p_sid = getS_id(MESSAGE, 1);

View File

@ -29,6 +29,8 @@ int releaseSTDBlocks(STD_BLOCKS *p_stdb);
int releaseStandardData(STD_DATA *p_std); int releaseStandardData(STD_DATA *p_std);
int releaseSTDConnection(STD_CTN *p_stdc); int releaseSTDConnection(STD_CTN *p_stdc);
int releaseDFile(D_FILE *p_file); int releaseDFile(D_FILE *p_file);
unsigned long calStandardData(STD_DATA *p_std);
CALLBACK_STATE(calStandardDataCTN);
List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list); List *_doStandardDataInfoWrite(unsigned int type, void *value, List *er_list);
List *_doStandardDataWrite(unsigned int type, void *value, List *er_list); List *_doStandardDataWrite(unsigned int type, void *value, List *er_list);

27
id/id.c
View File

@ -30,6 +30,10 @@ SID *initS_id(unsigned int deep_level){
p_sid->sr->value_deeper = NULL; p_sid->sr->value_deeper = NULL;
p_sid->sr->value_deepest = NULL; p_sid->sr->value_deepest = NULL;
p_sid->md5 = NULL; p_sid->md5 = NULL;
return p_sid;
}
void getRawS_id(SID *p_sid, unsigned int type, unsigned int deep_level){
if (deep_level > 0) { if (deep_level > 0) {
p_sid->sr->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN); p_sid->sr->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN);
if(p_sid->sr->value == NULL){ if(p_sid->sr->value == NULL){
@ -48,17 +52,17 @@ SID *initS_id(unsigned int deep_level){
printf("\ninitS_id(): Error in getting the memory of sid.value_deepest.\n"); printf("\ninitS_id(): Error in getting the memory of sid.value_deepest.\n");
} }
} }
return p_sid;
}
SID *getS_id(unsigned int type, unsigned int deep_level){
SID *p_sid = initS_id(deep_level);
p_sid->sr->type = type; p_sid->sr->type = type;
if(deep_level > 0){ if(deep_level > 0){
for(register int i = 0; i < DEEPC_LEN; i++) p_sid->sr->value[i] = rand()%65535; for(register int i = 0; i < DEEPC_LEN; i++) p_sid->sr->value[i] = rand()%65535;
if(deep_level > 1) for(register int i = 0; i < DEEPB_LEN; i++) p_sid->sr->value_deeper[i] = rand()%65535; if(deep_level > 1) for(register int i = 0; i < DEEPB_LEN; i++) p_sid->sr->value_deeper[i] = rand()%65535;
if (deep_level > 2) for(register int i = 0; i < DEEPA_LEN; i++) p_sid->sr->value_deepest[i] = rand()%65535; if (deep_level > 2) for(register int i = 0; i < DEEPA_LEN; i++) p_sid->sr->value_deepest[i] = rand()%65535;
} }
}
SID *getS_id(unsigned int type, unsigned int deep_level){
SID *p_sid = initS_id(deep_level);
getRawS_id(p_sid, type, deep_level);
s_idToMD5(p_sid); s_idToMD5(p_sid);
return p_sid; return p_sid;
} }
@ -69,7 +73,7 @@ int fitS_id(SID * const fs_id, SID * const ss_id){
return strcmp(fs_id->decrypt_str, ss_id->decrypt_str); return strcmp(fs_id->decrypt_str, ss_id->decrypt_str);
} }
int simFitS_id(SID * const fs_id, SID * const ss_id){ int simFitS_id(SID * fs_id, SID * ss_id){
return !fitS_id(fs_id, ss_id); return !fitS_id(fs_id, ss_id);
} }
@ -87,7 +91,9 @@ char *s_idToASCIIString(SID * const s_id){
free(s_id->md5); free(s_id->md5);
s_id->md5 = NULL; s_id->md5 = NULL;
} }
return s_id->decrypt_str; char *rtn_str = malloc(sizeof(char) * 33);
strcpy(rtn_str, s_id->decrypt_str);
return rtn_str;
} }
char *s_idToASCIIRawString(SID * const s_id){ char *s_idToASCIIRawString(SID * const s_id){
@ -287,3 +293,10 @@ char hexToChar(unsigned char n){
} }
return '0'; return '0';
} }
SID *copyS_id(SID *f_sid){
SID *s_sid = initS_id(f_sid->deep);
for(int i = 0; i < 16; i++)
s_sid->decrypt_hex[i] = f_sid->decrypt_hex[i];
return 0;
}

View File

@ -14,13 +14,15 @@ unsigned long long getId(void);
SID *getS_id(unsigned int type, unsigned int deep_level); SID *getS_id(unsigned int type, unsigned int deep_level);
int fitS_id(SID * const fs_id, SID * const ss_id); int fitS_id(SID * const fs_id, SID * const ss_id);
int simFitS_id(SID * const fs_id, SID * const ss_id); int simFitS_id(SID * fs_id, SID * ss_id);
char *s_idToASCIIString(SID * const s_id); char *s_idToASCIIString(SID * const s_id);
SID *asciiStringToS_id(char * const string); SID *asciiStringToS_id(char * const string);
void s_idToMD5(SID *s_id); void s_idToMD5(SID *s_id);
char hexToChar(unsigned char); char hexToChar(unsigned char);
SID *copyS_id(SID *f_sid);
void getRawS_id(SID *s_id, unsigned int type, unsigned int deep_level);
SID *initS_id(unsigned int deep_level); SID *initS_id(unsigned int deep_level);
int freeSidRaw(SID *s_id); int freeSidRaw(SID *s_id);

View File

@ -145,6 +145,18 @@ int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value)
} }
int insertInHead(List *p_list, Node *p_node) { int insertInHead(List *p_list, Node *p_node) {
if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1;
if(p_list->p_lq != NULL){
if(p_list->head->type == HOLE){
Node *t_node = p_list->head;
replaceNode(p_list, p_list->head, p_node);
p_list->p_lq->fn_node[0] = p_node;
releaseNode(t_node);
indexChange(p_list, 0, 1);
return 0;
}
indexChange(p_list, 0, 1);
}
if (isListEmpty(p_list)) { if (isListEmpty(p_list)) {
p_list->head = p_node; p_list->head = p_node;
p_list->tail = p_node; p_list->tail = p_node;
@ -172,6 +184,7 @@ inline int s_insertInHead(List *p_list, s_Node *s_p_node){
} }
int insertInTail(List *p_list, Node *p_node) { int insertInTail(List *p_list, Node *p_node) {
if(p_list->p_lq != NULL && p_list->p_lq->if_sort) return -1;
if (isListEmpty(p_list)) { if (isListEmpty(p_list)) {
p_list->head = p_node; p_list->head = p_node;
p_list->tail = p_node; p_list->tail = p_node;
@ -182,6 +195,15 @@ int insertInTail(List *p_list, Node *p_node) {
p_node->last = p_list->tail; p_node->last = p_list->tail;
p_list->tail = p_node; p_list->tail = p_node;
} }
if(p_list->p_lq != NULL){
p_node->f_number = p_list->p_lq->rlst_len;
if(p_list->p_lq->rlst_len >= p_list->p_lq->rlst_len + FN_NODE_SPARE)
p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(Node *) * (p_list->p_lq->rlst_len + FN_NODE_SPARE));
p_list->p_lq->fn_node[p_list->p_lq->rlst_len] = p_node;
p_list->p_lq->rlst_len++;
}
p_list->length += 1; p_list->length += 1;
return 0; return 0;
} }
@ -213,6 +235,7 @@ 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;
@ -246,6 +269,7 @@ int releaseList(List *p_list) {
p_list->tail = NULL; p_list->tail = NULL;
p_list->length = 0; p_list->length = 0;
if (p_list->s_id != NULL) freeS_id(p_list->s_id); if (p_list->s_id != NULL) freeS_id(p_list->s_id);
if(p_list->p_lq != NULL) disableListQuick(p_list);
free(p_list); free(p_list);
return 0; return 0;
} }
@ -254,6 +278,7 @@ int releaseListForSingle(List *p_list) {
p_list->head = NULL; p_list->head = NULL;
p_list->tail = NULL; p_list->tail = NULL;
if (p_list->s_id != NULL) freeS_id(p_list->s_id); if (p_list->s_id != NULL) freeS_id(p_list->s_id);
if(p_list->p_lq != NULL) disableListQuick(p_list);
p_list->length = 0; p_list->length = 0;
free(p_list); free(p_list);
return 0; return 0;
@ -263,7 +288,7 @@ unsigned long long len(List *p_list) {
return p_list->length; return p_list->length;
} }
int removeById(List *p_list, const SID *s_id) { int removeById(List *p_list, SID *s_id) {
Node *tmp = p_list->head; Node *tmp = p_list->head;
if (isListEmpty(p_list)) if (isListEmpty(p_list))
return -1; return -1;
@ -294,39 +319,56 @@ int removeById(List *p_list, const SID *s_id) {
} }
int removeByNode(List *p_list, Node *p_node) { int removeByNode(List *p_list, Node *p_node) {
Node *tmp = p_list->head;
if (isListEmpty(p_list)) if (isListEmpty(p_list))
return -1; return -1;
do { if(p_node == p_list->head){
if (tmp == p_node) { popFromHead(p_list);
tmp->last->next = tmp->next; return 0;
tmp->next->last = tmp->last; }
p_list->length -= 1; else if(p_node == p_list->tail){
return 1;//found 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{ else{
tmp = tmp->next; if(p_node != p_list->head){
if(p_node->f_number == 0){
Node *fn_node = findFnNode(p_list, p_node);
indexChange(p_list, fn_node->f_number, -1);
p_node->last->next = p_node->next;
p_node->next->last = p_node->last;
}
else{
digHole(p_list, p_node);
}
}
p_list->length -= 1;
} }
} while (tmp != NULL);
return 0;//not find return 0;//not find
} }
int popFromHead(List *p_list) { int popFromHead(List *p_list) {
if (isListEmpty(p_list)) if (isListEmpty(p_list))
return -1; return -1;
if(p_list->p_lq != NULL){
if(p_list->p_lq->fn_node[0] == p_list->head){
digHole(p_list, p_list->head);
}
}
else{ else{
//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;
//releaseNode(tmp); not necessary //releaseNode(tmp); not necessary
p_list->length -= 1;
}
if (isListEmpty(p_list)) { if (isListEmpty(p_list)) {
p_list->head = NULL; p_list->head = NULL;
p_list->tail = NULL; p_list->tail = NULL;
} }
p_list->length -= 1;
}
return 0; return 0;
} }
@ -334,21 +376,25 @@ int popFromTail(List *p_list) {
if (isListEmpty(p_list)) if (isListEmpty(p_list))
return -1; return -1;
else { else {
if(p_list->p_lq != NULL){
if(p_list->p_lq->fn_node[p_list->p_lq->rlst_len] == p_list->tail)
p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(p_list->p_lq->rlst_len - 1));
}
//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;
//releaseNode(tmp); not necessary //releaseNode(tmp); not necessary
p_list->length -= 1;
} }
if (isListEmpty(p_list)) { if (isListEmpty(p_list)) {
p_list->head = NULL; p_list->head = NULL;
p_list->tail = NULL; p_list->tail = NULL;
} }
p_list->length -= 1;
return 0; return 0;
} }
Node *findByIdForNode(List *p_list, const SID *s_id) { Node *findByIdForNode(List *p_list, SID * s_id) {
Node *ph_node = p_list->head; Node *ph_node = p_list->head;
Node *pt_node = p_list->tail; Node *pt_node = p_list->tail;
int direction = 0; int direction = 0;
@ -460,11 +506,12 @@ Node *copyNode(Node *p_node) {
Node *t_node = NULL; Node *t_node = NULL;
if (p_node->s_id == NULL) t_node = initNode(0); if (p_node->s_id == NULL) t_node = initNode(0);
else t_node = initNode(p_node->s_id->deep); else t_node = initNode(p_node->s_id->deep);
t_node->s_id = p_node->s_id; t_node->s_id = copyS_id(p_node->s_id);
t_node->last = p_node->last; t_node->last = p_node->last;
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;
t_node->f_number = p_node->f_number;
return t_node; return t_node;
} }
@ -477,12 +524,17 @@ List *copyList(List *p_list) {
t_list->head = p_list->head; t_list->head = p_list->head;
t_list->tail = p_list->tail; t_list->tail = p_list->tail;
t_list->s_id = p_list->s_id; t_list->s_id = p_list->s_id;
t_list->s_head = p_list->s_head;
t_list->length = p_list->length;
t_list->s_tail = p_list->s_tail;
if(p_list->head != NULL && p_list->tail != NULL){
p_node = p_list->head; p_node = p_list->head;
while (p_node != NULL) { while (p_node != NULL) {
t_node = copyNode(p_node); t_node = copyNode(p_node);
insertInTail(t_list, t_node); insertInTail(t_list, t_node);
p_node = p_node->next; p_node = p_node->next;
} }
}
return t_list; return t_list;
} }
@ -538,6 +590,7 @@ int releaseListForCustom(List *p_list, int (*func)(void *)){
p_list->tail = NULL; p_list->tail = NULL;
p_list->length = 0; p_list->length = 0;
if (p_list->s_id != NULL) freeS_id(p_list->s_id); if (p_list->s_id != NULL) freeS_id(p_list->s_id);
if(p_list->p_lq != NULL) disableListQuick(p_list);
free(p_list); free(p_list);
return 0; return 0;
} }
@ -613,23 +666,101 @@ 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;
if(p_list->p_lq != NULL){
if(pt_node->f_number == 0 && p_list->p_lq->fn_node[0] != pt_node){
p_node->f_number = pt_node->f_number;
}
else{
p_list->p_lq->fn_node[pt_node->f_number] = p_node;
p_node->f_number = pt_node->f_number;
}
}
return 0; return 0;
} }
int sortListById(List *p_list){ int exchangeNode(List *p_list, Node *f_node, Node *s_node){
Node *fl_node = f_node->last, *fn_node = f_node->next;
if(p_list->head != f_node) f_node->last->next = s_node;
else p_list->head = s_node;
if(p_list->tail != f_node) f_node->next->last = s_node;
else p_list->tail = s_node;
if(p_list->head != s_node) s_node->last->next = f_node;
else p_list->head = f_node;
if(p_list->tail != s_node) s_node->next->last = f_node;
else p_list->tail = f_node;
f_node->next = s_node->next;
f_node->last = s_node->last;
s_node->next = fn_node;
s_node->last = fl_node;
if(p_list->p_lq != NULL){
p_list->p_lq->fn_node[f_node->f_number] = s_node;
p_list->p_lq->fn_node[s_node->f_number] = f_node;
unsigned long long temp = f_node->f_number;
f_node->f_number = s_node->f_number;
s_node->f_number = temp;
}
return 0;
}
int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)){
unsigned long long target_index = begin;
register Node *t_node = findByIndexForNode(p_list, target_index);
register Node *i_node = NULL, *j_node = NULL;
register unsigned long long i = end,j = begin;
for(; i >= begin; i--){
if(i <= j) break;
i_node = findByIndexForNode(p_list, i);
if(func(t_node, i_node) < 0){
exchangeNode(p_list, t_node, i_node);
for(; j <= end; j++){
if(j >= i) break;
j_node = findByIndexForNode(p_list, j);
if(func(t_node, j_node) > 0){
exchangeNode(p_list, t_node, j_node);
break;
}
}
}
}
if(end - begin > 3){
if(t_node->f_number - begin > 2)
sortList(p_list, begin, t_node->f_number, func);
if(end - t_node->f_number > 2)
sortList(p_list, t_node->f_number, end, func);
}
return 0;
}
int sortListByCustom(List *p_list, int(*func)(Node *f_node, Node *s_node)){
if(p_list->p_lq != NULL && !p_list->p_lq->if_sort) p_list->p_lq->if_sort = 1;
sortList(p_list, 0, p_list->length-1, func);
return 0;
} }
int enableListQuick(List *p_list){ int enableListQuick(List *p_list){
if(p_list->length > 1500){ if(p_list->length > ENABLE_LIST_QUICK){
p_list->p_lq = malloc(sizeof(struct 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 = malloc(sizeof(Node *) * (p_list->length + FN_NODE_SPARE));
p_lq->if_sort = 0;
refreshFnNode(p_list);
//sortListById(p_list, 0, p_list->length);
return 0;
}
return -1;
}
int refreshFnNode(List *p_list){
if(p_list->p_lq != NULL){
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);
register Node *p_node = p_list->head; register Node *p_node = p_list->head;
unsigned long long i = 0; unsigned long long i = 0;
p_list->p_lq->rlst_len = p_list->length;
p_list->p_lq->fn_node = malloc(sizeof(Node *) * p_list->length);
p_list->p_lq->p_lindex = 0;
p_list->p_lq->head_index = 0;
p_list->p_lq->tail_index = p_list->length - 1;
while (p_node != NULL) { while (p_node != NULL) {
p_node->f_number = i++; p_node->f_number = i++;
p_list->p_lq->fn_node[i] = p_node; p_list->p_lq->fn_node[i] = p_node;
@ -639,3 +770,169 @@ int enableListQuick(List *p_list){
} }
return -1; 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 = p_lq->fn_node[index];
if(p_lq->idxc_count > 0){
int total_move = indexTransfromer(p_list, index);
if(total_move >=0){
for(int i = 0; i < ABS(total_move); i++) p_node = p_node->last;
}
else{
for(int i = 0; i < ABS(total_move); 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);
while(fn_node->f_number != 0) fn_node = fn_node->next;
indexChange(p_list, fn_node->f_number, 1);
}
p_list->length += 1;
return 0;
}
int insertBeforeNode(List *p_list, Node*t_node, Node *p_node){
if(t_node == p_list->head){
insertInHead(p_list, p_node);
return 0;
}
if(p_list->p_lq != NULL){
if(t_node->last->type == HOLE){
Node *temp_node = t_node->last;
replaceNode(p_list, t_node->last, p_node);
p_node->f_number = temp_node->f_number;
releaseNode(temp_node);
p_list->p_lq->fn_node[p_node->f_number] = p_node;
indexChange(p_list, p_node->f_number, 1);
return 0;
}
}
p_node->last = t_node->last;
p_node->next = t_node;
if(p_list->head != t_node)
t_node->last->next = p_node;
else
p_list->head = p_node;
t_node->last = p_node;
if(p_list->p_lq != NULL){
Node *fn_node = findFnNode(p_list, p_node);
indexChange(p_list, fn_node->f_number, 1);
}
p_list->length += 1;
return 0;
}
Node *findFnNode(List *p_list, Node *p_node){
Node *fn_node = p_node;
while(fn_node->f_number != 0) fn_node = fn_node->next;
return fn_node;
}
void initIdxcList(List *p_list){
struct list_quick *p_lq = p_list->p_lq;
for(int i = 0; i < INDEX_CHANGE_MAX; i++){
if(p_lq->idxc_lst[i] != NULL) free(p_lq->idxc_lst[i]);
p_lq->idxc_lst[i] = NULL;
}
p_lq->idxc_count = 0;
}
void digHole(List *p_list, Node *p_node){
Node *c_node = copyNode(p_node);
freeS_id(c_node->s_id);
replaceNode(p_list, p_node, c_node);
c_node->value = NULL;
c_node->type = HOLE;
indexChange(p_list, p_node->f_number, -1);
}
int disableListQuick(List *p_list){
free(p_list->p_lq->fn_node);
initIdxcList(p_list);
free(p_list->p_lq);
return 0;
}

View File

@ -3,6 +3,26 @@
#include "../type/type.h" #include "../type/type.h"
#include "../id/id.h" #include "../id/id.h"
#define lni(x) nodeWithInt(x,0)
#define lnd(x) nodeWithDouble(x,0)
#define lns(x) nodeWithString(x,0)
#define lnp(x) nodeWithPointer(x,0)
#define lsni(x) nodeWithInt(x,1)
#define lsnd(x) nodeWithDouble(x,1)
#define lsns(x) nodeWithString(x,1)
#define lsnp(x) nodeWithPointer(x,1)
#define lisrti(list, x) insertInTail(list, lni(x));
#define lisrtd(list, x) insertInTail(list, lnd(x));
#define lisrtp(list, x) insertInTail(list, lnp(x));
#define lisrts(list, x) insertInTail(list, lns(x));
#define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x))
#define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x))
#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x))
#define lidxs(list, x) getByStringForNode(findByIndexForNode(list, x))
int safeModeForNode(int ifon); int safeModeForNode(int ifon);
int releaseSingleListForsafeModeForNode(List *p_list); int releaseSingleListForsafeModeForNode(List *p_list);
int releaseSingleNodeForsafeModeForNode(List *p_list); int releaseSingleNodeForsafeModeForNode(List *p_list);
@ -16,21 +36,24 @@ int initMallocValueForNode(Node *,unsigned int,const void *);
int insertInHead(List *p_list, Node *p_node); int insertInHead(List *p_list, Node *p_node);
int insertInTail(List *p_list, Node *p_node); int insertInTail(List *p_list, Node *p_node);
int insertAfterNode(List *p_list, Node *t_node, Node *p_node);
int insertBeforeNode(List *p_list, Node*t_node, Node *p_node);
int s_insertInHead(List *p_list, s_Node *s_p_node); int s_insertInHead(List *p_list, s_Node *s_p_node);
int s_insertInTail(List *p_list, s_Node *s_p_node); int s_insertInTail(List *p_list, s_Node *s_p_node);
int replaceNode(List *p_list, Node *pt_node, Node *p_node); int replaceNode(List *p_list, Node *pt_node, Node *p_node);
int exchangeNode(List *p_list, Node *f_node, Node *s_node);
Node *copyNode(Node *); Node *copyNode(Node *);
int removeById(List *p_list, const SID *s_id); int removeById(List *p_list, SID *s_id);
int removeByNode(List *p_list, Node *p_node); int removeByNode(List *p_list, Node *p_node);
int popFromHead(List *p_list); int popFromHead(List *p_list);
int popFromTail(List *p_list); int popFromTail(List *p_list);
unsigned long long len(List *p_list); unsigned long long len(List *p_list);
Node *findByIdForNode(List *p_list, const SID *s_id); Node *findByIdForNode(List *p_list, SID * s_id);
Node *findByValue(List *p_list, unsigned int type, const void *value); Node *findByValue(List *p_list, unsigned int type, const void *value);
List *mply_findByValue(List *p_list, unsigned int type, const void *value); List *mply_findByValue(List *p_list, unsigned int type, const void *value);
@ -64,7 +87,32 @@ int showError(Error *);
int showWarning(Notice *); int showWarning(Notice *);
int enableListQuick(List *p_list); int enableListQuick(List *p_list);
int sortListById(List *p_list); int refreshFnNode(List *p_list);
int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node));
int sortListByCustom(List *p_list, int(*func)(Node *f_node, Node *s_node));
int indexTransfromer(List *p_list, unsigned long long m_index);
int indexChange(List *p_list, unsigned long long c_index, int move);
Node *getNodeByFnNode(List *p_list, unsigned long long index);
Node *findFnNode(List *p_list, Node *p_node);
void initIdxcList(List *p_list);
void digHole(List *p_list, Node *p_node);
int disableListQuick(List *p_list);
Node *findByIndexForNode(List *, unsigned long long);
Node *findByIntForNode(List *, int);
Node *findByDoubleForNode(List *, double);
Node *findByStringForNode(List *, char *);
Node *findByPointerForNode(List *, void *);
Node *getListTail(List *);
Node *updateNodeByIndex(List *, void *, unsigned long long);
int getByIntForNode(Node *);
unsigned int getByUIntForNode(Node *);
double getByDoubleForNode(Node *);
char *getByStringForNode(Node *);
void *getByPointerForNode(Node *);
unsigned long long getIndexForNode(List *p_list,Node *p_node);
static int if_safeModeForNode; static int if_safeModeForNode;
static List *node_list; static List *node_list;

View File

@ -4,7 +4,7 @@ Node *nodeWithInt(int m_int, _Bool if_sid) {
Node *p_node; Node *p_node;
int *p_int = (int *)malloc(sizeof(int)); int *p_int = (int *)malloc(sizeof(int));
if(p_int == NULL){ if(p_int == NULL){
showError(pushError(INT, STANDARD, initInfo("nodeWithInt()", "Error in getting the memory of int."))); showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int.")));
return NULL; return NULL;
} }
*p_int = m_int; *p_int = m_int;
@ -17,7 +17,7 @@ Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){
Node *p_node; Node *p_node;
unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int)); unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int));
if(pu_int == NULL){ if(pu_int == NULL){
showError(pushError(INT, STANDARD, initInfo("nodeWithUInt()", "Error in getting the memory of int."))); showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int.")));
return NULL; return NULL;
} }
*pu_int = m_uint; *pu_int = m_uint;
@ -26,11 +26,24 @@ Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){
return p_node; return p_node;
} }
Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) {
Node *p_node;
unsigned long long *p_ullint = (unsigned long long *)malloc(sizeof(unsigned long long));
if(p_ullint == NULL){
showError(pushError(INT, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of int.")));
return NULL;
}
*p_ullint = m_ullint;
p_node = initNode(if_sid);
initMallocValueForNode(p_node, ULLINT, (void *)p_ullint);
return p_node;
}
Node *nodeWithDouble(double m_double, _Bool if_sid) { Node *nodeWithDouble(double m_double, _Bool if_sid) {
Node *p_node; Node *p_node;
double *p_double = (double *)malloc(sizeof(double)); double *p_double = (double *)malloc(sizeof(double));
if(p_double == NULL){ if(p_double == NULL){
showError(pushError(DOUBLE, STANDARD, initInfo("nodeWithDouble()", "Error in getting the memory of double."))); showError(pushError(DOUBLE, STANDARD, initInfo(__FUNCTION__, "Error in getting the memory of double.")));
return NULL; return NULL;
} }
*p_double = m_double; *p_double = m_double;
@ -68,9 +81,8 @@ Node *nodeWithComplex(void) {
Node *findByIndexForNode(List *p_list, unsigned long long m_index) { Node *findByIndexForNode(List *p_list, unsigned long long m_index) {
if(p_list->p_lq != NULL){ if(p_list->p_lq != NULL){
register struct list_quick *p_lq = p_list->p_lq; register struct list_quick *p_lq = p_list->p_lq;
if(m_index > p_lq->head_index && p_lq->last_index) return p_lq->fn_node[m_index]; if(p_lq->fn_node != NULL) return getNodeByFnNode(p_list, m_index);
} }
else{
Node *p_node = p_list->head; 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++) {
@ -78,7 +90,6 @@ Node *findByIndexForNode(List *p_list, unsigned long long m_index) {
} }
return p_node; return p_node;
} }
}
s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) { s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) {
s_Node *s_p_node = p_list->s_head; s_Node *s_p_node = p_list->s_head;
@ -92,6 +103,8 @@ s_Node *s_findByIndexForNode(List *p_list, unsigned long long m_index) {
List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) { List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) {
Node *p_node = p_list->head; Node *p_node = p_list->head;
List *m_rtnlst = NULL; List *m_rtnlst = NULL;
unsigned long long count = 0;
insertInTail(expand_resources, nodeWithULLInt(count, 0));
while (p_node != NULL) { while (p_node != NULL) {
if (p_node->value != NULL) { if (p_node->value != NULL) {
List *m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources); List *m_rtnlst = (*p_func)(p_node->type, p_node->value, expand_resources);
@ -510,6 +523,7 @@ inline s_Node *s_nodeWithUInt(unsigned int t_uint){
s_p_node->value = pt_uint; s_p_node->value = pt_uint;
return s_p_node; return s_p_node;
} }
inline s_Node *s_nodeWithDouble(double t_double){ inline s_Node *s_nodeWithDouble(double t_double){
s_Node *s_p_node = s_initNode(); s_Node *s_p_node = s_initNode();
unsigned int *pt_double = malloc(sizeof(double)); unsigned int *pt_double = malloc(sizeof(double));
@ -517,6 +531,7 @@ inline s_Node *s_nodeWithDouble(double t_double){
s_p_node->value = pt_double; s_p_node->value = pt_double;
return s_p_node; return s_p_node;
} }
inline s_Node *s_nodeWithString(const char *t_string){ inline s_Node *s_nodeWithString(const char *t_string){
s_Node *s_p_node = s_initNode(); s_Node *s_p_node = s_initNode();
char *pt_string = malloc(strlen(t_string) + 1); char *pt_string = malloc(strlen(t_string) + 1);
@ -524,8 +539,56 @@ inline s_Node *s_nodeWithString(const char *t_string){
s_p_node->value = pt_string; s_p_node->value = pt_string;
return s_p_node; return s_p_node;
} }
inline s_Node *s_nodeWithPointer(const void *t_pointer){ inline s_Node *s_nodeWithPointer(const void *t_pointer){
s_Node *s_p_node = s_initNode(); s_Node *s_p_node = s_initNode();
s_p_node->value = (void *) t_pointer; s_p_node->value = (void *) t_pointer;
return s_p_node; return s_p_node;
} }
List *newReturn(int if_status ,int status, char *argc, ...){
List *p_list = initList(0);
if(if_status){
lisrti(p_list, status);
}
if(status != 0){
va_list args;
va_start(args, argc);
char p_ch = argc[0];
char t_ch[256];
int count = 0, t_count = 0;
while(p_ch != '\0'){
if(p_ch == '%'){
switch (argc[count + 1]) {
case 'd':
lisrti(p_list, va_arg(args, int));
break;
case 's':
t_count = 0;
while ((t_ch[t_count] = va_arg(args, int)) != '\0') t_count++;
t_ch[t_count] = '\0';
lisrts(p_list, t_ch);
break;
case 'f':
lisrtd(p_list, va_arg(args, double));
break;
case 'p':
lisrtp(p_list, va_arg(args, void *));
break;
default:
break;
}
count++;
}
p_ch = argc[++count];
}
va_end(args);
}
return p_list;
}
List *newCReturn(void){
return newReturn(1, 0, NULL);
}

View File

@ -3,11 +3,25 @@
#include "list.h" #include "list.h"
Node *nodeWithInt(int); #define RETURN(argc, args...) newReturn(1, -1, argc , args)
Node *nodeWithUInt(unsigned int); #define C_RETURN newCReturn()
Node *nodeWithDouble(double); #define SEND_ARG(argc, args...) newReturn(0, -1, argc , args)
Node *nodeWithString(const char *); #define CALLBACK_STATE(name) List *do_##name(unsigned int, void *, List *)
Node *nodeWithPointer(const void *); #define CALLBACK_DEFINE(name) List *do_##name(unsigned int type, void *value, List *args)
#define VALUE(c_type) (c_type)value
#define ARGS(x, type)\
if(#type == "int") lidxi(args, x);\
else if if(#type == "double") lidxd(args, x);\
else if(#type == "string") lidxs(args, x);\
else lidxi(args, x);
#define CALLBACK_CALL(name) do_##name
Node *nodeWithInt(int, _Bool if_sid);
Node *nodeWithUInt(unsigned int, _Bool if_sid);
Node *nodeWithULLInt(unsigned long long, _Bool if_sid);
Node *nodeWithDouble(double, _Bool if_sid);
Node *nodeWithString(const char *, _Bool if_sid);
Node *nodeWithPointer(const void *, _Bool if_sid);
s_Node *s_nodeWithInt(int); s_Node *s_nodeWithInt(int);
s_Node *s_nodeWithUInt(unsigned int); s_Node *s_nodeWithUInt(unsigned int);
@ -27,12 +41,6 @@ int updateValueWithDoubleForNode(Node *,double);
int updateValueWithStringForNode(Node *,char *); int updateValueWithStringForNode(Node *,char *);
int updateValueWithPointerForNode(Node *,void *); int updateValueWithPointerForNode(Node *,void *);
Node *findByIndexForNode(List *, unsigned long long);
Node *findByIntForNode(List *, int);
Node *findByDoubleForNode(List *, double);
Node *findByStringForNode(List *, char *);
Node *findByPointerForNode(List *, void *);
List *mply_findByIntForNode(List*, int); List *mply_findByIntForNode(List*, int);
List *mply_findByDoubleForNode(List*, double); List *mply_findByDoubleForNode(List*, double);
List *mply_findByStringForNode(List*, char *); List *mply_findByStringForNode(List*, char *);
@ -43,13 +51,9 @@ void printNodeInfo(Node *p_node,int priority);
void printList(List *); void printList(List *);
void printNode(Node *p_node); void printNode(Node *p_node);
int getByIntForNode(Node *);
unsigned int getByUIntForNode(Node *);
double getByDoubleForNode(Node *);
char *getByStringForNode(Node *);
void *getByPointerForNode(Node *);
unsigned long long getIndexForNode(List *p_list,Node *p_node);
List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *), List *expand_resources); List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *), List *expand_resources);
List *newReturn(int if_status ,int status, char *argc, ...);
List *newCReturn(void);
unsigned long long calListMemory(List *); unsigned long long calListMemory(List *);
#endif #endif

18
test.c
View File

@ -82,19 +82,9 @@ int stack(void) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
init_rand(); SID *p_sid = getS_id(VOID, 2);
List *t_list = initList(); s_idToASCIIString(p_sid);
for (int i = 0; i < 100; i++) { printf("%s",p_sid->decrypt_str);
insertInHead(t_list, nodeWithInt(i)); freeS_id(p_sid);
}
STD_DATA *p_std = listToSTD(t_list);
D_FILE *p_dfilew = initDataFileForWrite("data.df");
dataFileAddStandardData(p_dfilew, p_std);
dataFileWriteIn(p_dfilew);
releaseDFile(p_dfilew);
D_FILE *p_dfiler = initDataFileForRead("data.df");
dataFileReadOut(p_dfiler);
releaseDFile(p_dfiler);
releaseList(t_list);
return 0; return 0;
} }

View File

@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h>
/* /*
#include <sys/types.h> #include <sys/types.h>
@ -31,6 +32,8 @@
#define STANDARD_DATA 13 #define STANDARD_DATA 13
#define DATA_FILE 14 #define DATA_FILE 14
#define MESSAGE 15 #define MESSAGE 15
#define HOLE 16
#define ULLINT 17
#define DEEPC 1 #define DEEPC 1
#define DEEPB 2 #define DEEPB 2
@ -43,14 +46,20 @@
#define DEEP_LEN 25 #define DEEP_LEN 25
#define DEEPER_LEN 65 #define DEEPER_LEN 65
#define DEEPEST_LEN 225 #define DEEPEST_LEN 225
#define SID_LEN 32
#define FILE_TSET_LEN 18 #define FILE_TSET_LEN 18
#define HEAD_TEST_LEN 9 #define HEAD_TEST_LEN 9
#define ENABLE_LIST_QUICK 1500
#define FN_NODE_SPARE 12
#define INDEX_CHANGE_MAX 500
#define INDEX_DISTANCE_MAX 120
#define HIGH 0x3 #define HIGH 0x3
#define STANDARD 0x2 #define STANDARD 0x2
#define LOW 0x1 #define LOW 0x1
#define ABS(x) (x>0)?(x):(-x)
typedef struct md5_ctx{ typedef struct md5_ctx{
unsigned int count[2]; unsigned int count[2];
unsigned int state[4]; unsigned int state[4];
@ -105,12 +114,16 @@ typedef struct List{
SID *s_id; SID *s_id;
} List; } List;
struct index_change{
unsigned long long c_index;
int f_count;
};
struct list_quick{ struct list_quick{
Node **fn_node; Node **fn_node;
unsigned long long last_index; _Bool if_sort;
Node *p_lindex; unsigned int idxc_count;
unsigned long long head_index; struct index_change *idxc_lst[INDEX_CHANGE_MAX];
unsigned long long tail_index;
unsigned long long rlst_len; unsigned long long rlst_len;
FILE *fp; FILE *fp;
List *stdid_lst; List *stdid_lst;