[med-svn] [sprai] 02/12: Imported Upstream version 0.9.9.13+dfsg

Afif Elghraoui afif at moszumanska.debian.org
Fri Apr 15 08:34:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

afif pushed a commit to branch master
in repository sprai.

commit 4f43fceb8bd169433e70df4900410f9870b496c4
Author: Afif Elghraoui <afif at ghraoui.name>
Date:   Thu Apr 14 00:28:25 2016 -0700

    Imported Upstream version 0.9.9.13+dfsg
---
 makefile      |   2 +-
 myrealigner.c | 291 ++++++++++++++++++++++++++++++++++------------------------
 wscript       |   2 +-
 3 files changed, 174 insertions(+), 121 deletions(-)

diff --git a/makefile b/makefile
index f6a175b..b1ca723 100644
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
 APPNAME = 'sprai'
-VERSION = '0.9.9.12'
+VERSION = '0.9.9.13'
 
 PREFIX=$(PWD)
 COMPILED= \
diff --git a/myrealigner.c b/myrealigner.c
index 88622a9..4512855 100644
--- a/myrealigner.c
+++ b/myrealigner.c
@@ -11,7 +11,6 @@ int BandSize = 8;
 int minimum_ballots = 3;
 int maximum_ballots = 11;
 
-
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -66,6 +65,101 @@ typedef struct fragEl{
   struct fragEl *down;
 }fragEl;
 
+typedef struct ElPool{
+  struct ElPool * ext;
+  struct fragEl * Elements;
+  size_t count;
+  size_t size;
+}ElPool;
+
+void* 
+malloc_or_die(size_t size, const char* message)
+{
+  void *pval;
+  pval = malloc(size); 
+  if(pval == NULL){ 
+    fputs("Fatal error!\n", stderr);
+    fputs("cannot allocate memory: ", stderr);
+    fputs(message, stderr);
+    fputs("\n", stderr);
+    exit(1); 
+  } 
+  return pval;
+}
+void* 
+realloc_or_die(void*buf, size_t size, const char* message)
+{
+  void *pval;
+  pval = realloc(buf, size); 
+  if(pval == NULL){ 
+    fputs("Fatal error!\n", stderr);
+    fputs("cannot reallocate memory: ", stderr);
+    fputs(message, stderr);
+    fputs("\n", stderr);
+    exit(1); 
+  } 
+  return pval;
+}
+
+ElPool*
+init_ElPool(ElPool* elpool, size_t size)
+{
+  fragEl* FreeElList = NULL;
+  elpool->ext = NULL;
+  elpool->count = 0;
+  elpool->size = size;
+  FreeElList = (fragEl *) malloc_or_die(sizeof(fragEl)*size, "FreeElList");
+  elpool->Elements = FreeElList;
+  return elpool;
+}
+fragEl *
+getEl(ElPool* pool){
+  size_t el_index;
+  if(pool->count >= pool->size){
+    if(pool->ext == NULL){
+      pool->ext = malloc_or_die(sizeof(ElPool),"el_pool_expand");
+      init_ElPool(pool->ext, pool->size * 1.4);
+    }
+    return getEl(pool->ext);
+  }
+  if(pool->Elements == NULL){
+    fprintf(stderr, "pool->Elements is NULL\n");
+    abort();
+  }
+  el_index = pool->count;
+  pool->Elements[el_index].el.base = -1;
+  pool->Elements[el_index].el.qv = ' ';
+  pool->Elements[el_index].prev = NULL;
+  pool->Elements[el_index].next = NULL;
+  pool->Elements[el_index].up = NULL;
+  pool->Elements[el_index].down = NULL;
+  return &pool->Elements[pool->count++];
+}
+
+size_t
+freeElPool(ElPool* pool)
+{
+  size_t ext_size;
+  if(pool == NULL)
+    return 0;
+  free(pool->Elements);
+  ext_size = freeElPool(pool->ext);
+  ext_size += pool->size ;
+  return ext_size;
+}
+void
+flushElPool(ElPool*pool)
+{
+  size_t ext_size;
+  ext_size = freeElPool(pool->ext);
+  pool->ext = NULL;
+  if(ext_size){
+    pool->size += ext_size;
+    pool->Elements = realloc_or_die(pool->Elements, sizeof(fragEl)*pool->size, "expanding element pool");
+  }
+  pool->count = 0;
+}
+
 typedef struct colStruc{
   int colInf[6];// Information, not Infimum // colInf[.] <- the number of '.'
   int  colDepth;
@@ -92,110 +186,77 @@ frag    *Frags;// reads
 colStruc  *FirstCol;
 colStruc  *LastCol;
 
-fragEl    *FreeElList=NULL;
-unsigned long long el_index=0ull;
-unsigned long long elsize;
-
-fragEl *getEl(){
-  if(el_index >= elsize){
-    fprintf(stderr,"never come here (getEl() in myrealigner)\n");
-    exit(1);
-    fprintf(stderr, "no el is left\n");
-    fprintf(stderr,"reallocate: el\n");
-    // realloc
-    unsigned long long tmpsize = elsize * 2ull;
-    if(tmpsize > elsize){
-      elsize = tmpsize;
-    }
-    else{
-      fprintf(stderr, "elsize overflow\n");
-      abort();
-    }
-    fragEl * tmp = (fragEl*)malloc(sizeof(fragEl)*elsize);
-    if(tmp == NULL){
-      fprintf(stderr, "cannot REallocate memory: fragEl\n");
-      abort();
-    }
-    else{
-      FreeElList = tmp;
-    }
-  }
-  if(&FreeElList[el_index] == NULL){
-    fprintf(stderr, "FreeElList is NULL\n");
-    abort();
-  }
-  FreeElList[el_index].el.base = -1;
-  FreeElList[el_index].el.qv = ' ';
-  FreeElList[el_index].prev = NULL;
-  FreeElList[el_index].next = NULL;
-  FreeElList[el_index].up = NULL;
-  FreeElList[el_index].down = NULL;
-  return &FreeElList[el_index++];
-}
+typedef struct colPool{
+  struct colPool *ext;
+  colStruc *Cols;
+  int count;
+  size_t size;
+}colPool;
 
-int freeEl(fragEl * ptr){
-  ptr->next = FreeElList;
-  FreeElList = ptr;
-  return 0;
+colPool*
+init_colPool(colPool* pool, size_t size)
+{
+  pool->ext = NULL;
+  pool->count = 0;
+  pool->size = size;
+  pool->Cols = (colStruc *) malloc_or_die(sizeof(colStruc)*size, "init_colPool");
+  return pool;
 }
 
-colStruc *FreeColList=NULL;
-int col_index=0;
-unsigned long long colsize;
-
-colStruc *getCol(){
-  if(col_index >= colsize){
+colStruc *getCol(colPool*pool){
+  colStruc *acol = NULL;
+  if(pool->count >= pool->size){
     fprintf(stderr,"never come here (getCol() in myrealigner)\n");
     exit(1);
-    fprintf(stderr,"no col is left\n");
-    // realloc
-    fprintf(stderr,"reallocate: col\n");
-    unsigned long long tmpsize = colsize * 2ull;
-    if(tmpsize > colsize){
-      colsize = tmpsize;
-    }
-    else{
-      fprintf(stderr, "colsize overflow\n");
-      abort();
-    }
-    colStruc * tmp = (colStruc*)malloc(sizeof(colStruc)*colsize);
-    if(tmp == NULL){
-      fprintf(stderr, "cannot REallocate memory: colStruc\n");
-      abort();
-    }
-    else{
-      FreeColList = tmp;
-    }
   }
   int i;
-  if(&FreeColList[col_index] == NULL){
+  if(pool == NULL){
     fprintf(stderr, "FreeColList is NULL\n");
     abort();
   }
+  acol = pool->Cols+pool->count;
   for (i=0; i < 6; ++i)
-    FreeColList[col_index].colInf[i] = 0;
-  FreeColList[col_index].colDepth = 0;
-  FreeColList[col_index].preCalc[5] = 0.0;
-  FreeColList[col_index].next = NULL;
-  FreeColList[col_index].prev = NULL;
-  FreeColList[col_index].frags.up = &(FreeColList[col_index].frags);
-  FreeColList[col_index].frags.down = &(FreeColList[col_index].frags);
-  FreeColList[col_index].frags.prev = (fragEl*) &(FreeColList[col_index]);
-  return &(FreeColList[col_index++]);
+    acol->colInf[i] = 0;
+  acol->colDepth = 0;
+  acol->preCalc[5] = 0.0;
+  acol->next = NULL;
+  acol->prev = NULL;
+  acol->frags.up = &(acol->frags);
+  acol->frags.down = &(acol->frags);
+  acol->frags.prev = (fragEl*) &(acol);
+  return &(pool->Cols[pool->count++]);
 }
-
-int freeCol(colStruc * ptr){
-  ptr->next = FreeColList;
-  FreeColList = ptr;
-  return 0;
+size_t
+freeColPool(colPool* pool)
+{
+  size_t ext_size;
+  if(pool == NULL)
+    return 0;
+  free(pool->Cols);
+  ext_size = freeColPool(pool->ext);
+  ext_size += pool->size ;
+  return ext_size;
+}
+void
+flushColPool(colPool*pool)
+{
+  size_t ext_size;
+  ext_size = freeColPool(pool->ext);
+  pool->ext = NULL;
+  if(ext_size){
+    pool->size += ext_size;
+    pool->Cols = realloc_or_die(pool->Cols, sizeof(fragEl)*pool->size, "expanding element pool");
+  }
+  pool->count = 0;
 }
 
+
 int encode[128];
 int * row;
 int maxNumFrags=-1;
 FILE * input;
 
-int readFrags(){
+int readFrags(ElPool*elpool,colPool*colpool){
   char *s;
   int  i, r, numFrags;
   colStruc  *curCol;
@@ -205,7 +266,7 @@ int readFrags(){
     row[i] = -1;
   //buffer[BUFSIZE-1] = '\0';
   numFrags = 0;
-  elPtr = telPtr = getEl();
+  elPtr = telPtr = getEl(elpool);
   elPtr->el.base = -1;
   elPtr->el.qv = ' ';
   for(i=1; i < BandSize; ++i){
@@ -217,13 +278,13 @@ int readFrags(){
     //          p                    p  
     //          t                    t  
     //          r                    r  
-    elPtr->next = getEl();
+    elPtr->next = getEl(elpool);
     elPtr = elPtr->next;
     elPtr->el.base = -1;
     elPtr->el.qv = ' ';
   }
 
-  FirstCol = curCol = getCol();
+  FirstCol = curCol = getCol(colpool);
 
   Rows = -1;
   while((s=fgets(sbuf, 2*MaxFragSize-1, input)) != NULL){
@@ -318,7 +379,7 @@ int readFrags(){
     }
 
     r = 0;
-    curCol->next = getCol();
+    curCol->next = getCol(colpool);
     curCol->next->prev = curCol;
     curCol = curCol->next;
     int j;
@@ -347,7 +408,7 @@ int readFrags(){
             }
           }
           Frags[numFrags].len = 0;
-          elPtr = getEl();
+          elPtr = getEl(elpool);
           for(i=0; i < BandSize; ++i){
             // e1e2e3... -> --------e1e2e3...
             //              bandsize  b a n d s i z e
@@ -358,7 +419,7 @@ int readFrags(){
             // in the loop 'for (j=0, tptr=ptr=pf->ofrag; j < BandSize; ++j)...' in reAlign
             elPtr->el.base = -1;
             elPtr->el.qv = ' ';
-            elPtr->next = getEl();
+            elPtr->next = getEl(elpool);
             elPtr->next->prev = elPtr;
             elPtr = elPtr->next;
           }
@@ -383,7 +444,7 @@ int readFrags(){
         elPtr->down = curCol->frags.down;
         curCol->frags.down = elPtr;
         elPtr->down->up = elPtr;
-        elPtr->next = Frags[row[r]].lastEl = getEl();
+        elPtr->next = Frags[row[r]].lastEl = getEl(elpool);
         Frags[row[r]].lastEl->prev = elPtr;
         if(i != 0){// not '-'
           Frags[row[r]].afrag[Frags[row[r]].len].base = buffer[j];
@@ -426,7 +487,7 @@ int readFrags(){
   }
   if(s == NULL)
     DoneFlag = 1;
-  curCol->next = LastCol = getCol();
+  curCol->next = LastCol = getCol(colpool);
   LastCol->prev = curCol;
   ++Rows;
   if(Rows>=MaxDepth*2){
@@ -665,7 +726,7 @@ int  *shift;
 
 /* reAlign realigns the fnum fragment against the alignment of the rest of the fragments */
 // fnum: fragment number = id of the fragment (given in readFrags)
-int reAlign (int fnum){
+int reAlign (int fnum, ElPool*elpool,colPool*colpool){
   int  i, j, m, n;
   char    *cptr;
   base_t * fel;
@@ -695,7 +756,7 @@ int reAlign (int fnum){
   // set start column
   for(n=0; n < BandSize; ++n){// go back to the n previous colum
     if(mstart == FirstCol){// if you reach FirstColumn, then add a new FirstCol
-      FirstCol = mstart->prev = getCol();
+      FirstCol = mstart->prev = getCol(colpool);
       FirstCol->next = mstart;
     }
     mstart = mstart->prev;
@@ -899,7 +960,7 @@ int reAlign (int fnum){
       --j;
     }
     else{
-      tcol = getCol();
+      tcol = getCol(colpool);
       tcol->prev = col;
       tcol->next = col->next;
       col->next->prev = tcol;
@@ -917,7 +978,7 @@ int reAlign (int fnum){
         if(fptr->next->el.base != -1){
           ++(tcol->colDepth);
           ++(tcol->colInf[0]);
-          tptr = getEl();
+          tptr = getEl(elpool);
           tptr->prev = fptr;
           tptr->next = fptr->next;
           tptr->next->prev = tptr;
@@ -935,7 +996,7 @@ int reAlign (int fnum){
       --i;
     }
     if(ptr == pf->ofrag && i > 0){
-      pf->ofrag = getEl();
+      pf->ofrag = getEl(elpool);
       pf->ofrag->prev = ptr->prev;
       ptr->prev->next = pf->ofrag;
       ptr->prev = pf->ofrag;
@@ -981,6 +1042,8 @@ void useErr(char *name)
 }
 
 int main(int argc, char **argv){
+  ElPool elpool;
+  colPool colpool;
   int hitnum=0;
   {
     int r;
@@ -1184,20 +1247,10 @@ int main(int argc, char **argv){
   }
   {
     unsigned long long MaxIns = 31;
-    elsize = (unsigned long long)(MaxFragSize*(1+MaxIns));
-    elsize *= (unsigned long long)(MaxDepth/FoS);
-
-    colsize = (unsigned long long)(MaxFragSize*(1+MaxIns));
-  }
-  FreeElList = (fragEl *) malloc(sizeof(fragEl)*elsize);
-  if(FreeElList == NULL){
-    fprintf(stderr, "cannot allocate memory: FreeElList\n");
-    abort();
-  }
-  FreeColList = (colStruc *) malloc(sizeof(colStruc)*colsize);
-  if(FreeColList == NULL){
-    fprintf(stderr, "cannot allocate memory: FreeColList\n");
-    abort();
+    init_ElPool(&elpool, MaxFragSize); /* should be insufficient and trigger espansion at some point*/
+    size_t colsize = (unsigned long long)(MaxFragSize*(1+MaxIns));
+    colsize = 100000; /* should be insufficient and trigger espansion at some point*/
+    init_colPool(&colpool,colsize);
   }
 
   for (i = 0; i < 128; i++){
@@ -1212,7 +1265,7 @@ int main(int argc, char **argv){
 
   while(!DoneFlag){
     buf4printComment[0] = '\0';
-    numFrags = readFrags();
+    numFrags = readFrags(&elpool, &colpool);
     if(numFrags == 0){
       if(!DoneFlag)
         fprintf(stderr, "no frag\n");
@@ -1223,10 +1276,10 @@ int main(int argc, char **argv){
     maxNumFrags = (numFrags > maxNumFrags) ? numFrags : maxNumFrags;
 
     /* tack 2 blank columns on end of alignment to allow movement */
-    LastCol->next = getCol();
+    LastCol->next = getCol(&colpool);
     LastCol->next->prev = LastCol;
     LastCol = LastCol->next;
-    LastCol->next = getCol();
+    LastCol->next = getCol(&colpool);
     LastCol->next->prev = LastCol;
     LastCol = LastCol->next;
 
@@ -1249,7 +1302,7 @@ int main(int argc, char **argv){
         oldScore = score;
         ++flag;
         for(i=0; i < numFrags; i++){
-          reAlign(i);// reAlign each read
+          reAlign(i, &elpool, &colpool);// reAlign each read
         }
 
         // calculate the score again
@@ -1292,8 +1345,8 @@ int main(int argc, char **argv){
     NumIts += flag;
     ++NumCons;
 
-    el_index=0;
-    col_index=0;
+    flushElPool(&elpool);
+    flushColPool(&colpool);
   }
 
   free(bmat);
diff --git a/wscript b/wscript
index 50f098c..bdf8f74 100644
--- a/wscript
+++ b/wscript
@@ -1,5 +1,5 @@
 APPNAME = 'sprai'
-VERSION = '0.9.9.12'
+VERSION = '0.9.9.13'
 
 srcdir = '.'
 blddir = 'build'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/sprai.git



More information about the debian-med-commit mailing list