Word GMSDS(Word *A, Word m, Word (*C)(Word,Word)) { Word *T,*T1,*T2,*A1,*A2,m1,m1p,m2,m2p,mp,k,l; Step1: /* Split. */ m1 = m >> 1; m2 = m1 + ODD(m); A1 = A; A2 = A + m1; Step2: /* Sort sublists. */ if (m1 < 4) { m1p = G23VSDS(A1,m1,C); } else m1p = GMSDS(A1,m1,C); if (m2 < 4) { m2p = G23VSDS(A2,m2,C); } else m2p = GMSDS(A2,m2,C); Step3: /* Copy A1 into a temporary array. */ T1 = GETARRAY(m1); for(k = 0; k < m1; k++) T1[k] = A1[k]; A1 = T1; Step4: /* Copy A2 into a temporary array. */ T2 = GETARRAY(m2); for(k = 0; k < m2; k++) T2[k] = A2[k]; A2 = T2; Step5: /* Merge A1 and A2 until one or both is exhausted. */ mp = m; for(k = 0; (m1p > 0) && (m2p > 0); k++) { switch(C(A1[0],A2[0])) { case (1) : A[k] = A2[0]; A2++; m2p--; break; case (0) : A[k] = A1[0]; A1++; m1p--; A[--mp] = A2[0];A2++; m2p--; break; case (-1): A[k] = A1[0]; A1++; m1p--; break; } } Step6: /* Complete merge. */ while (m1p > 0) { A[k++] = A1[0]; A1++; m1p--; } while (m2p > 0) { A[k++] = A2[0]; A2++; m2p--; } Step7: /* Write suppressed duplicates to end. */ for(T = T1 + m1 -1; T >= A1; T--) { A[--mp] = T[0]; } for(T = T2 + m2 -1; T >= A2; T--) { A[--mp] = T[0]; } Return: /* Prepare to return. */ FREEARRAY(T1); FREEARRAY(T2); return (mp); }
Word MINHITSETSRDR(Word A, Word B) { Word n,*N,i,L,Ap; Step1: /* Quick decisions. */ if (A == NIL) return (NIL); if ((B == 0) || (FIRST(A) == NIL)) return (MC_FAIL); Step2: /* Sort Rows. */ n = LENGTH(A); N = GETARRAY(n); i = 0; for(L = A; L != NIL; L = RED(L)) N[i++] = FIRST(L); n = GMSDS(N,n,comp); Step3: /* Reconstruct list. */ Ap = NIL; for(i = n - 1; i >= 0; i--) Ap = COMP(N[i],Ap); Return: /* Return. */ FREEARRAY(N); return (MINHITSET(Ap,B)); }
Word LDCOEFMASK(Word c, Word P, Word J) { Word *A,P_2,n,i,M,P_1,L,m,j,p,Lp,h,q,v,l; Step1: /* Set up A to be a characteristic vector for the set of level 2 proj fac's whose leading coefficients vanish in c. */ P_2 = LELTI(P,2); n = THIRD(LELTI(LAST(P_2),PO_LABEL)); A = GETARRAY(n + 1); for(i = 1; i <= n; i++) A[i] = 0; Step2: /* Set L to be the list of projection factors which vanish in c. */ M = LELTI(c,MULSUB); P_1 = LELTI(P,1); L = NIL; while(M != NIL) { ADV(M,&m,&M); j = FIRST(m); do ADV(P_1,&p,&P_1); while(j != THIRD(LELTI(p,PO_LABEL))); L = COMP(p,L); } Step3: /* Set Lp to the list of projection polynomials with factors in L. */ Lp = NIL; while(L != NIL) { ADV(L,&p,&L); for(h = LELTI(p,PO_PARENT); h != NIL; h = RED(h)) Lp = COMP(THIRD(FIRST(h)),Lp); } Step4: /* Run through the histories of each polynomial in Lp. If the polynomial is the leading coefficient of some bivariate projection factor, set A at the index for that projection factor to 1. */ while(Lp != NIL) { ADV(Lp,&p,&Lp); for(h = LELTI(p,PO_PARENT); h != NIL; h = RED(h)) { q = FIRST(h); if (FIRST(q) == PO_LCO) { l = LELTI(THIRD(q),PO_LABEL); if (SECOND(l) == 2) A[ THIRD(l) ] = 1; } } } Step5: /* Create the vector itself! */ v = NIL; while(P_2 != NIL) { ADV(P_2,&p,&P_2); j = THIRD(LELTI(p,PO_LABEL)); v = COMP(A[j],v); } v = INV(v); Return: /* Prepare to return. */ FREEARRAY(A); return v; }
void setDMSFriendlyName(JNIEnv* env,jobject jthiz,jstring jstrFriendlyName) { icstring strName = env->GetStringUTFChars(jstrFriendlyName,NULL); if(!strName) return; FREEARRAY(CESDMServer_Android::m_ServerName); CESDMServer_Android::m_ServerName = strdup(strName); env->ReleaseStringUTFChars(jstrFriendlyName,strName); return; }
CESContentDirectory_Device_Android::~CESContentDirectory_Device_Android() { FREEARRAY(m_thizUDN); CFileHandleList::iterator itbegin = m_fileHandleList.begin(); CFileHandleList::iterator itend = m_fileHandleList.end(); for (itbegin; itbegin != itend; ++itbegin) { int fn = (int)(*itbegin); if(fn!=-1) close(fn); } m_fileHandleList.clear(); //DELETE(m_pSpecialDevice); }
bool vFile::Read(void) { if(!m_fp) { return false; } if(!(m_iFlags & modeRead)) { return false; } long size = Length(); FREEARRAY(m_pDataBuf) m_pDataBuf = new unsigned char[size + 1]; memset(m_pDataBuf, NULL, size + 1); Seek(0, SEEK_SET); size_t readSize = fread(m_pDataBuf, size, 1, m_fp); if(readSize < 1) { return false; } return true; }
void vFile::Close(void) { F_FREE(m_fp); FREEARRAY(m_pDataBuf); }
Sint depthfirststree(Suffixtree *stree,Reference *startnode, Sint (*processleaf)(Uint,Bref,void *), bool (*processbranch1)(Bref,void *), Sint (*processbranch2)(Bref,void *), bool (*stoptraversal)(void *),void *stopinfo,void *info) { bool godown = true, readyforpop = false; Uint child, brotherval; Bref lcpnode = NULL; Reference currentnode; ArrayBref stack; if(startnode->toleaf) { if(processleaf((Uint) (startnode->address - stree->leaftab),NULL,info) != 0) { return -1; } return 0; } if(stoptraversal != NULL && stoptraversal(stopinfo)) { return 0; } currentnode.toleaf = false; currentnode.address = startnode->address; INITARRAY(&stack,Bref); STOREINARRAY(&stack,Bref,128,currentnode.address); SETCURRENT(GETCHILD(currentnode.address)); if(processbranch1 == NULL) { #define PROCESSBRANCH1(A,B) /* Nothing */ #define PROCESSBRANCH2(A,B) godown = true while(true) { if(stoptraversal != NULL && stoptraversal(stopinfo)) { return 0; } if(currentnode.toleaf) { /*fprintf(stderr,"visit leaf %lu ", (long unsigned int) LEAFADDR2NUM(stree,currentnode.address)); fprintf(stderr,"below %lu ",(long unsigned int) BRADDR2NUM(stree,startnode->address)); fprintf(stderr,"depth %lu\n",stree->currentdepth);*/ if(processleaf(LEAFADDR2NUM(stree,currentnode.address),lcpnode,info) != 0) { return -1; } brotherval = LEAFBROTHERVAL(*(currentnode.address)); if(NILPTR(brotherval)) { readyforpop = true; currentnode.toleaf = false; } else { SETCURRENT(brotherval); // current comes from brother lcpnode = stack.spaceBref[stack.nextfreeBref-1]; } } else { if(readyforpop) { if(stack.nextfreeBref == UintConst(1)) { break; } (stack.nextfreeBref)--; /*fprintf(stderr,"#pop[%lu]=",(long unsigned int) stack.nextfreeBref); fprintf(stderr,"%lu\n", (long unsigned int) BRADDR2NUM(stree,stack.spaceBref[stack.nextfreeBref]));*/ PROCESSBRANCH2(stack.spaceBref[stack.nextfreeBref],info); brotherval = GETBROTHER(stack.spaceBref[stack.nextfreeBref]); if(!NILPTR(brotherval)) { SETCURRENT(brotherval); // current comes from brother lcpnode = stack.spaceBref[stack.nextfreeBref-1]; readyforpop = false; } } else { /*fprintf(stderr,"#process1 %lu\n", (long unsigned int) BRADDR2NUM(stree,currentnode.address));*/ PROCESSBRANCH1(currentnode.address,info); if(godown) { STOREINARRAY(&stack,Bref,128,currentnode.address); /*fprintf(stderr,"#push[%lu]=",(long unsigned int) (stack.nextfreeBref-1)); fprintf(stderr,"%lu\n",(long unsigned int) BRADDR2NUM(stree,currentnode.address));*/ child = GETCHILD(currentnode.address); SETCURRENT(child); // current comes from child } else { brotherval = GETBROTHER(currentnode.address); if(NILPTR(brotherval)) { readyforpop = true; } else { SETCURRENT(brotherval); // current comes brother } } } } } } else { #undef PROCESSBRANCH1 #undef PROCESSBRANCH2 #define PROCESSBRANCH1(A,B) godown = processbranch1(A,B) #define PROCESSBRANCH2(A,B) if(processbranch2(A,B) != 0)\ {\ return -2;\ } while(true) { if(stoptraversal != NULL && stoptraversal(stopinfo)) { return 0; } if(currentnode.toleaf) { /*fprintf(stderr,"visit leaf %lu ", (long unsigned int) LEAFADDR2NUM(stree,currentnode.address)); fprintf(stderr,"below %lu ",(long unsigned int) BRADDR2NUM(stree,startnode->address)); fprintf(stderr,"depth %lu\n",stree->currentdepth);*/ if(processleaf(LEAFADDR2NUM(stree,currentnode.address),lcpnode,info) != 0) { return -1; } brotherval = LEAFBROTHERVAL(*(currentnode.address)); if(NILPTR(brotherval)) { readyforpop = true; currentnode.toleaf = false; } else { SETCURRENT(brotherval); // current comes from brother lcpnode = stack.spaceBref[stack.nextfreeBref-1]; } } else { if(readyforpop) { if(stack.nextfreeBref == UintConst(1)) { break; } (stack.nextfreeBref)--; /*fprintf(stderr,"#pop[%lu]=",(long unsigned int) stack.nextfreeBref); fprintf(stderr,"%lu\n", (long unsigned int) BRADDR2NUM(stree,stack.spaceBref[stack.nextfreeBref]));*/ PROCESSBRANCH2(stack.spaceBref[stack.nextfreeBref],info); brotherval = GETBROTHER(stack.spaceBref[stack.nextfreeBref]); if(!NILPTR(brotherval)) { SETCURRENT(brotherval); // current comes from brother lcpnode = stack.spaceBref[stack.nextfreeBref-1]; readyforpop = false; } } else { /*fprintf(stderr,"#process1 %lu\n", (long unsigned int) BRADDR2NUM(stree,currentnode.address));*/ PROCESSBRANCH1(currentnode.address,info); if(godown) { STOREINARRAY(&stack,Bref,128,currentnode.address); /*fprintf(stderr,"#push[%lu]=",(long unsigned int) (stack.nextfreeBref-1)); fprintf(stderr,"%lu\n",(long unsigned int) BRADDR2NUM(stree,currentnode.address));*/ child = GETCHILD(currentnode.address); SETCURRENT(child); // current comes from child } else { brotherval = GETBROTHER(currentnode.address); if(NILPTR(brotherval)) { readyforpop = true; } else { SETCURRENT(brotherval); // current comes brother } } } } } } FREEARRAY(&stack,Bref); return 0; }
Word MINPFSETNSC(Word P,Word S,Word D,Word K) { Word C,Sltr,Pltr,r,L_r,Ls_r,L,l,l_t,l_s,ls,Kp,Js,x,Jsp,s_k,sk; Word x_s,js,Ls,O,Q,Q_i,Sp,Pp,i,Cp,*V,*Vp,**A,a,N,k,S_r,I,j,p; Step1: /* Initialization. */ C = NIL; Sltr = NIL; Pltr = NIL; N = LENGTH(K); Step2: /* Loop over each level in D. */ for(r = 1; r <= N; r++) { Step3: /* Get signiture and truth value for each cell. */ L_r = CADCL(D,r); for(Ls_r = NIL; L_r != NIL; L_r = RED(L_r)) { l = FIRST(L_r); l_t = LELTI(l,TRUTH); l_s = LELTI(l,SIGNPF); for(ls = NIL; l_s != NIL; l_s = RED(l_s)) { ls = CCONC(FIRST(l_s),ls); } ls = COMP(l_t,ls); Ls_r = COMP(ls,Ls_r); } Step4: /* Get conflict cell signitures. */ Jsp = NIL; for(Kp = LELTI(K,r); Kp != NIL; Kp = RED(Kp)) { k = FIRST(FIRST(Kp)); s_k = LELTI(k,SIGNPF); for(sk = NIL; s_k != NIL; s_k = RED(s_k)) { sk = CCONC(FIRST(s_k),sk); } if (! MEMBER(sk,Jsp) ) Jsp = COMP(sk,Jsp); } for(Js = NIL; Jsp != NIL; Jsp = RED(Jsp)) { Js = COMP(COMP(CFLCT,FIRST(Jsp)),Js); } Step5: /* Put lists together, and sort with duplicate removal. */ Ls = CCONC(Js,Ls_r); Ls = GMSDSL(Ls,comp1); Step6: /* Put this all into array representation. */ a = LENGTH(Ls); k = LENGTH(FIRST(Ls)) - 1; V = (Word*)GETARRAY(a*(k + 1)); Vp = V; A = (Word**)GETARRAY(a*(sizeof(Word*)/sizeof(Word))); /* ASSUMES THIS / IS EXACT! */ for(i = 0; i < a; i++) { A[i] = V + 1; for(ADV(Ls,&ls,&Ls); ls != NIL; ls = RED(ls)) *(V++) = FIRST(ls); } Step7: /* Build S_r. */ Sltr = CCONC(Sltr,LELTI(S,r)); Pltr = CCONC(Pltr,LELTI(P,r)); Sp = CINV(Sltr); for(S_r = NIL; Sp != NIL; Sp = RED(Sp)) { i = PFPIPFL(FIRST(Sp),Pltr); S_r = COMP(i - 1,S_r); } Step8: /* Sort cell signitures on S_r, and list conflict resolving polynomials for each pair of conflicting cells in the same class. */ CSORTSS(A,a,S_r); for(i = 0;i < a; i = j) { for(j = i + 1; (j < a) && ( SIGEQUALOL(A[i],A[j],S_r));j++); Cp = ICSIGDIFFLNSC(A+i,j-i,k); C = CCONC(C,Cp); } Step9: /* Deallocate memory. */ FREEARRAY(Vp); FREEARRAY(A); } Step10:/* Get a min-hit-set */ O = MINHITSETSR(C,-1); O = LMERGE(O,S_r); O = LBIBMS(O); Q = NIL; for(r = N; r > 0; r--) Q = COMP(NIL,Q); while (O != NIL) { ADV(O,&k,&O); p = LELTI(Pltr,k+1); i = LELTI(LELTI(p,PO_LABEL),2); Q_i = SUFFIX(LELTI(Q,i),p); SLELTI(Q,i,Q_i); } Return: /* Prepare to return. */ return (Q); }
Sint procmaxmatches(MMcallinfo *mmcallinfo,Multiseq *subjectmultiseq) { Matchprocessinfo matchprocessinfo; Uint filenum, filelen; Sint retcode; Uchar *filecontent; double start, finish; /*fprintf(stderr,"# construct suffix tree for sequence of length %lu\n", (Showuint) subjectmultiseq->totallength); fprintf(stderr,"# (maximum reference length is %lu)\n", (Showuint) getmaxtextlenstree()); fprintf(stderr,"# (maximum query length is %lu)\n", (Showuint) ~((Uint)0));*/ start = omp_get_wtime(); if(constructprogressstree (&matchprocessinfo.stree, subjectmultiseq->sequence, subjectmultiseq->totallength, NULL, NULL, NULL) != 0) { return -1; } finish = omp_get_wtime(); /*fprintf(stderr,"# CONSTRUCTIONTIME %s %s %.2f\n", &mmcallinfo->program[0],&mmcallinfo->subjectfile[0], getruntime());*/ matchprocessinfo.subjectmultiseq = subjectmultiseq; matchprocessinfo.minmatchlength = mmcallinfo->minmatchlength; matchprocessinfo.showstring = mmcallinfo->showstring; matchprocessinfo.showsequencelengths = mmcallinfo->showsequencelengths; matchprocessinfo.showreversepositions = mmcallinfo->showreversepositions; matchprocessinfo.forward = mmcallinfo->forward; matchprocessinfo.fourcolumn = mmcallinfo->fourcolumn; matchprocessinfo.cmum = mmcallinfo->cmum; matchprocessinfo.cmumcand = mmcallinfo->cmumcand; matchprocessinfo.reversecomplement = mmcallinfo->reversecomplement; matchprocessinfo.chunks = mmcallinfo->chunks; if(mmcallinfo->cmum) { INITARRAY(&matchprocessinfo.mumcandtab,MUMcandidate); } retcode = getmaxdesclen(subjectmultiseq); if(retcode < 0) { return -2; } matchprocessinfo.maxdesclength = (Uint) retcode; for(filenum=0; filenum < mmcallinfo->numofqueryfiles; filenum++) { filecontent = CREATEMEMORYMAP (mmcallinfo->queryfilelist[filenum], True, &filelen); if (filecontent == NULL || filelen == 0) { ERROR2("cannot open file \"%s\" or file \"%s\" is empty", mmcallinfo->queryfilelist[filenum], mmcallinfo->queryfilelist[filenum]); return -3; } if (scanmultiplefastafile (&matchprocessinfo.querymultiseq, mmcallinfo->queryfilelist[filenum], mmcallinfo->matchnucleotidesonly ? MMREPLACEMENTCHARQUERY : 0, filecontent, filelen) != 0) { return -4; } /*fprintf(stderr, "# matching query-file \"%s\"\n# against subject-file \"%s\"\n", mmcallinfo->queryfilelist[filenum], mmcallinfo->subjectfile);*/ if (overallsequences (False, &matchprocessinfo.querymultiseq, (void *) &matchprocessinfo, findmaxmatchesonbothstrands) != 0) { return -5; } freemultiseq(&matchprocessinfo.querymultiseq); } if(mmcallinfo->cmum) { FREEARRAY(&matchprocessinfo.mumcandtab,MUMcandidate); } freestree (&matchprocessinfo.stree); fprintf(stdout,"ST=%f,",(double) (finish-start)); return 0; }
void IBPRRIOAPSF(Word M, Word I, Word B, BDigit p, BDigit k, Word *J_, Word *L_) { BDigit *Mp,*bp,*c,i,m,n,q1,q2,S,s,t; Word b,Bp,I1,I2,J,K,L,Ls,Lp,T,Jp; Step1: /* Convert the minimal polynomial to a software interval polynomial. */ n = PDEG(M); q1 = p + 3; q2 = q1 + q1; S = (n + 1) * q2 + 1; Mp = GETARRAY(S); IPSIP(M,p,Mp); Step2: /* Compute the trend of \alpha. */ b = SECOND(I); bp = GETARRAY(q1); t = LBRNFEC(b,p,bp); J = I; L = 0; if (t == 0) { FREEARRAY(bp); goto Return; } t = SIPES(Mp,bp); FREEARRAY(bp); if (t == NIL) goto Return; Step3: /* Refine the isolating interval for \alpha. */ J = SIPIR(Mp,I,t,- (p * ZETA)); FREEARRAY(Mp); Step4: /* Isolate the real roots of B(J)[Y]. */ L = NIL; m = PDEG(B); s = (m + 1) * q2 + 1; c = GETARRAY(s); IBPELBRISIPR(B,J,p,c); L = SIPRRID(c); if (L == 0) goto Step8; t = c[s - q2 + 1]; if (EVEN(m)) t = -t; Step5: /* Refine the intervals. */ if (k == NIL) goto Return; Ls = NIL; for(Lp = L; Lp != NIL; Lp = RED(Lp)) { Jp = SIPIR(c,FIRST(Lp),t,-k); Ls = COMP(Jp,Ls); t = -t; } L = CINV(Ls); Step8: /* Free arrays. */ FREEARRAY(c); Return: /* Return J and L. */ *J_ = J; *L_ = L; return; }
void CDlnaFrame::LoadAllPlugins() { struct dirent **pDirNameList = NULL; #if defined(OS_ANDROID) || defined(PLATFORM_64) int nret = scandir(m_dirName,&pDirNameList,dllFilter,(int (*)(const dirent**, const dirent**))dllComapre); #else int nret = scandir(m_dirName,&pDirNameList,dllFilter,(int (*)(const void*, const void*))dllComapre); #endif if(nret > 0) { int prefixlen = strlen(m_dirName); BOOL bNeedAppendSlash = (m_dirName[strlen(m_dirName)-1] != '/'); for (int i = 0; i < nret; i++) { char* pFullPath = NULL; if(bNeedAppendSlash) pFullPath = new char[prefixlen + 1 + strlen(pDirNameList[i]->d_name) + 1]; else pFullPath = new char[prefixlen + strlen(pDirNameList[i]->d_name) + 1]; memset(pFullPath,0,sizeof(pFullPath)); strcat(pFullPath,m_dirName); if(bNeedAppendSlash) strcat(pFullPath,"/"); strcat(pFullPath,pDirNameList[i]->d_name); void *pHandle = dlopen(pFullPath,/*RTLD_LAZY*/RTLD_NOW|RTLD_GLOBAL); if(!pHandle) { Trace( "fail to load %s\n",pDirNameList[i]->d_name); } else { CPlugIn* pPlugin = new CPlugIn; pPlugin->pHandle = pHandle; if(LoadAllFunctions(pPlugin) != 0) { Trace( "fail to load functions from %s\n",pDirNameList[i]->d_name); DELETE(pPlugin); } else { Trace( "succeed to load %s\n",pDirNameList[i]->d_name); pPlugin->pName = strdup(pDirNameList[i]->d_name); m_ListPlugin.push_back(pPlugin); } } FREE(pDirNameList[i]); DELETEARRAY(pFullPath); } FREEARRAY(pDirNameList); } else Trace("fail to load plugin from %s\n",m_dirName); }