static int _release(lua_State *L) { skiplist *sl = _to_skiplist(L); printf("collect sl:%p\n", sl); slFree(sl); return 0; }
int main(void) { srand((unsigned)time(0)); int count = 20, i; printf("### Function Test ###\n"); printf("=== Init Skip List ===\n"); skiplist *sl = slCreate(); for (i = 0; i < count; ++i) { slInsert(sl, i); } printf("=== Print Skip List ===\n"); slPrint(sl); printf("=== Search Skip List ===\n"); for (i = 0; i < count; ++i) { int value = rand() % (count + 10); slSearch(sl, value); } printf("=== Delete Skip List ===\n"); for (i = 0; i < count + 10; i += 2) { printf("Delete[%d]: %s\n", i, slDelete(sl, i) ? "SUCCESS" : "NOT FOUND"); } slPrint(sl); slFree(sl); sl = NULL; return 0; }
int decodeReq(const char *reqStr, char *content, PReq req) { PStrList reqList=slCreate(""); char *p; memset(req, 0, sizeof(TReq)); slSetText(reqList, reqStr, "\n"); // logMsg("ReqLine Count=%d,",reqList->count); // logMsg("'ReqID',"); req->ReqID=slGetValueInt(reqList, "ReqID", -1); p=slGetValue(reqList, "URL"); if(p) strcpy(req->URL, p); p=slGetValue(reqList, "CT"); if(p) strcpy(req->ContentType, p); p=slGetValue(reqList, "Cookies"); if(p) decodeLine(p, req->Cookies); req->Content=slGetValue(reqList, "Content"); p=slGetValue(reqList, "CL"); if(p) req->ContentSize=atoi(p); if(req->Content) { if(content==NULL) content=(char *)reqStr; req->ContentSize=decodeLine(req->Content, content); req->Content=content; // logMsg("%d bytes. Finish.\n", req->ContentSize); } slFree(reqList); return 1; }
PStrList queryStrToList(const char *queryStr) { PStrList res=slCreate(""); if(queryStr) { int i; PStrList content=slCreate(""); slSetText(content, queryStr, "&"); for(i=0;i<content->count;i++) if(content->strs[i]) slAdd(res, decodeQueryStr(content->strs[i])); slFree(content); } return res; }