int main(int argc,char **argv) { long i; char stdi=0; double min,max,maxmax; if (scan_help(argc,argv)) show_options(argv[0]); scan_options(argc,argv); #ifndef OMIT_WHAT_I_DO if (verbosity&VER_INPUT) what_i_do(argv[0],WID_STR); #endif infile=search_datafile(argc,argv,NULL,verbosity); if (infile == NULL) stdi=1; if (outfile == NULL) { if (!stdi) { check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1)); strcpy(outfile,infile); strcat(outfile,".rec"); } else { check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1)); strcpy(outfile,"stdin.rec"); } } if (!stdo) test_outfile(outfile); if (columns == NULL) series=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset, verbosity); else series=(double**)get_multi_series(infile,&length,exclude,&dim,columns, dimset,verbosity); maxmax=0.0; for (i=0;i<dim;i++) { rescale_data(series[i],length,&min,&max); if (max > maxmax) maxmax=max; } if (epsset) eps /= maxmax; check_alloc(list=(long*)malloc(sizeof(long)*length)); check_alloc(box=(long**)malloc(sizeof(long*)*BOX)); for (i=0;i<BOX;i++) check_alloc(box[i]=(long*)malloc(sizeof(long)*BOX)); make_multi_box(series,box,list,length,BOX,dim,embed,delay,eps); lfind_neighbors(); return 0; }
PCFOP * read_initbase(const char * line) { char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(struct PCFOP)); check_alloc(ret); ret->op = initbase_op; uint32_t base; bitr = buf; bitr[0] = '\0'; line = skip_to_colon(line); line++; line = assert_token(line, buf, bitr, "BASE"); sscanf(line, "%d\n", &base); assert(base >= 0); ret->data = malloc(sizeof(uint32_t)); check_alloc(ret->data); *((uint32_t*)ret->data) = base; return ret; }
PCFOP * read_mkptr(const char * line) { char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(PCFOP)); uint32_t * data = malloc(sizeof(uint32_t)); check_alloc(ret); check_alloc(data); ret->op = mkptr_op; ret->data = data; bitr = buf; line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "DEST") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", data) == 1); } else assert(0); return ret; }
int main(int argc,char **argv) { char stdi=0; unsigned int i,j; double rms,*av; if (scan_help(argc,argv)) show_options(argv[0]); scan_options(argc,argv); #ifndef OMIT_WHAT_I_DO if (verbosity&VER_INPUT) what_i_do(argv[0],WID_STR); #endif infile=search_datafile(argc,argv,NULL,verbosity); if (infile == NULL) stdi=1; if (outfile == NULL) { if (!stdi) { check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1)); strcpy(outfile,infile); strcat(outfile,".pca"); } else { check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1)); strcpy(outfile,"stdin.pca"); } } if (!stout) test_outfile(outfile); if (column == NULL) series=(double**)get_multi_series(infile,&LENGTH,exclude,&DIM,"",dimset, verbosity); else series=(double**)get_multi_series(infile,&LENGTH,exclude,&DIM,column, dimset,verbosity); dimemb=DIM*EMB; if (!projection_set) LDIM=dimemb; else { if (LDIM < 1) LDIM=1; if (LDIM > dimemb) LDIM=dimemb; } check_alloc(av=(double*)malloc(sizeof(double)*DIM)); for (j=0;j<DIM;j++) { av[j]=rms=0.0; variance(series[j],LENGTH,&av[j],&rms); for (i=0;i<LENGTH;i++) series[j][i] -= av[j]; } make_pca(av); return 0; }
HashTable* ht_make(size_t len) { HashTable* t = malloc(sizeof(HashTable)); check_alloc(t); t->buckets = calloc(sizeof(LinkedList*), len); check_alloc(t->buckets); t->len = len; return t; }
PCFOP * read_gate(const char * line) { char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(PCFOP)); struct PCFGate * data = malloc(sizeof(struct PCFGate)); uint32_t i = 0; check_alloc(ret); check_alloc(data); bitr = buf; ret->op = gate_op; ret->data = data; data->tag = TAG_INTERNAL; bitr[0] = '\0'; for(i = 0; i < 4; i++) { line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "DEST") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->reswire) == 1); } else if(strcmp(buf, "OP1") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->wire1) == 1); } else if(strcmp(buf, "OP2") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->wire2) == 1); } else if(strcmp(buf, "TRUTH-TABLE") == 0) { bitr = buf; line = read_token(line, bitr); assert(buf[0] == '#'); assert(buf[1] == '*'); data->truth_table = (buf[2] == '1' ? 1 : 0) | (buf[3] == '1' ? 2 : 0) | (buf[4] == '1' ? 4 : 0) | (buf[5] == '1' ? 8 : 0); } else assert(0); } return ret; }
PCFOP * read_branch(const char * line) { char buf[LINE_MAX], *bitr; PCFOP * ret = (PCFOP*)malloc(sizeof(PCFOP)); uint32_t i = 0; struct branch_op_data * data = (struct branch_op_data*)malloc(sizeof(struct call_op_data)); check_alloc(ret); check_alloc(data); ret->op = branch_op; ret->data = data; bitr = buf; for(i = 0; i < 2; i++) { line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "CND") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->cnd_wire) == 1); } else if(strcmp(buf, "TARG") == 0) { ENTRY * ent = (ENTRY*)malloc(sizeof(ENTRY)); check_alloc(ent); while((line[0] == ' ') || (line[0] == '"')) { assert(line[0] != '\0'); line++; } bitr = buf; line = read_token(line, bitr); assert(buf[strlen(buf)-1] == '"'); buf[strlen(buf)-1] = '\0'; ent->key = malloc(strlen(buf)+1); strcpy(ent->key, buf); data->target = ent; } else { assert(0); } } return ret; }
PCFOP * read_const(const char * line) { char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(PCFOP)); struct const_op_data * data = malloc(sizeof(struct const_op_data)); check_alloc(ret); check_alloc(data); bitr = buf; ret->op = const_op; ret->data = data; bitr[0] = '\0'; line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "DEST") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->dest) == 1); } else if(strcmp(buf, "OP1") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->value) == 1); } else assert(0); line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "DEST") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->dest) == 1); } else if(strcmp(buf, "OP1") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->value) == 1); } else assert(0); return ret; }
Heap* hp_make(size_t cap) { Heap* h = malloc(sizeof(Heap)); check_alloc(h); h->v = calloc(cap, sizeof(int)); check_alloc(h->v); h->cap = cap; h->tail = 0; return h; }
DynArray* dyn_make(size_t cap) { DynArray* m = malloc(sizeof(DynArray)); check_alloc(m); m->v = calloc(cap, sizeof(int)); check_alloc(m->v); m->cap = cap; m->tail = 0; return m; }
PCFOP * read_label(const char * line, struct PCFState * st, uint32_t iptr) { ENTRY * newent, * r; char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(struct PCFOP)); check_alloc(ret); ret->op = nop; bitr = buf; line = skip_to_colon(line); // Skip over the ':' line++; line = assert_token(line, buf, bitr, "STR"); while((line[0] == ' ') || (line[0] == '"')) { assert(line[0] != '\0'); line++; } bitr = buf; while((line[0] != ' ') && (line[0] != '"') && (line[0] != ')')) { assert(line[0] != '\0'); bitr[0] = line[0]; line++; bitr++; } bitr[0] = '\0'; newent = (ENTRY*)malloc(sizeof(ENTRY)); check_alloc(newent); newent->key = malloc(strlen(buf)+1); check_alloc(newent->key); strcpy(newent->key, buf); newent->data = malloc(sizeof(uint32_t)); check_alloc(newent->data); *((uint32_t*)newent->data) = iptr; //hsearch_r(*newent, ENTER, &r, st->labels); if(hsearch_r(*newent, ENTER, &r, st->labels) == 0) { fprintf(stderr, "Problem inserting hash table for %s %d: %s\n", newent->key, *((uint32_t*)newent->data), strerror(errno)); abort(); } return ret; }
int allocate_boundary_coef(int *nintcf, double **bs, double **be, double **bn, double **bw, double **bl, double **bh, double **bp, double **su) { *bs = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(bs, "malloc for bs failed"); *be = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(be, "malloc for be failed"); *bn = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(bn, "malloc for bn failed"); *bw = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(bw, "malloc for bw failed"); *bl = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(bl, "malloc for bl failed"); *bh = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(bh, "malloc for bh failed"); *bp = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(bp, "malloc for bp failed"); *su = (double *) malloc(((*nintcf)+1)*sizeof(double)); check_alloc(su, "malloc for su failed"); return POSL_OK; }
frame_reader_t frame_reader_new() { frame_reader_t reader = malloc(sizeof(frame_reader)); check_alloc(reader); memset(reader, 0, sizeof(frame_reader)); reader->num_schemas = 0; reader->capacity = 16; reader->schemas = malloc(reader->capacity * sizeof(void*)); check_alloc(reader->schemas); reader->frame_schema = schema_for_frame(); reader->frame_iface = avro_generic_class_from_schema(reader->frame_schema); avro_generic_value_new(reader->frame_iface, &reader->frame_value); reader->avro_reader = avro_reader_memory(NULL, 0); return reader; }
/* Allocates a new schema list entry. */ schema_list_entry *schema_list_entry_new(frame_reader_t reader) { if (reader->num_schemas == reader->capacity) { reader->capacity *= 4; reader->schemas = realloc(reader->schemas, reader->capacity * sizeof(void*)); check_alloc(reader->schemas); } schema_list_entry *new_entry = malloc(sizeof(schema_list_entry)); check_alloc(new_entry); memset(new_entry, 0, sizeof(schema_list_entry)); reader->schemas[reader->num_schemas] = new_entry; reader->num_schemas++; return new_entry; }
char *test_outfile(char *name) { char *nname; unsigned int len,i=1; FILE *file; if (access(name,F_OK) != -1) { len=strlen(name); check_alloc(nname=(char*)malloc(sizeof(char)*(len+4))); sprintf(nname,"%s",name); while (access(nname,F_OK) != -1) { sprintf(nname,"%s.%u",name,i); i++; } if (i > 1) { free(name); name=nname; } } file=fopen(name,"a"); if (file == NULL) { fprintf(stderr,"Couldn't open %s for writing. Exiting\n",name); exit(TEST_OUTFILE_NO_WRITE_ACCESS); } fclose(file); return name; }
int lca(int** clade, int nbcl, int nbotu, int cl1, int cl2){ int i, j, *lcacl, noparent, sz, min, rgmin; lcacl=(int*)check_alloc(nbotu, sizeof(int)); for(i=0;i<nbotu;i++){ if(clade[cl1][i]==1 || clade[cl2][i]==1) lcacl[i]=1; else lcacl[i]=0; } min=nbotu+1; rgmin=-1; for(i=0;i<nbcl;i++){ sz=0; noparent=0; for(j=0;j<nbotu;j++){ if(clade[i][j]==0 && lcacl[j]==1) {noparent=1; break;} sz+=clade[i][j]; } if(noparent) continue; if(sz<min){ min=sz; rgmin=i; } } if(rgmin<0){ printf("erreur lca\n"); exit(EXIT_FAILURE); } free(lcacl); return rgmin; }
void create_delay_list(void) { unsigned int i=0,num=0; while (multidelay[i]) { if (!(isdigit(multidelay[i])) && !(multidelay[i] == ',')) { fprintf(stderr,"Wrong format of -D parameter. Exiting!\n"); exit(DELAY_WRONG_FORMAT_D); } i++; } i=0; while (multidelay[i]) { if (multidelay[i++] == ',') num++; } check_alloc(delaylist=(unsigned int*)malloc(sizeof(int)*(num+1))); for (i=0;i<=num;i++) { sscanf(multidelay,"%d",&delaylist[i]); if (i<num) { while ((*multidelay) != ',') multidelay++; } multidelay++; } if ((num+1) != (embdim-indim)) { fprintf(stderr,"Wrong number of delays. See man page. Exiting!\n"); exit(DELAY_WRONG_NUM_D); } }
static void hp_ensure_size(Heap* h, size_t min_size) { if (h->cap < min_size) { h->cap = 2*min_size; // TODO check for overflow h->v = realloc(h->v, 2*min_size); // TODO expansion method? check_alloc(h->v); } }
LinkedList* lnls_make(LinkedList* next, const char* val) { LinkedList* list = malloc(sizeof(LinkedList)); check_alloc(list); list->next = next; list->val = val; return list; }
void copytree(int** from, int** to, int nb){ int i, j, jfrom, jto; int eq, opp; int *keep_to, *keep_from; keep_to=check_alloc(nb, sizeof(int)); keep_from=check_alloc(nb, sizeof(int)); /* seek common branches */ for(jfrom=0;jfrom<nb-3;jfrom++){ for(jto=0;jto<nb-3;jto++){ if(keep_to[jto]==1) continue; eq=opp=0; for(i=0;i<nb;i++){ if(from[i][jfrom]==to[i][jto]) eq=1; else opp=1; if(eq && opp) break; } if(i==nb){ /* identical branches */ keep_to[jto]=1; keep_from[jfrom]=1; break; } } } /* copy distinct branches */ for(jfrom=0;jfrom<nb-3;jfrom++){ if(keep_from[jfrom]==1) continue; for(jto=0;jto<nb-3;jto++){ if(keep_to[jto]==1) continue; for(i=0;i<nb;i++) to[i][jto]=from[i][jfrom]; keep_to[jto]=1; break; } } free(keep_to); free(keep_from); }
void dyn_resize(DynArray* m, size_t cap) { m->v = realloc(m->v, cap*sizeof(int)); check_alloc(m->v); m->cap = cap; if (m->tail > cap) { m->tail = cap; } }
int do_poly(char *buff, FILE * infile) { int num; char origcmd[64]; float xper, yper; char *fgets(); int to_return; sscanf(buff, "%s", origcmd); num = 0; for (;;) { if ((to_return = G_getl2(buff, 128, infile)) != 1) break; if (2 != sscanf(buff, "%f %f", &xper, &yper)) { if ('#' == buff[0]) { G_debug(3, " skipping comment line [%s]", buff); continue; } G_debug(3, "coordinate pair not found. ending polygon. [%s]", buff); break; } if (!mapunits) { if (xper < 0. || yper < 0. || xper > 100. || yper > 100.) break; } check_alloc(num + 1); if (mapunits) { xarray[num] = (int)(D_u_to_d_col(xper) + 0.5); yarray[num] = (int)(D_u_to_d_row(yper) + 0.5); } else { xarray[num] = l + (int)(xper * xincr); yarray[num] = b - (int)(yper * yincr); } num++; } if (num) { /* this check is here so you can use the "polyline" command to make an unfilled polygon */ if (!strcmp(origcmd, "polygon")) R_polygon_abs(xarray, yarray, num); else R_polyline_abs(xarray, yarray, num); } return (to_return); }
PCFOP * read_arith(const char * line, void (*op)(struct PCFState *, struct PCFOP *)) { char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(PCFOP)); struct arith_op_data * data = malloc(sizeof(struct arith_op_data)); uint32_t i = 0; check_alloc(ret); check_alloc(data); bitr = buf; ret->op = op; ret->data = data; bitr[0] = '\0'; for(i = 0; i < 3; i++) { line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "DEST") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->dest) == 1); } else if(strcmp(buf, "OP1") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->op1) == 1); } else if(strcmp(buf, "OP2") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->op2) == 1); } else assert(0); } return ret; }
void iterate_model(double **coeff,double *sigma,FILE *file) { long i,j,i1,i2,n,d; double **iterate,*swap; check_alloc(iterate=(double**)malloc(sizeof(double*)*(poles+1))); for (i=0;i<=poles;i++) check_alloc(iterate[i]=(double*)malloc(sizeof(double)*dim)); rnd_init(0x44325); for (i=0;i<1000;i++) gaussian(1.0); for (i=0;i<dim;i++) for (j=0;j<poles;j++) iterate[j][i]=gaussian(sigma[i]); for (n=0;n<ilength;n++) { for (d=0;d<dim;d++) { iterate[poles][d]=gaussian(sigma[d]); for (i1=0;i1<dim;i1++) for (i2=0;i2<poles;i2++) iterate[poles][d] += coeff[d][i1*poles+i2]*iterate[poles-1-i2][i1]; } if (file != NULL) { for (d=0;d<dim;d++) fprintf(file,"%e ",iterate[poles][d]); fprintf(file,"\n"); } else { for (d=0;d<dim;d++) printf("%e ",iterate[poles][d]); printf("\n"); } swap=iterate[0]; for (i=0;i<poles;i++) iterate[i]=iterate[i+1]; iterate[poles]=swap; } for (i=0;i<=poles;i++) free(iterate[i]); free(iterate); }
PCFOP * read_indir_copy(const char * line) { char buf[LINE_MAX], *bitr; PCFOP * ret = malloc(sizeof(PCFOP)); struct copy_op_data * data = malloc(sizeof(struct copy_op_data)); uint32_t i = 0; check_alloc(ret); check_alloc(data); bitr = buf; ret->op = indir_copy_op; ret->data = data; bitr[0] = '\0'; for(i = 0; i < 3; i++) { line = skip_to_colon(line); line++; bitr = buf; line = read_token(line, bitr); if(strcmp(buf, "DEST") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->dest) == 1); } else if(strcmp(buf, "OP1") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->source) == 1); } else if(strcmp(buf, "OP2") == 0) { bitr = buf; line = read_token(line, bitr); assert(sscanf(buf, "%d", &data->width) == 1); } else assert(0); } return ret; }
void populate_table(Table *t, void **values, int num) { int q; for (q= 0; q < num; q++) { /* Create space for the three letter acronym, plus null terminator. */ char *key= calloc(4, sizeof(char)); check_alloc(key); strncpy(key, values[q], 3); insert(t, (void*)key, (void*)values[q]); } }
static void test_chunkalloc(skiatest::Reporter* reporter) { static const size_t kMin = 1024; SkChunkAlloc alloc(kMin); //------------------------------------------------------------------------ // check empty check_alloc(reporter, alloc, 0, 0, 0); REPORTER_ASSERT(reporter, !alloc.contains(nullptr)); REPORTER_ASSERT(reporter, !alloc.contains(reporter)); // reset on empty allocator alloc.reset(); check_alloc(reporter, alloc, 0, 0, 0); // rewind on empty allocator alloc.rewind(); check_alloc(reporter, alloc, 0, 0, 0); //------------------------------------------------------------------------ // test reset when something is allocated size_t size = kMin >> 1; void* ptr = simple_alloc(reporter, &alloc, size); alloc.reset(); check_alloc(reporter, alloc, 0, 0, 0); REPORTER_ASSERT(reporter, !alloc.contains(ptr)); //------------------------------------------------------------------------ // test rewind when something is allocated ptr = simple_alloc(reporter, &alloc, size); alloc.rewind(); check_alloc(reporter, alloc, size, 0, 1); REPORTER_ASSERT(reporter, !alloc.contains(ptr)); // use the available block ptr = simple_alloc(reporter, &alloc, size); alloc.reset(); //------------------------------------------------------------------------ // test out allocating a second block ptr = simple_alloc(reporter, &alloc, size); ptr = alloc.allocThrow(kMin); check_alloc(reporter, alloc, 2*kMin, size+kMin, 2); REPORTER_ASSERT(reporter, alloc.contains(ptr)); //------------------------------------------------------------------------ // test out unalloc size_t freed = alloc.unalloc(ptr); REPORTER_ASSERT(reporter, freed == kMin); check_alloc(reporter, alloc, 2*kMin, size, 2); REPORTER_ASSERT(reporter, !alloc.contains(ptr)); }
void init_neighbor_search(double **x,struct param p,unsigned int *fut) { long n=3; int i,j,k; if (p.DIM == 1) { nsseconddim=0; nsthirddim=0; } else if (p.DIM == 2) { nsseconddim=1; nsthirddim=1; } else { nsseconddim=1; nsthirddim=2; } for (i=0; i<NEIGH; i++) { neigh[i].n=n; check_alloc(neigh[i].list=(long*)malloc(sizeof(long)*p.LENGTH)); check_alloc(neigh[i].box=(long***)malloc(sizeof(long**)*n)); for (j=0; j<n; j++) { check_alloc(neigh[i].box[j]=(long**)malloc(sizeof(long*)*n)); for (k=0; k<n; k++) check_alloc(neigh[i].box[j][k]=(long*)malloc(sizeof(long)*n)); } put_in_boxes(i,x,p,fut); n=n*2; } for (i=0; i<EPSILONS; i++) { for (j=0; j<EPSILONS; j++) { starteps[i][j]=0.0; countstarteps[i][j]=0; } } minminn=p.minminn; }
double* multiply_matrix_vector(double **mat,double *vec) { long i,j; double *new_vec; check_alloc(new_vec=(double*)malloc(sizeof(double)*poles*dim)); for (i=0;i<poles*dim;i++) { new_vec[i]=0.0; for (j=0;j<poles*dim;j++) new_vec[i] += mat[i][j]*vec[j]; } return new_vec; }
void nesteddist(int** clade, int nb, int nbcl, int* clsz, int otu, int** dist){ int i, j, k, *cllist, *clldist, *ranks, nbnest=0; cllist=(int*)check_alloc(nbcl, sizeof(int)); clldist=(int*)check_alloc(nbcl, sizeof(int)); ranks=(int*)check_alloc(nbcl, sizeof(int)); for(i=0;i<nbcl;i++){ dist[i][i]=0; if(clade[i][otu]){ cllist[nbnest]=i; clldist[nbnest]=clsz[i]; nbnest++; } } sort(clldist, ranks, nbnest); for(j=0;j<nbnest;j++){ for(k=j+1;k<nbnest;k++){ dist[cllist[j]][cllist[k]]=ranks[k]-ranks[j]; if(dist[cllist[j]][cllist[k]]>0) dist[cllist[j]][cllist[k]]--; else dist[cllist[j]][cllist[k]]++; dist[cllist[k]][cllist[j]]=-dist[cllist[j]][cllist[k]]; } } /* For nested clades, dist[i][j]=-dist[j][i]. dist[i][j] is positive if */ /* clade i is a part of clade j, negative if clade j is a part of clade i, */ /* so that d[i][j]<0 => clade i cannot move toward clade j. */ /* Non-nested clades have positive distances both ways. */ free(cllist); free(clldist); free(ranks); }