bridge/class-master/depend/pari/src/basemath/ifactor1.c
/* Move to a larger main vector, updating *where if it points into it, and
 * *partial in any case. Can be used as a specialized gcopy before
 * a gerepileupto() (pass 0 as the new length). Normally, one would pass
 * new_lg=1 to let this function guess the new size.  To be used sparingly.
 * Complex version of ifac_defrag(), combined with reallocation.  If new_lg
 * is 0, use the old length, so this acts just like gcopy except that the
 * 'where' pointer is carried along; if it is 1, we make an educated guess.
 * Exception:  If new_lg is 0, the vector is full to the brim, and the first
 * entry is composite, we make it longer to avoid being called again a
 * microsecond later. It is safe to call this with *where = NULL:
 * if it doesn't point anywhere within the old structure, it is left alone */
Move to a larger main vector, updating *where if it points into it, and
*partial in any case. Can be used as a specialized gcopy before
a gerepileupto() (pass 0 as the new length). Normally, one would pass
new_lg=1 to let this function guess the new size.  To be used sparingly.
Complex version of ifac_defrag(), combined with reallocation.  If new_lg
is 0, use the old length, so this acts just like gcopy except that the
'where' pointer is carried along; if it is 1, we make an educated guess.
Exception:  If new_lg is 0, the vector is full to the brim, and the first
entry is composite, we make it longer to avoid being called again a
microsecond later. It is safe to call this with *where = NULL:
if it doesn't point anywhere within the old structure, it is left alone
Move to a larger main vector updating * where if it points into it and * partial in any case . Can be used as a specialized gcopy before a gerepileupto () ( pass 0 as the new length ) . Normally one would pass new_lg = 1 to let this function guess the new size . To be used sparingly . Complex version of ifac_defrag () combined with reallocation . If new_lg is 0 use the old length so this acts just like gcopy except that the ' where ' pointer is carried along ; if it is 1 we make an educated guess . Exception : If new_lg is 0 the vector is full to the brim and the first entry is composite we make it longer to avoid being called again a microsecond later . It is safe to call this with * where = NULL : if it doesn ' t point anywhere within the old structure it is left alone
static void
ifac_realloc(GEN *partial, GEN *where, long new_lg)
{
  long old_lg = lg(*partial);
  GEN newpart, scan_new, scan_old;
  if (new_lg == 1)
    new_lg = 2*old_lg - 6;        
  else if (new_lg <= old_lg)        
  {
    GEN first = *partial + 3;
    new_lg = old_lg;
    if (VALUE(first) && (CLASS(first) == gen_0 || CLASS(first)==NULL))
      new_lg += 6; 
  }
  newpart = cgetg(new_lg, t_VEC);
  if (DEBUGMEM >= 3)
    err_printf("IFAC: new partial factorization structure (%ld slots)\n",
               (new_lg - 3)/3);
  MOEBIUS(newpart) = MOEBIUS(*partial);
  icopyifstack(HINT(*partial), HINT(newpart));
  scan_new = newpart + new_lg - 3; 
  scan_old = *partial + old_lg - 3; 
  for (; scan_old > *partial + 2; scan_old -= 3)
  {
    if (*where == scan_old) *where = scan_new;
    if (!VALUE(scan_old)) continue; 
    COPY(scan_old, scan_new); scan_new -= 3;
  }
  scan_new += 3; 
  while ((scan_new -= 3) > newpart) ifac_delete(scan_new);
  *partial = newpart;
}
static void ifac_realloc ( GEN * partial , GEN * where , long new_lg ) { long old_lg = lg ( * partial ) ; GEN newpart , scan_new , scan_old ; if ( new_lg == 1 ) new_lg = 2 * old_lg - 6 ; else if ( new_lg <= old_lg ) { GEN first = * partial + 3 ; new_lg = old_lg ; if ( VALUE ( first ) && ( CLASS ( first ) == gen_0 || CLASS ( first ) == NULL ) ) new_lg += 6 ; } newpart = cgetg ( new_lg , t_VEC ) ; if ( DEBUGMEM >= 3 ) err_printf ( " \n " , ( new_lg - 3 ) / 3 ) ; MOEBIUS ( newpart ) = MOEBIUS ( * partial ) ; icopyifstack ( HINT ( * partial ) , HINT ( newpart ) ) ; scan_new = newpart + new_lg - 3 ; scan_old = * partial + old_lg - 3 ; for ( ; scan_old > * partial + 2 ; scan_old -= 3 ) { if ( * where == scan_old ) * where = scan_new ; if ( ! VALUE ( scan_old ) ) continue ; COPY ( scan_old , scan_new ) ; scan_new -= 3 ; } scan_new += 3 ; while ( ( scan_new -= 3 ) > newpart ) ifac_delete ( scan_new ) ; * partial = newpart ; }
Move to a larger main vector, updating *where if it points into it, and
 *partial in any case.
Move to a larger main vector updating * where if it points into it and * partial in any case .
/* from 7 slots to 13 to 25... */ /* includes case new_lg == 0 */ /* structure full and first entry composite or unknown */ /* give it a little more breathing space */ /* Downward sweep through the old *partial. Pick up 'where' and carry it
   * over if we pass it. (Only useful if it pointed at a non-empty slot.)
   * Factors are COPY'd so that we again have a nice object (parent older
   * than children, connected), except the one factor that may still be living
   * in a clone where n originally was; exponents are similarly copied if they
   * aren't global constants; class-of-factor fields are global constants so we
   * need only copy them as pointers. Caller may then do a gerepileupto() */ /* LAST(newpart) */ /* LAST(*partial) */ /* skip empty slots */ /* back up to last slot written */