#define panic(c) {gb_free(node_blocks) ; \ panic_code= c;gb_alloc_trouble= 0;return NULL;} \ #define nodes_per_block 111 \ #define copy5(y,x) { \ *(y) = *(x) ; \ *((y) +1) = *((x) +1) ; \ *((y) +2) = *((x) +2) ; \ *((y) +3) = *((x) +3) ; \ *((y) +4) = *((x) +4) ; \ } \ #define hash_prime 6997 \ #define weight u.i #define loc a.i \ #define mtch(i) (*(q+i) ==*(r+i) ) #define match(a,b,c,d) (mtch(a) &&mtch(b) &&mtch(c) &&mtch(d) ) #define store_loc_of_diff(k) cur_vertex->arcs->loc= (cur_vertex->arcs-1) ->loc= k \ /*7:*/ #line 150 "gb_words.w" #include "gb_io.h" #include "gb_flip.h" #include "gb_graph.h" #include "gb_sort.h" /*15:*/ #line 280 "gb_words.w" typedef struct node_struct{ long key; struct node_struct*link; char wd[5]; }node; /*:15*//*23:*/ #line 403 "gb_words.w" typedef Vertex*hash_table[hash_prime]; /*:23*/ #line 156 "gb_words.w" /*4:*/ #line 92 "gb_words.w" static int max_c[]= {15194,3560,4467,460,6976,756,362}; static int default_wt_vector[]= {100,10,4,2,2,1,1,1,1}; /*:4*//*17:*/ #line 294 "gb_words.w" Area node_blocks; /*:17*//*25:*/ #line 410 "gb_words.w" static hash_table*htab; /*:25*/ #line 157 "gb_words.w" /*10:*/ #line 207 "gb_words.w" static double flabs(x) int x; {if(x>=0)return(double)x; return-((double)x); } /*:10*//*13:*/ #line 253 "gb_words.w" static long iabs(x) int x; {if(x>=0)return(long)x; return-((long)x); } /*:13*/ #line 158 "gb_words.w" Graph*words(n,wt_vector,wt_threshold,seed) unsigned n; int wt_vector[]; long wt_threshold; long seed; {/*8:*/ #line 177 "gb_words.w" Graph*new_graph; /*:8*//*14:*/ #line 262 "gb_words.w" int c[7]; register long wt; char word[5]; int nn= 0; /*:14*//*16:*/ #line 288 "gb_words.w" node*next_node; node*bad_node; node*stack_ptr; node*cur_node; /*:16*//*24:*/ #line 406 "gb_words.w" Vertex*cur_vertex; char*next_string; /*:24*/ #line 165 "gb_words.w" gb_init_rand(seed); /*9:*/ #line 194 "gb_words.w" if(!wt_vector)wt_vector= default_wt_vector; else{register double flacc; register int*p,*q; register long acc; /*11:*/ #line 227 "gb_words.w" p= wt_vector; flacc= flabs(*p++); if(flacc=(double)0x60000000) panic(very_bad_specs); /*:11*/ #line 200 "gb_words.w" ; /*12:*/ #line 243 "gb_words.w" p= wt_vector; acc= iabs(*p++); if(acc=0x40000000) panic(bad_specs); /*:12*/ #line 201 "gb_words.w" ; } /*:9*/ #line 167 "gb_words.w" ; /*18:*/ #line 297 "gb_words.w" next_node= bad_node= stack_ptr= NULL; if(gb_open("words.dat")!=0) panic(early_data_fault); do/*19:*/ #line 309 "gb_words.w" {register int j; for(j= 0;j<5;j++)word[j]= gb_char(); /*21:*/ #line 348 "gb_words.w" {register int*p,*q; register long c; switch(gb_char()){ case'*':wt= wt_vector[0];break; case'+':wt= wt_vector[1];break; case' ':case'\n':wt= 0;break; default:panic(syntax_error); } p= &max_c[0];q= &wt_vector[2]; do{ if(p==&max_c[7]) panic(syntax_error+1); c= gb_number(10); if(c>*p++) panic(syntax_error+2); wt+= c**q++; }while(gb_char()==','); } /*:21*/ #line 312 "gb_words.w" ; if(wt>=wt_threshold){ /*20:*/ #line 328 "gb_words.w" if(next_node==bad_node){ cur_node= gb_alloc_type(nodes_per_block,node,node_blocks); if(cur_node==NULL) panic(no_room+1); next_node= cur_node+1; bad_node= cur_node+nodes_per_block; }else cur_node= next_node++; cur_node->key= wt+0x40000000; cur_node->link= stack_ptr; copy5(cur_node->wd,word); stack_ptr= cur_node; /*:20*/ #line 314 "gb_words.w" ; nn++; } gb_newline(); } /*:19*/ #line 303 "gb_words.w" while(!gb_eof()); if(gb_close()!=0) panic(late_data_fault); /*:18*/ #line 168 "gb_words.w" ; /*22:*/ #line 380 "gb_words.w" gb_linksort(stack_ptr); /*27:*/ #line 424 "gb_words.w" if(n==0||nnid,"words(%u,0,%ld,%ld)",n,wt_threshold,seed); else sprintf(new_graph->id, "words(%u,{%d,%d,%d,%d,%d,%d,%d,%d,%d},%ld,%ld)", n,wt_vector[0],wt_vector[1],wt_vector[2],wt_vector[3],wt_vector[4], wt_vector[5],wt_vector[6],wt_vector[7],wt_vector[8],wt_threshold,seed); strcpy(new_graph->format,"IZZZZZIZZZZZZZ"); cur_vertex= new_graph->vertices; next_string= gb_alloc_type(6*n,char,new_graph->data); htab= gb_alloc_type(5,hash_table,new_graph->aux_data); /*:27*/ #line 382 "gb_words.w" ; if(gb_alloc_trouble==0&&n){ register int j; register node*p; nn= n; for(j= 127;j>=0;j--) for(p= (node*)gb_sorted[j];p;p= p->link){ /*28:*/ #line 441 "gb_words.w" {register char*q; q= cur_vertex->name= next_string; next_string+= 6; copy5(q,p->wd); cur_vertex->weight= p->key-0x40000000; /*29:*/ #line 458 "gb_words.w" {register char*r; register Vertex**h; register long raw_hash; raw_hash= (((((((*q<<5)+*(q+1))<<5)+*(q+2))<<5)+*(q+3))<<5)+*(q+4); for(h= htab[0]+(raw_hash-(*q<<20))%hash_prime; *h;h==htab[0]?h= htab[1]-1:h--){ r= (*h)->name; if(match(1,2,3,4)) gb_new_edge(cur_vertex,*h,1),store_loc_of_diff(0); } *h= cur_vertex; for(h= htab[1]+(raw_hash-(*(q+1)<<15))%hash_prime; *h;h==htab[1]?h= htab[2]-1:h--){ r= (*h)->name; if(match(0,2,3,4)) gb_new_edge(cur_vertex,*h,1),store_loc_of_diff(1); } *h= cur_vertex; for(h= htab[2]+(raw_hash-(*(q+2)<<10))%hash_prime; *h;h==htab[2]?h= htab[3]-1:h--){ r= (*h)->name; if(match(0,1,3,4)) gb_new_edge(cur_vertex,*h,1),store_loc_of_diff(2); } *h= cur_vertex; for(h= htab[3]+(raw_hash-(*(q+3)<<5))%hash_prime; *h;h==htab[3]?h= htab[4]-1:h--){ r= (*h)->name; if(match(0,1,2,4)) gb_new_edge(cur_vertex,*h,1),store_loc_of_diff(3); } *h= cur_vertex; for(h= htab[4]+(raw_hash-*(q+4))%hash_prime; *h;h==htab[4]?h= htab[5]-1:h--){ r= (*h)->name; if(match(0,1,2,3)) gb_new_edge(cur_vertex,*h,1),store_loc_of_diff(4); } *h= cur_vertex; } /*:29*/ #line 447 "gb_words.w" ; cur_vertex++; } /*:28*/ #line 389 "gb_words.w" ; if(--nn==0)goto done; } } done:gb_free(node_blocks); /*:22*/ #line 169 "gb_words.w" ; if(gb_alloc_trouble){ gb_recycle(new_graph); panic(alloc_fault); } return new_graph; } /*:7*//*30:*/ #line 511 "gb_words.w" Vertex*find_word(q,f) char*q; void(*f)(); {register char*r; register Vertex**h; register long raw_hash; raw_hash= (((((((*q<<5)+*(q+1))<<5)+*(q+2))<<5)+*(q+3))<<5)+*(q+4); for(h= htab[0]+(raw_hash-(*q<<20))%hash_prime; *h;h==htab[0]?h= htab[1]-1:h--){ r= (*h)->name; if(mtch(0)&&match(1,2,3,4)) return*h; } /*31:*/ #line 528 "gb_words.w" for(h= htab[0]+(raw_hash-(*q<<20))%hash_prime; *h;h==htab[0]?h= htab[1]-1:h--){ r= (*h)->name; if(match(1,2,3,4)) (*f)(*h); } for(h= htab[1]+(raw_hash-(*(q+1)<<15))%hash_prime; *h;h==htab[1]?h= htab[2]-1:h--){ r= (*h)->name; if(match(0,2,3,4)) (*f)(*h); } for(h= htab[2]+(raw_hash-(*(q+2)<<10))%hash_prime; *h;h==htab[2]?h= htab[3]-1:h--){ r= (*h)->name; if(match(0,1,3,4)) (*f)(*h); } for(h= htab[3]+(raw_hash-(*(q+3)<<5))%hash_prime; *h;h==htab[3]?h= htab[4]-1:h--){ r= (*h)->name; if(match(0,1,2,4)) (*f)(*h); } for(h= htab[4]+(raw_hash-*(q+4))%hash_prime; *h;h==htab[4]?h= htab[5]-1:h--){ r= (*h)->name; if(match(0,1,2,3)) (*f)(*h); } /*:31*/ #line 524 "gb_words.w" ; return NULL; } /*:30*/