changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > ventivac / appl/lib/rabin.b

revision 144: 207beea1188c
parent 115: 1c52c2978769
     1.1--- a/appl/lib/rabin.b	Mon Aug 20 18:18:59 2007 +0200
     1.2+++ b/appl/lib/rabin.b	Thu Aug 30 14:13:56 2007 +0200
     1.3@@ -39,46 +39,46 @@
     1.4 		return (nil, sprint("bad min/max"));
     1.5 	if(min < rcfg.width)
     1.6 		return (nil, "min < width");
     1.7-	c := ref Rfile(b, rcfg, min, max, array[max+rcfg.width] of byte, 0, 0, big 0);
     1.8+	r := ref Rfile(b, rcfg, min, max, array[max+rcfg.width] of byte, 0, 0, big 0);
     1.9 
    1.10-	(prime, width, mod) := (c.rcfg.prime, c.rcfg.width, c.rcfg.mod);
    1.11-	while(c.n < width) {
    1.12-		ch := c.b.getb();
    1.13+	(prime, width, mod) := (r.rcfg.prime, r.rcfg.width, r.rcfg.mod);
    1.14+	while(r.n < width) {
    1.15+		ch := r.b.getb();
    1.16 		if(ch == ERROR)
    1.17 			return (nil, sprint("reading: %r"));
    1.18 		if(ch == EOF)
    1.19 			break;
    1.20-		c.buf[c.n] = byte ch;
    1.21-		c.state = (prime*c.state + ch) % mod;
    1.22-		c.n++;
    1.23+		r.buf[r.n] = byte ch;
    1.24+		r.state = (prime*r.state + ch) % mod;
    1.25+		r.n++;
    1.26 	}
    1.27-	return (c, nil);
    1.28+	return (r, nil);
    1.29 }
    1.30 
    1.31-Rfile.read(c: self ref Rfile): (array of byte, big, string)
    1.32+Rfile.read(r: self ref Rfile): (array of byte, big, string)
    1.33 {
    1.34-	(prime, width, mod) := (c.rcfg.prime, c.rcfg.width, c.rcfg.mod);
    1.35+	(prime, width, mod) := (r.rcfg.prime, r.rcfg.width, r.rcfg.mod);
    1.36 	for(;;) {
    1.37-		ch := c.b.getb();
    1.38+		ch := r.b.getb();
    1.39 		if(ch == ERROR)
    1.40 			return (nil, big 0, sprint("reading: %r"));
    1.41 		if(ch == EOF) {
    1.42-			d := c.buf[:c.n];
    1.43-			off := c.off;
    1.44-			c.n = 0;
    1.45-			c.off += big len d;
    1.46+			d := r.buf[:r.n];
    1.47+			off := r.off;
    1.48+			r.n = 0;
    1.49+			r.off += big len d;
    1.50 			return (d, off, nil);
    1.51 		}
    1.52-		c.buf[c.n] = byte ch;
    1.53-		c.state = (mod+prime*c.state + ch - c.rcfg.tab[int c.buf[c.n-width]]) % mod;
    1.54-		c.n++;
    1.55-		if(c.n-width >= c.max || (c.n-width >= c.min && c.state == mod-1)) {
    1.56-			d := array[c.n-width] of byte;
    1.57-			d[:] = c.buf[:len d];
    1.58-			off := c.off;
    1.59-			c.buf[:] = c.buf[c.n-width:c.n];
    1.60-			c.n = width;
    1.61-			c.off += big len d;
    1.62+		r.buf[r.n] = byte ch;
    1.63+		r.state = (mod+prime*r.state + ch - r.rcfg.tab[int r.buf[r.n-width]]) % mod;
    1.64+		r.n++;
    1.65+		if(r.n-width >= r.max || (r.n-width >= r.min && r.state == mod-1)) {
    1.66+			d := array[r.n-width] of byte;
    1.67+			d[:] = r.buf[:len d];
    1.68+			off := r.off;
    1.69+			r.buf[:] = r.buf[r.n-width:r.n];
    1.70+			r.n = width;
    1.71+			r.off += big len d;
    1.72 			return (d, off, nil);
    1.73 		}
    1.74 	}