- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
#define poff acurp + curp * (nSQs+2) /*probs: offset*/
long psum() {return c(poff+ 1);} long pmax() {return c(poff+2);}
long pn (long n) {return c(poff+2+n); }
void setp (long n, long x){set (poff+2+n, x);} /*prob changes:*/
void setmax (long x){set (poff+2, x);} /*metasearching*/
void setsum (long x){set (poff+1, x);}
long get2ndmax() {long n= poff+2, x=pmax(), m=n, s=0,end=n+nSQs;
do {n++;} while (c(n) != x); /*find 2nd-highest <=pmax*/
do {m++; if (s < c(m) && m !=n) s= c(m);}/*jue tncheck?*/
while (s < x && m < end); return s;}
void addtoSQ(long i, long val) {long x; /*increase prob of ith SQ*/
if (val < 1 || i >nSQs || i<1) return; /*not possible!*/
x = psum()+val;if (x > maxint) return; /*has max normalizer*/
setsum (x); /*normalizer +*/ x = pn(i)+val; setp(i, x);
if (x > pmax()) setmax (x);} /*maximal SQprob has increased */
void subofSQ(long i, long val) {long x; /*decrease prob of ith SQ*/
if (val < 1 || i >nSQs || i<1) return; /*not possible!*/
x = pn(i)-val; if (x < 0) return;/*no neg probabilities!*/
setsum (psum()- val); setp(i,x);/*don't check if =0!*/
if (x + val == pmax()) setmax (get2ndmax());} /*change of max*/
void incSQ() {long i= top(); addtoSQ(i,1);} /*top, not pop!*/
void decSQ() {long i= top(), x,y,z; /*decrem prob of the SQ*/
if (i> nSQs || i< 1) return;/*no such search Q number known*/
x = pn(i); if (x==0) return; /*SQ: already 0*/
y = psum(); z = pmax();
if (x == 1 && y <= z+1) stop /*leave at least 2 SQs*/
if (x == z) setmax (get2ndmax()); /*change of max*/
setp(i, x-1); setsum (y-1);} /*normalizer -1*/
long upSQ; /*SQ probability:enumerator += upSQ: increase*/
void oldSQ() {long a=pop()+ndecl, n,i; if(a<0||a> oldp)stop/*bad*/
n=old[a].size; a=old[a].start;/*all SQs of old nondecl: +upSQ*/
tncheck n+=a; for(i=a;i<n;i++)addtoSQ(SQ[q[i].Q], upSQ);}
void setpat() {long i= pop(); /*instantiate my search pattern*/
if (i<0 || i > patp) stop /*no such search pattern exists*/
set (acurp,i);}/*next SQ-search defined via new probabilities!*/
void pupat() {long i = apatp; /*push search pattern*/
if (i>maxpat) stop i++; set(apatp,i); /*not too many?*/
cpabn (poff+1, acurp + 1 + i *(2+ nSQs), 2 + nSQs,
acurp + 1, aendpats); }
void popat() {long i= apatp; if(i==0) stop
set(apatp,i-1); push(i); } /*pop search pattern*/