bridge/class-master/depend/pari/src/basemath/ifactor1.c
/* Re-sort one (typically unknown) entry from washere to a new position,
 * rotating intervening entries upward to fill the vacant space. If the new
 * position is the same as the old one, or the new value of the entry coincides
 * with a value already occupying a lower slot, then we just add exponents (and
 * use the 'more known' class, and return 1 immediately when in Moebius mode).
 * Slots between *where and washere must be in sorted order, so a sweep using
 * this to re-sort several unknowns must proceed upward, see ifac_resort().
 * Bubble-sort-of-thing sort. Won't be exercised frequently, so this is ok */
Re-sort one (typically unknown) entry from washere to a new position,
rotating intervening entries upward to fill the vacant space. If the new
position is the same as the old one, or the new value of the entry coincides
with a value already occupying a lower slot, then we just add exponents (and
use the 'more known' class, and return 1 immediately when in Moebius mode).
Slots between *where and washere must be in sorted order, so a sweep using
this to re-sort several unknowns must proceed upward, see ifac_resort().
Bubble-sort-of-thing sort. Won't be exercised frequently, so this is ok
Re - sort one ( typically unknown ) entry from washere to a new position rotating intervening entries upward to fill the vacant space . If the new position is the same as the old one or the new value of the entry coincides with a value already occupying a lower slot then we just add exponents ( and use the ' more known ' class and return 1 immediately when in Moebius mode ) . Slots between * where and washere must be in sorted order so a sweep using this to re - sort several unknowns must proceed upward see ifac_resort () . Bubble - sort - of - thing sort . Won ' t be exercised frequently so this is ok
static void
ifac_sort_one(GEN *where, GEN washere)
{
  GEN old, scan = washere - 3;
  GEN value, exponent, class0, class1;
  long cmp_res;
  if (scan < *where) return; 
  value    = VALUE(washere);
  exponent = EXPON(washere);
  class0 = CLASS(washere);
  cmp_res = -1; 
  while (scan >= *where) 
  {
    if (VALUE(scan))
    { 
      cmp_res = cmpii(value, VALUE(scan));
      if (cmp_res >= 0) break; 
    }
    SHALLOWCOPY(scan, scan+3);
    scan -= 3;
  }
  scan += 3;
  if (cmp_res)
  {
    if (cmp_res < 0 && scan != *where)
      pari_err_BUG("ifact_sort_one [misaligned partial]");
    INIT(scan, value, exponent, class0); return;
  }
  if (DEBUGLEVEL >= 4)
    err_printf("IFAC: repeated factor %Ps\n\tin ifac_sort_one\n", value);
  old = scan - 3;
  class1 = CLASS(old);
  if (class0) 
  {
    if (class1)
    {
      if (class0 == gen_0 && class1 != gen_0)
        pari_err_BUG("ifac_sort_one (composite = prime)");
      else if (class0 != gen_0 && class1 == gen_0)
        pari_err_BUG("ifac_sort_one (prime = composite)");
      else if (class0 == gen_2)
        CLASS(scan) = class0;
    }
    else
      CLASS(scan) = class0;
  }
  CLASS(scan) = class1;
  if (EXPON(old) == gen_1 && exponent == gen_1)
    EXPON(scan) = gen_2;
  else
    EXPON(scan) = addii(EXPON(old), exponent);
  old = scan - 3;
  *scan = *old;
  ifac_delete(old);
  if (old == *where) *where += 3;
}
static void ifac_sort_one ( GEN * where , GEN washere ) { GEN old , scan = washere - 3 ; GEN value , exponent , class0 , class1 ; long cmp_res ; if ( scan < * where ) return ; value = VALUE ( washere ) ; exponent = EXPON ( washere ) ; class0 = CLASS ( washere ) ; cmp_res = -1 ; while ( scan >= * where ) { if ( VALUE ( scan ) ) { cmp_res = cmpii ( value , VALUE ( scan ) ) ; if ( cmp_res >= 0 ) break ; } SHALLOWCOPY ( scan , scan + 3 ) ; scan -= 3 ; } scan += 3 ; if ( cmp_res ) { if ( cmp_res < 0 && scan != * where ) pari_err_BUG ( " " ) ; INIT ( scan , value , exponent , class0 ) ; return ; } if ( DEBUGLEVEL >= 4 ) err_printf ( " \n \t \n " , value ) ; old = scan - 3 ; class1 = CLASS ( old ) ; if ( class0 ) { if ( class1 ) { if ( class0 == gen_0 && class1 != gen_0 ) pari_err_BUG ( " " ) ; else if ( class0 != gen_0 && class1 == gen_0 ) pari_err_BUG ( " " ) ; else if ( class0 == gen_2 ) CLASS ( scan ) = class0 ; } else CLASS ( scan ) = class0 ; } CLASS ( scan ) = class1 ; if ( EXPON ( old ) == gen_1 && exponent == gen_1 ) EXPON ( scan ) = gen_2 ; else EXPON ( scan ) = addii ( EXPON ( old ) , exponent ) ; old = scan - 3 ; * scan = * old ; ifac_delete ( old ) ; if ( old == * where ) * where += 3 ; }
Re-sort one (typically unknown) entry from washere to a new position,
 rotating intervening entries upward to fill the vacant space.
Re - sort one ( typically unknown ) entry from washere to a new position rotating intervening entries upward to fill the vacant space .
/* nothing to do, washere==*where */ /* sentinel */ /* at least once */ /* current slot nonempty, check against where */ /* have found where to stop */ /* copy current slot upward by one position and move pointers down */ /* At this point there are the following possibilities:
   * 1) cmp_res == -1. Either value is less than that at *where, or *where was
   * pointing at vacant slots and any factors we saw en route were larger than
   * value. At any rate, scan == *where now, and scan is pointing at an empty
   * slot, into which we'll stash our entry.
   * 2) cmp_res == 0. The entry at scan-3 is the one, we compare class0
   * fields and add exponents, and put it all into the vacated scan slot,
   * NULLing the one at scan-3 (and possibly updating *where).
   * 3) cmp_res == 1. The slot at scan is the one to store our entry into. */ /* case cmp_res == 0: repeated factor detected */ /* if old class0 was composite and new is prime, or vice versa, complain
   * (and if one class0 was unknown and the other wasn't, use the known one) */ /* should never be used */ /* else stay with the existing known class0 */ /* in any case, add exponents */ /* move the value over and null out the vacated slot below */ /* finally, see whether *where should be pulled in */