static void _pe_q_insert (struct h * h) { int idx; /* if we reached the maximum depth (-d option) or we already found the * stop transition (-T option), skip the insertion */ if (u.depth && h->depth > u.depth) return; if (pe.q.skip) return; /* make room for a new item and proceed with the insertion */ pe.q.size++; idx = pe.q.size; _pe_q_alloc (); /* when the -T is used and u.stoptr is found, empty the queue to make * sure that the corresponding event is processed immediately. Also, * prevent any further additions to the PE queue. */ if (h->e->ft == u.stoptr) { pe.q.skip = 1; pe.q.size = 1; pe.q.tab[1] = h; return; } /* insert the new element at the end, then move upwards as needed */ for (; idx > 1; idx /= 2) { if (h_cmp (h, pe.q.tab[idx / 2]) > 0) break; pe.q.tab[idx] = pe.q.tab[idx / 2]; /* move parent downwards */ } pe.q.tab[idx] = h; }
void marking_add (struct h *h) { struct hash_entry *he, *nhe; struct ls *buckl, *n; int ret; ASSERT (h); ASSERT (h->marking); ASSERT (h->corr != 0); /* histories always initialized as cutoffs */ /* h->corr = 0; return; */ /* add the marking h->marking to the hash table if there is no * other history h' such that h->marking = h'->marking; if such h' * exists, then h is a cutoff; the function returns 1 iff h is a cutoff */ /* determine if the marking h->marking is in the hash table */ ASSERT (marking_hash (h->marking) == h->hash); buckl = hash.tab + h->hash; for (n = buckl->next; n; n = n->next) { he = ls_i (struct hash_entry, n, nod); ret = nl_compare (he->h->marking, h->marking); if (ret == 0) break; } #ifdef CONFIG_MCMILLAN /* if it is the case, and the corresponding history is smaller, * according to the McMillan's order, then it is a cutoff */ if (n && h_cmp (he->h, h) < 0) { #else /* if present in the hash table, then we know h is a cutoff, as we are * sure that the corresponding history is smaller (the ERV order is * total) */ if (n) { // FIXME -- this deosn't work!!! ASSERT (h_cmp (he->h, h) < 0); ASSERT (h_cmp (he->h, h) <= 0); #endif /* deallocate the marking and set history h as a cutoff, whose * corresponding history is he->h */ ASSERT (he); nl_delete (h->marking); h->marking = 0; h->corr = he->h; u.unf.numcutoffs++; return; } /* otherwise, insert h into the table */ h->corr = 0; nhe = gl_malloc (sizeof (struct hash_entry)); nhe->h = h; ls_insert (buckl, &nhe->nod); return; } static void _marking_print (const struct nl *l) { if (! l) return; _marking_print (l->next); PRINT (" %s", ((const struct place*) (l->node))->name); } void marking_print (const struct h *h) { _marking_print (h->marking); }
void h_htoa(hfloat* ha, char* buf, unsigned int ccmax, int radix) { if(h_iszero(ha)) { buf[0]='0'; buf[1]='\0'; return; } const char abc[]="0123456789ABCDEF"; hfloat t; h_init(&t); h_copy(&t, ha); int i,j,k; int exp = 0; bool negexp=false; __int8 digit=0; unsigned __int32 limb; short digitsize; char* pc=buf; memset(buf,0,ccmax); if(ha->s) { *pc='-'; pc++; } //if(t<1) { *pc='0'; pc++; } if(radix==16) digitsize=4; if(radix==8) digitsize=3; if(radix==2) digitsize=1; switch(radix) { case 16: case 8: case 2: exp = ha->e; if(exp<=0) { negexp=true; *pc='0'; pc++; *pc='.'; pc++; exp=-exp; if(exp>=digitsize) for(i=0;i<exp;i+=digitsize) {*pc='0'; pc++; } } digit=0; if(negexp) k=exp%digitsize; else k=digitsize-exp%digitsize; if(k==digitsize) k=0; for(i=0;i<MSIZE;i++) { limb = ha->m[i]; for(j=0;j<32;j++) { if(limb&0x80000000) digit|=1; k++; if(k>=digitsize) { k=0; *pc = abc[digit]; *pc++; digit=0; } exp--; if((exp==0) && !negexp) { *pc='.'; pc++; } digit<<=1; limb<<=1; } } break; case 10: hfloat a,b; h_init(&a); h_init(&b); h_copy(&t, ha); if(t.s!=0) t.s=0; exp = 0; h_copy_d(&b, 0.1); if(t.e<=0) { strcpy(pc,"0."); pc+=2; while(h_cmp(&t,&b)>0) { h_mul_d(&t, 10.0, &t); *pc='0'; pc++; } } else { strcpy(pc, "0"); pc++; } // в начале - 0, для округления с переполнением (999.99999) while(h_cmp_d(&t, 1000000000.0)<=0) { h_div_d(&t, 1000000000.0, &t); exp+=9; } while(h_cmp_d(&t, 1000000.0)<=0) { h_div_d(&t, 1000000.0, &t); exp+=6; } while(h_cmp_d(&t, 1000.0)<=0) { h_div_d(&t, 1000.0, &t); exp+=3; } while(h_cmp_d(&t, 1.0)<=0) { h_div_d(&t, 10.0, &t); exp++; } h_clear(&a); h_clear(&b); unsigned __int8 _e; for(i=0;i<MSIZE*32/4/5;i++) { h_mul_d(&t,100000.0, &t); if( (exp<=5)&&(exp>=0) ) _e=(unsigned __int8)exp; else _e=0; exp-=5; __asm { mov ebx, t.m mov eax, [ebx] mov ecx, 32 sub ecx, t.e getfrac: clc rcr eax, 1 dec cl jnz getfrac mov esi, pc mov ch, _e or ch, 0x80 call ascii4 add esi, ebx mov pc, esi } h_clrat(&t); } // теперь buf содержит наше число в десятичном виде. // округляем его (23.01299999999 -> 23.013) pc = buf+strlen(buf)-1; if(*pc=='9') { k=1; do { if(!isdigit(*pc)) { pc--; continue; } *pc+=k; if(*pc>'9') { *pc='0'; k=1; } else k=0; pc--; } while(k==1); } break; } pc=buf+strlen(buf)-1; while( (*pc=='0')&&(pc!=buf) ) { *pc=0; pc--; } if(*pc=='.') *pc=0; if( (buf[0]=='0')&&(buf[1]!='.') ) memmove(buf, buf+1, strlen(buf)); if( (buf[0]=='-')&&(buf[1]=='0')&&(buf[2]!='.') ) memmove(buf+1, buf+2, strlen(buf)-1); h_clear(&t); }