bridge/class-master/depend/pari/src/basemath/concat.c
/* assume A or B is a t_LIST */
assume A or B is a t_LIST
assume A or B is a t_LIST
static GEN
listconcat(GEN A, GEN B)
{
  long i, l1, lx;
  GEN L, z, L1, L2;
  if (typ(A) != t_LIST) {
    if (list_typ(B)!=t_LIST_RAW) pari_err_TYPE("listconcat",B);
    L2 = list_data(B);
    if (!L2) return mklistcopy(A);
    lx = lg(L2) + 1;
    z = mklist();
    list_data(z) = L = cgetg(lx, t_VEC);
    for (i = 2; i < lx; i++) gel(L,i) = gcopy(gel(L2,i-1));
    gel(L,1) = gcopy(A); return z;
  } else if (typ(B) != t_LIST) {
    if (list_typ(A)!=t_LIST_RAW) pari_err_TYPE("listconcat",A);
    L1 = list_data(A);
    if (!L1) return mklistcopy(B);
    lx = lg(L1) + 1;
    z = mklist();
    list_data(z) = L = cgetg(lx, t_VEC);
    for (i = 1; i < lx-1; i++) gel(L,i) = gcopy(gel(L1,i));
    gel(L,i) = gcopy(B); return z;
  }
  if (list_typ(A)!=t_LIST_RAW) pari_err_TYPE("listconcat",A);
  if (list_typ(B)!=t_LIST_RAW) pari_err_TYPE("listconcat",B);
  L1 = list_data(A); if (!L1) return listcopy(B);
  L2 = list_data(B); if (!L2) return listcopy(A);
  l1 = lg(L1);
  lx = l1-1 + lg(L2);
  z = cgetg(3, t_LIST);
  z[1] = 0UL;
  list_data(z) = L = cgetg(lx, t_VEC);
  L2 -= l1-1;
  for (i=1; i<l1; i++) gel(L,i) = gclone(gel(L1,i));
  for (   ; i<lx; i++) gel(L,i) = gclone(gel(L2,i));
  return z;
}
static GEN listconcat ( GEN A , GEN B ) { long i , l1 , lx ; GEN L , z , L1 , L2 ; if ( typ ( A ) != t_LIST ) { if ( list_typ ( B ) != t_LIST_RAW ) pari_err_TYPE ( " " , B ) ; L2 = list_data ( B ) ; if ( ! L2 ) return mklistcopy ( A ) ; lx = lg ( L2 ) + 1 ; z = mklist ( ) ; list_data ( z ) = L = cgetg ( lx , t_VEC ) ; for ( i = 2 ; i < lx ; i ++ ) gel ( L , i ) = gcopy ( gel ( L2 , i - 1 ) ) ; gel ( L , 1 ) = gcopy ( A ) ; return z ; } else if ( typ ( B ) != t_LIST ) { if ( list_typ ( A ) != t_LIST_RAW ) pari_err_TYPE ( " " , A ) ; L1 = list_data ( A ) ; if ( ! L1 ) return mklistcopy ( B ) ; lx = lg ( L1 ) + 1 ; z = mklist ( ) ; list_data ( z ) = L = cgetg ( lx , t_VEC ) ; for ( i = 1 ; i < lx - 1 ; i ++ ) gel ( L , i ) = gcopy ( gel ( L1 , i ) ) ; gel ( L , i ) = gcopy ( B ) ; return z ; } if ( list_typ ( A ) != t_LIST_RAW ) pari_err_TYPE ( " " , A ) ; if ( list_typ ( B ) != t_LIST_RAW ) pari_err_TYPE ( " " , B ) ; L1 = list_data ( A ) ; if ( ! L1 ) return listcopy ( B ) ; L2 = list_data ( B ) ; if ( ! L2 ) return listcopy ( A ) ; l1 = lg ( L1 ) ; lx = l1 - 1 + lg ( L2 ) ; z = cgetg ( 3 , t_LIST ) ; z [ 1 ] = 0UL ; list_data ( z ) = L = cgetg ( lx , t_VEC ) ; L2 -= l1 - 1 ; for ( i = 1 ; i < l1 ; i ++ ) gel ( L , i ) = gclone ( gel ( L1 , i ) ) ; for ( ; i < lx ; i ++ ) gel ( L , i ) = gclone ( gel ( L2 , i ) ) ; return z ; }
assume A or B is a t_LIST
assume A or B is a t_LIST
/* A, B both t_LISTs */