コード例 #1
0
ファイル: int_affine.c プロジェクト: davidad/rala_util
int affine_restore(affine_stack_t **p) {
	if((*p)->prev == NULL) {
		return 1;
	}
	affine_stack_t *old = *p;
	*p = (*p)->prev;
	free_pars(old);
	free(old);
	return 0;
}
コード例 #2
0
ファイル: int_affine.c プロジェクト: davidad/rala_util
void affine_start_split(affine_stack_t **p) {
	if((*p)->trivial_par) {
		free_pars(*p);
		(*p)->par_next = malloc(sizeof(affine_par_t));
		init_par((*p)->par_next);
		(*p)->par_cur = (*p)->par_next;
		(*p)->trivial_par =false;
	} else {
		affine_par_t** par_iter = &((*p)->par_next);
		while((*par_iter)!=NULL) par_iter=&((*par_iter)->par_next);
		(*par_iter) = malloc(sizeof(affine_par_t));
		(*p)->par_cur = (*par_iter);
		init_par(*par_iter);
		if((*p)->prev == NULL || (*p)->prev->par_next == NULL) {
			(*par_iter)->cur = (*p)->cur;
		}
	}
}
コード例 #3
0
ファイル: stream.c プロジェクト: BioDAG/align-paths
mclx* mclxIOstreamIn
(  mcxIO*   xf
,  mcxbits  bits
,  mclpAR*  transform
,  void    (*ivpmerge)(void* ivp1, const void* ivp2)
,  mclxIOstreamer* streamer
,  mcxOnFail ON_FAIL
)
   {  mcxstatus status  =  STATUS_FAIL
   ;  const char* me    =  module

   ;  mcxbool symmetric =  bits & MCLXIO_STREAM_SYMMETRIC
   ;  mcxbool mirror    =  bits & MCLXIO_STREAM_MIRROR

   ;  mcxbool abc       =  bits & MCLXIO_STREAM_ABC    ? TRUE : FALSE
   ;  mcxbool one23     =  bits & MCLXIO_STREAM_123    ? TRUE : FALSE
   ;  mcxbool etc       =  bits & (MCLXIO_STREAM_ETC | MCLXIO_STREAM_ETC_AI) ? TRUE : FALSE

   ;  mcxbool longlist  =  bits & (MCLXIO_STREAM_ETCANY | MCLXIO_STREAM_235ANY) ? TRUE : FALSE

   ;  mcxTing* linebuf  =  mcxTingEmpty(NULL, 100)

   ;  map_state  map_c  =  { NULL, NULL, -1 , 0}
   ;  map_state  map_r  =  { NULL, NULL, -1 , 0}

   ;  stream_state   iface
   ;  etc_state      etcstate

   ;  unsigned long n_ite = 0
   ;  mclx* mx = NULL

   ;  if (!ivpmerge)
      ivpmerge = mclpMergeMax

   ;  if (symmetric)
         iface.map_c = &map_c    /* this bit of hidgery-pokery       */
      ,  iface.map_r = &map_c    /* is a crucial interfacummathingy  */
   ;  else
         iface.map_c = &map_c
      ,  iface.map_r = &map_r

;if(DEBUG2)fprintf(stderr, "%s abc\n", abc ? "yes" : "no")
   ;  etcstate.etcbuf = NULL
   ;  etcstate.etcbuf_ofs = 0
   ;  etcstate.etcbuf_check = 0
   ;  etcstate.x_prev   =  ULONG_MAX      /* note we depend on ULONG_MAX + 1 == 0 */
   ;  etcstate.n_y   =  0

         /* fixme incomplete and distributed initialization of iface */
   ;  iface.pars = NULL
   ;  iface.pars_n_alloc = 0
   ;  iface.pars_n_used = 0

;if(DEBUG3)fprintf(stderr, "1 + max c %lu\n", (ulong) (iface.map_c->max_seen+1))
                                 /* fixme: put the block below in a subroutine */
   ;  while (1)
      {  if (abc + one23 + longlist > TRUE)   /* OUCH */
         {  mcxErr(module, "multiple stream formats specified")
         ;  break
      ;  }
         if (!symmetric && streamer->tab_sym_in)
         {  mcxErr(module, "for now disallowed, single tab, different domains")
         ;  break
      ;  }
         if ((!one23 && !abc && !longlist))
         {  mcxErr(module, "not enough to get going")
         ;  break
      ;  }

                              /* These have maps associated with them.
                               * Note that bitsp may be changed (by filling in
                               * somewhat underspecified settings).
                               * todo hierverder: etc case supported below ?
                              */
         if (abc || etc)
         stream_state_set_map(symmetric, &iface, streamer, &bits)

      ;  if (xf->fp == NULL && (mcxIOopen(xf, ON_FAIL) != STATUS_OK))
         {  mcxErr(me, "cannot open stream <%s>", xf->fn->str)
         ;  break
      ;  }
         status = STATUS_OK
      ;  break
   ;  }

      iface.bits  =  bits

   ;  if (!status)
      while (1)
      {  unsigned long x = 876543210, y = 876543210
      ;  double value = 0
      ;  n_ite++

      ;  iface.x =  0
      ;  iface.y =  0

      ;  if (n_ite % 20000 == 0)
         fputc('.', stderr)               /* fixme conditional to sth */
      ;  if (n_ite % 1000000 == 0)
         fprintf(stderr, " %ldM\n", (long) (n_ite / 1000000))

                        /* 
                         * -  the read routines largely manage iface, including
                         * map_c->max_seen and map_r->max_seen.  It would be
                         * nice to encapsulate that management in a single
                         * place. Note the read_abc requirement that sometimes
                         * a label may need to be deleted from a hash. The fact
                         * that handle_label (called by read_etc and read_abc)
                         * also manages max_seen complicate encapsulation though.
                         *
                         * -  read_etc manages its line buffer.
                        */
      ;  status
         =     one23 ?     read_123(xf, linebuf, &iface, streamer, &value, bits)
            :  abc   ?     read_abc(xf, linebuf, &iface, &value)
            :  longlist ?  read_etc(xf, &iface, &etcstate, &value)
            :  STATUS_FAIL

      ;  x = iface.x
      ;  y = iface.y

                        /* considerme: etc status ignore could still expand column range.
                         * do we change the status and deal with not incorporating the row,
                         * or do we keep status, and change realloc/ignore logic below?
                        */
;if(0)fprintf(stderr, "#x now %lu status %s\n", (ulong) (iface.map_c->max_seen+1), MCXSTATUS(status))
                        /* etc/235 are special in that with NEW x and IGNORE y
                         * we respect x
                         * fixme: should not do that for auto-increment
                        */
      ;  if (status == STATUS_IGNORE)     /* maybe restrict mode */
         {  if
            (  longlist
            && iface.statusx == STATUS_NEW
            && iface.map_c->max_seen+1 > iface.pars_n_used    /* note mixed-sign comparison */
            )
            {  if ((status = pars_realloc(&iface, iface.map_c->max_seen+1)))
               break
         ;  }
            continue
      ;  }
         else if (status)                 /* FAIL or DONE */
         break

      ;  if
         (  iface.map_c->max_seen >= iface.pars_n_used     /* note mixed-sign comparison */
         && (status = pars_realloc(&iface, iface.map_c->max_seen+1))
         )
         break

      ;  status = STATUS_FAIL    /* fixme restructure logic, mid-re-initialization is ugly */

      ;  if
         ( bits & (MCLXIO_STREAM_LOGTRANSFORM | MCLXIO_STREAM_NEGLOGTRANSFORM) )
         {  if (bits & MCLXIO_STREAM_LOGTRANSFORM)
            value = value > 0 ? log(value) : -PVAL_MAX
         ;  else if (bits & MCLXIO_STREAM_NEGLOGTRANSFORM)
            value = value > 0 ? -log(value) : PVAL_MAX
         ;  if (bits & MCLXIO_STREAM_LOG10)
            value /= log(10)
      ;  }

         if (transform)
         {  mclp bufivp
         ;  bufivp.idx = 0
         ;  bufivp.val = value
         ;  value = mclpUnary(&bufivp, transform)
      ;  }

                                 /* fixme: below we have canonical dependence, index as offset */
         if (value)
         {  if(DEBUG3)fprintf(stderr, "attempt to extend %d\n", (int) x)
         ;  if (mclpARextend(iface.pars+x, y, value))
            {  mcxErr(me, "x-extend fails")
            ;  break
         ;  }
            if (mirror && mclpARextend(iface.pars+y, x, value))
            {  mcxErr(me, "y-extend fails")
            ;  break
         ;  }
         }
         status = STATUS_OK
   ;  }

      if (n_ite >= 1000000 && n_ite % 5000000)
      fputc('\n', stderr)

   ;  mcxTingFree(&(etcstate.etcbuf))

   ;  if (status == STATUS_FAIL || ferror(xf->fp))
      mcxErr(me, "error occurred (status %d lc %d)", (int) status, (int) xf->lc)
   ;  else
      {  mx = make_mx_from_pars(streamer, &iface, ivpmerge, bits)
      ;  status = mx ? STATUS_OK : STATUS_FAIL
   ;  }

      mcxTingFree(&linebuf)
   ;  free_pars(&iface)

   ;  if (status == STATUS_FAIL)
      {  if (ON_FAIL == EXIT_ON_FAIL)
         mcxDie(1, me, "fini")
   ;  }

               /* with 123, etcai there is simply no column tab
                * todo: perhaps create a dummy one (integers).
               */
      if
      (  !status
      && (abc || (bits & (MCLXIO_STREAM_ETC | MCLXIO_STREAM_ETC_AI)))
      )
      {  if (symmetric)
         streamer->tab_sym_out = make_tab(iface.map_c)
      ;  else
         {  if (!(bits & MCLXIO_STREAM_ETC_AI))
            streamer->tab_col_out = make_tab(iface.map_c)
;if(0)fprintf(stderr, "%p x %p\n", (void*) iface.map_c->map, (void*) iface.map_c->tab)
;if(0)mcxHashStats(stdout, iface.map_c->map)
         ;  streamer->tab_row_out = make_tab(iface.map_r)
      ;  }
      }

      mcxHashFree(&(iface.map_c->map), mcxTingRelease, NULL)
   ;  if (!symmetric)
      mcxHashFree(&(iface.map_r->map), mcxTingRelease, NULL)

   ;  return mx
;  }