This commit is contained in:
Saturneic 2018-08-22 16:36:26 +08:00
parent c5890b4c1f
commit b153b11a29
8 changed files with 797 additions and 705 deletions

View File

@ -3,32 +3,52 @@
version = "1.0">
<ContextStates>
<ContextState
contextName = "init_node:list.h">
contextName = "_doStandardDataToList:communicate.c">
</ContextState>
<ContextState
contextName = "s_idToASCIIString:id.c">
<PersistentStrings>
<PersistentString
value = "list_list">
value = "sizeof(char)">
</PersistentString>
<PersistentString
value = "buff[buff_count]">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "listToSTD:communicate.c">
contextName = "standardDataAddBlock:communicate.c">
<PersistentStrings>
<PersistentString
value = "(int *)p_node-&gt;value">
value = "(int *)data">
</PersistentString>
<PersistentString
value = "(int *)p_stdb-&gt;buff">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "releaseMalloc:list.h">
contextName = "setS_idWithString:id.c">
</ContextState>
<ContextState
contextName = "initS_id:id.c">
contextName = "initStandardDBlocks:communicate.c">
</ContextState>
<ContextState
contextName = "printStandardData:communicate.c">
contextName = "readStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "initStandardData:communicate.c">
contextName = "dataForStandardDBlock:communicate.c">
<PersistentStrings>
<PersistentString
value = "(int *)p_stdb-&gt;buff">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "releaseNULLList:list.h">
</ContextState>
<ContextState
contextName = "findByIndexForNode:list_expand.c">
</ContextState>
<ContextState
contextName = "getByIntForNode:list_expand.c">
@ -39,22 +59,36 @@
</PersistentStrings>
</ContextState>
<ContextState
contextName = "listThrough:list_expand.c">
contextName = "freeS_id:id.c">
</ContextState>
<ContextState
contextName = "readStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "initStandardDBlocks:communicate.c">
</ContextState>
<ContextState
contextName = "dataForStandardDBlock:communicate.c">
contextName = "dataFileReadOut:communicate.c">
<PersistentStrings>
<PersistentString
value = "(int *)p_stdb-&gt;buff">
value = "strlen(string_sid)">
</PersistentString>
<PersistentString
value = "(int *)content">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "main:test.c">
<PersistentStrings>
<PersistentString
value = "(int *)p_node-&gt;value">
</PersistentString>
<PersistentString
value = "strlen(string)">
</PersistentString>
<PersistentString
value = "((STD_DATA *)(p_dfiler-&gt;pf_stdlst-&gt;head-&gt;value))-&gt;pd_blocklst">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "insertInHead:list.c">
</ContextState>
<ContextState
contextName = "insertInTail:list.h">
<PersistentStrings>
@ -67,7 +101,52 @@
</PersistentStrings>
</ContextState>
<ContextState
contextName = "releaseNULLList:list.h">
contextName = "releaseMalloc:list.h">
</ContextState>
<ContextState
contextName = "listToSTD:communicate.c">
<PersistentStrings>
<PersistentString
value = "(int *)p_node-&gt;value">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "initStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "printListForCustom:list_expand.c">
</ContextState>
<ContextState
contextName = "init_node:list.h">
<PersistentStrings>
<PersistentString
value = "list_list">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "printStandardData:communicate.c">
</ContextState>
<ContextState
contextName = "indexTransfromer:list.c">
</ContextState>
<ContextState
contextName = "listThrough:list_expand.c">
</ContextState>
<ContextState
contextName = "initS_id:id.c">
</ContextState>
<ContextState
contextName = "standardDataToList:communicate.c">
<PersistentStrings>
<PersistentString
value = "(STD_BLOCKS *)p_std-&gt;pd_blocklst-&gt;head-&gt;value">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "readDataFileInfo:communicate.c">
</ContextState>
<ContextState
contextName = "asciiStringToS_id:id.c">
@ -86,95 +165,33 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "_doStandardDBlockWrite:communicate.c">
<PersistentStrings>
<PersistentString
value = "&amp;p_stdb-&gt;blocks_num">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "dataFileReadOut:communicate.c">
<PersistentStrings>
<PersistentString
value = "strlen(string_sid)">
</PersistentString>
<PersistentString
value = "(int *)content">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "printListForCustom:list_expand.c">
</ContextState>
<ContextState
contextName = "standardDataToList:communicate.c">
<PersistentStrings>
<PersistentString
value = "(STD_BLOCKS *)p_std-&gt;pd_blocklst-&gt;head-&gt;value">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "_doStandardDataInfoWrite:communicate.c">
</ContextState>
<ContextState
contextName = "standardDataAddBlock:communicate.c">
contextName = "dataFileWriteIn:communicate.c">
</ContextState>
<ContextState
contextName = "getNodeByFnNode:list.c">
<PersistentStrings>
<PersistentString
value = "(int *)data">
</PersistentString>
<PersistentString
value = "(int *)p_stdb-&gt;buff">
value = "ABS(total_move)">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "copyS_id:id.c">
</ContextState>
<ContextState
contextName = "dataFileWriteIn:communicate.c">
</ContextState>
<ContextState
contextName = "freeS_id:id.c">
</ContextState>
<ContextState
contextName = "setS_idWithString:id.c">
</ContextState>
<ContextState
contextName = "s_idToASCIIString:id.c">
<PersistentStrings>
<PersistentString
value = "sizeof(char)">
</PersistentString>
<PersistentString
value = "buff[buff_count]">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "main:test.c">
<PersistentStrings>
<PersistentString
value = "strlen(string)">
</PersistentString>
<PersistentString
value = "((STD_DATA *)(p_dfiler-&gt;pf_stdlst-&gt;head-&gt;value))-&gt;pd_blocklst">
</PersistentString>
<PersistentString
value = "(int *)p_node-&gt;value">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "readDataFileInfo:communicate.c">
</ContextState>
<ContextState
contextName = "_doStandardDataToList:communicate.c">
</ContextState>
<ContextState
contextName = "init_list:list.h">
</ContextState>
<ContextState
contextName = "_doStandardDBlockWrite:communicate.c">
<PersistentStrings>
<PersistentString
value = "&amp;p_stdb-&gt;blocks_num">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>

View File

@ -41,6 +41,7 @@ STD_DATA *initStandardData(unsigned int type, SID *s_id){
p_std->type = type;
p_std->size = 0;
p_std->location = 0;
p_std->read_data = 0;
if(s_id == NULL) p_std->s_id = getS_id(STANDARD_DATA, 2);
else p_std->s_id = copyS_id(s_id);
@ -89,6 +90,7 @@ int dataFileAddStandardData(D_FILE *p_dfile, STD_DATA *p_std){
}
int dataFileWriteIn(D_FILE *p_dfile){
fwrite(p_dfile->pf_head->head_test, sizeof(char), 18, p_dfile->fp);
fwrite(&p_dfile->pf_head->data_num, sizeof(unsigned long long), 1, p_dfile->fp);
fwrite("STDINFO", sizeof(char), 8, p_dfile->fp);
@ -385,6 +387,7 @@ int readStandardData(D_FILE *p_dfile,STD_DATA *p_std){
freeS_id(sb_sid);
}
}
p_std->read_data = 1;
return 0;
}

View File

@ -138,7 +138,7 @@ List *initList(_Bool if_sid) {
return p_list;
}
int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) {
inline int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) {
p_node->type = type;
p_node->value = (void *)p_value;
return 0;
@ -149,10 +149,11 @@ int insertInHead(List *p_list, Node *p_node) {
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);
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);
@ -198,8 +199,10 @@ int insertInTail(List *p_list, Node *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));
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++;
}
@ -225,7 +228,7 @@ int releaseNode(Node *p_node) {
removeByNode(node_list, p_node);
}
if (p_node->value != NULL) {
if (p_node->type != POINTER) {
if (p_node->type != POINTER && p_node->type != HOLE) {
if (p_node->type == LIST) {
releaseList((List *)p_node->value);
}
@ -331,16 +334,14 @@ int removeByNode(List *p_list, Node *p_node) {
p_node->next->last = p_node->last;
}
else{
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);
}
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;
}
@ -352,8 +353,22 @@ Node *popFromHead(List *p_list) {
return NULL;
Node *p_node = p_list->head;
if(p_list->p_lq != NULL){
if(p_list->p_lq->fn_node[0] == p_list->head){
digHole(p_list, p_list->head);
if(p_list->head->type == HOLE){
Node *t_node = p_list->head;
while(t_node->type == HOLE) t_node = t_node->next;
if(t_node->f_number != 0){
Node *r_node = t_node;
digHole(p_list, t_node);
return r_node;
}
p_node = t_node;
}
else{
if(p_list->p_lq->fn_node[0] == p_list->head){
Node *r_node = p_list->head;
digHole(p_list, p_list->head);
return r_node;
}
}
}
else{
@ -376,8 +391,14 @@ Node *popFromTail(List *p_list) {
return NULL;
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));
if(p_list->p_lq->fn_node[p_list->p_lq->rlst_len - 1] == p_list->tail){
p_list->p_lq->fn_node[p_list->p_lq->rlst_len - 1] = NULL;
p_list->p_lq->rlst_len--;
if(p_list->p_lq->fn_len - p_list->p_lq->rlst_len > FN_NODE_SPARE * 2){
p_list->p_lq->fn_node = realloc(p_list->p_lq->fn_node, sizeof(p_list->p_lq->fn_len - FN_NODE_SPARE));
p_list->p_lq->fn_len -= FN_NODE_SPARE;
}
}
}
//Node *tmp = p_list->tail;
p_list->tail->last->next = NULL;
@ -743,27 +764,41 @@ int enableListQuick(List *p_list){
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->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;
}
return -1;
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);
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) {
p_node->f_number = i++;
if(p_node->type == HOLE){
removeByNode(p_list, p_node);
releaseNode(p_node);
p_node = p_node->next;
continue;
}
p_node->f_number = i;
p_list->p_lq->fn_node[i] = p_node;
p_node = p_node->next;
i++;
}
p_list->p_lq = blk_plq;
return 0;
}
return -1;
@ -821,14 +856,29 @@ int indexTransfromer(List *p_list, unsigned long long m_index){
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];
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);
if(total_move >=0){
for(int i = 0; i < ABS(total_move); i++) p_node = p_node->last;
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{
for(int i = 0; i < ABS(total_move); i++) p_node = p_node->next;
unsigned long long jump = index - temp;
for(int i = 0; i < jump; i++) p_node = p_node->next;
}
return p_node;
}
@ -866,7 +916,6 @@ int insertAfterNode(List *p_list, Node *t_node, Node *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;
@ -906,7 +955,7 @@ int insertBeforeNode(List *p_list, Node*t_node, Node *p_node){
Node *findFnNode(List *p_list, Node *p_node){
Node *fn_node = p_node;
while(fn_node->f_number != 0) fn_node = fn_node->next;
while(fn_node->f_number == 0) fn_node = fn_node->next;
return fn_node;
}

View File

@ -22,6 +22,13 @@
#define lisrtp(list, x) insertInTail(list, lnp(x));
#define lisrts(list, x) insertInTail(list, lns(x));
#define lisrhi(list, x) insertInHead(list, lni(x));
#define lisrhd(list, x) insertInHead(list, lnd(x));
#define lisrhu(list, x) insertInHead(list, lnu(x));
#define lisrhull(list, x) insertInHead(list, lnull(x));
#define lisrhp(list, x) insertInHead(list, lnp(x));
#define lisrhs(list, x) insertInHead(list, lns(x));
#define lidxp(list, x) getByPointerForNode(findByIndexForNode(list, x))
#define lidxi(list, x) getByIntForNode(findByIndexForNode(list, x))
#define lidxd(list, x) getByDoubleForNode(findByIndexForNode(list, x))

53
test.c
View File

@ -60,23 +60,44 @@ int stack(void) {
releaseStack(t_stack);
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) {
for (int i = 0; i < 65535; i++){
list();
/*D_FILE *p_dfile = initDataFileForRead("data.db");
readDataFileInfo(p_dfile);
SID *temp_sid = setS_idWithString("f7dd8f0a75a0c20e4dca1b78347083cf");
readStandardDataBySid(p_dfile, temp_sid);
freeS_id(temp_sid);
printListForCustom(p_dfile->pf_stdlst, printStandardData);
List *t_list = standardDataToList(p_dfile->pf_stdlst->head->value);
printList(t_list);
releaseList(t_list);
releaseDFile(p_dfile);*/
usleep(500);
}
//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);
return 0;
}

7
test.h
View File

@ -1,5 +1,7 @@
#ifndef TEST_H
#define TEST_H
#define TEST_H
#include <sys/time.h>
#include "type/type.h"
#include "list/list_expand.h"
@ -9,6 +11,7 @@
int stack(void);
int list(void);
int tree(void);
int tree(void);
int time_avg(void);
#endif // TEST_H

View File

@ -50,8 +50,8 @@
#define FILE_TSET_LEN 18
#define HEAD_TEST_LEN 9
#define INFO_TEST_LEN 8
#define ENABLE_LIST_QUICK 1500
#define FN_NODE_SPARE 12
#define ENABLE_LIST_QUICK 65535
#define FN_NODE_SPARE 500
#define INDEX_CHANGE_MAX 500
#define INDEX_DISTANCE_MAX 120
#define STD_TEXT_LEN 4
@ -60,7 +60,7 @@
#define STANDARD 0x2
#define LOW 0x1
#define ABS(x) (x>0)?(x):(-x)
#define ABS(x) ((x>0)?(x):(-x))
typedef struct md5_ctx{
unsigned int count[2];
@ -125,6 +125,7 @@ struct list_quick{
Node **fn_node;
_Bool if_sort;
unsigned int idxc_count;
unsigned long long fn_len;
struct index_change *idxc_lst[INDEX_CHANGE_MAX];
unsigned long long rlst_len;
FILE *fp;
@ -224,6 +225,7 @@ typedef struct standard_data_head{
typedef struct standard_data{
SID *s_id;
int read_data;
unsigned int type;
unsigned long long size;
unsigned long long location;