INT_VECTOR int_vec_copy(INT_VECTOR a, INT_VECTOR result) { int i, m; m = Int_VecLen(a); if(result==NULL) if((result = int_vec_creat(m, UNDEFINED))==NULL) int_vec_error(INT_VEC_MALLOC); for(i=0; i<m; ++i) result[i] = a[i]; return result; }
INT_VECTOR __int_vec_creat(int len) { INT_VECTOR int_vector; if((int_vector = (int*)malloc(sizeof(int)*(len+1)))==NULL) return (int_vec_error(INT_VEC_MALLOC)); int_vector[0] = len; return (int_vector+1); }
INT_VECTOR int_vec_divs_inv(INT_VECTOR A, int s, INT_VECTOR result) { int i, m; m = Int_VecLen(A); if(result==NULL) if((result = int_vec_creat(m, UNDEFINED))==NULL) int_vec_error(INT_VEC_MALLOC); #pragma omp parallel for for(i=0; i<m; ++i) result[i] = s/A[i]; return result; }
INT_VECTOR int_vec_append(INT_VECTOR a, int i) { int l; l = Int_VecLen(a); a--; if((a = (int *)realloc(a, sizeof(int)*(l+2)))==NULL) return int_vec_error(INT_VEC_MALLOC); a[0]= l+1; ++a; a[l] = i; return a; }
INT_VECTOR int_vec_div(INT_VECTOR A, INT_VECTOR B, INT_VECTOR result) { int i, m; m = Int_VecLen(A); if(result==NULL) if((result = int_vec_creat(m, UNDEFINED))==NULL) int_vec_error(INT_VEC_MALLOC); if(m!=Int_VecLen(B)) gen_error(GEN_SIZEMISMATCH); #pragma omp parallel for for(i=0; i<m; ++i) result[i] = A[i]/B[i]; return result; }
INT_VECTOR int_vec_permute_vect(int n, int k, INT_VECTOR result) { int i, j, d; if(result== NULL) if((result = int_vec_creat(k, SERIES_INT_VECTOR))==NULL) return int_vec_error(INT_VEC_MALLOC); for(i=0; i<n-1; i++) { j = result[i]; d = i + (rand()%(n-i)); result[i] = result[d]; result[d] = j; } return result; }
INT_VECTOR int_vec_randperm(int n, INT_VECTOR result) { int i, j; int t = 0; if(result==NULL) if((result = int_vec_creat(n, UNDEFINED))==NULL) return int_vec_error(INT_VEC_MALLOC); if(!MAT_SET_SEED)mat_set_seed(0); for(i=0; i<n; ++i) result[i] = i; for(i=0; i<n; ++i) { j = rand()%(n-i)+i; t = result[j]; result[j] =result[i]; result[i] = t; } return result; }
INT_VECTOR int_vec_concat(INT_VECTOR a, INT_VECTOR b, INT_VECTOR result) { int i, m, n; m = Int_VecLen(a); n = Int_VecLen(b); if(result==NULL) { if((result = int_vec_creat(m+n, UNDEFINED))==NULL) return NULL; } else { if(Int_VecLen(result)!=(m+n)) return int_vec_error(INT_VEC_SIZEMISMATCH); } #pragma omp parallel for for(i=0; i<m; ++i) result[i] = a[i]; #pragma omp parallel for for(i=0; i<n; ++i) result[i+m] = b[i]; return result; }