changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: minor things

changeset 87: afca2ca2ff3a
parent 86: 7bf17e4341ab
child 88: 9cd17b4554ae
author: Mechiel Lukkien <mechiel@ueber.net>
date: Thu, 19 Jul 2007 21:45:12 +0200
files: appl/cmd/rabinparams.b appl/cmd/testrabin.b appl/lib/rabin.b
description: minor things
     1.1--- a/appl/cmd/rabinparams.b	Wed Jul 18 20:23:35 2007 +0200
     1.2+++ b/appl/cmd/rabinparams.b	Thu Jul 19 21:45:12 2007 +0200
     1.3@@ -13,7 +13,7 @@
     1.4 print, sprint, fprint, fildes: import sys;
     1.5 Rcfg, Rfile: import rabin;
     1.6 
     1.7-bflag, dflag, vflag: int;
     1.8+bflag, dflag, vflag, iflag: int;
     1.9 prime, mod, width, mask, min, max: int;
    1.10 rcfg: ref Rcfg;
    1.11 berr: ref Iobuf;
    1.12@@ -48,11 +48,12 @@
    1.13 	bounds = array[256] of array of (array of byte, int);
    1.14 
    1.15 	arg->init(args);
    1.16-	arg->setusage(arg->progname()+" [-bv] [-p prime] [-n width] [-m mod] [-k mask] [-s min] [-S max] dir ...");
    1.17+	arg->setusage(arg->progname()+" [-biv] [-p prime] [-n width] [-m mod] [-k mask] [-s min] [-S max] dir ...");
    1.18 	while((c := arg->opt()) != 0)
    1.19 		case c {
    1.20 		'b' =>	bflag++;
    1.21 		'd' =>	dflag++;
    1.22+		'i' =>	iflag++;
    1.23 		'p' =>	prime = int arg->earg();
    1.24 		'n' =>	width = int arg->earg();
    1.25 		'm' =>	mod = int arg->earg();
    1.26@@ -111,8 +112,11 @@
    1.27 	if(vflag)
    1.28 		print("walk %s\n", path);
    1.29 	fd := sys->open(path, Sys->OREAD);
    1.30-	if(fd == nil)
    1.31+	if(fd == nil) {
    1.32+		if(iflag)
    1.33+			return;
    1.34 		fail(sprint("opening %s: %r", path));
    1.35+	}
    1.36 	(ok, dir) := sys->fstat(fd);
    1.37 	if(ok < 0)
    1.38 		fail(sprint("fstat %s: %r", path));
     2.1--- a/appl/cmd/testrabin.b	Wed Jul 18 20:23:35 2007 +0200
     2.2+++ b/appl/cmd/testrabin.b	Thu Jul 19 21:45:12 2007 +0200
     2.3@@ -33,7 +33,7 @@
     2.4 	rabin->init(bufio);
     2.5 
     2.6 	p := 269;
     2.7-	m := 1<<10;
     2.8+	m := 1<<13;
     2.9 	n := 3;
    2.10 	mask := m-1;
    2.11 	min := 1024;
     3.1--- a/appl/lib/rabin.b	Wed Jul 18 20:23:35 2007 +0200
     3.2+++ b/appl/lib/rabin.b	Thu Jul 19 21:45:12 2007 +0200
     3.3@@ -15,7 +15,6 @@
     3.4 	bufio = b;
     3.5 }
     3.6 
     3.7-
     3.8 modpower(base, n, mod: int): int
     3.9 {
    3.10 	power := 1;
    3.11@@ -30,11 +29,11 @@
    3.12 	if((mod & (mod-1)) != 0)
    3.13 		return (nil, "mod is not power of 2");
    3.14 
    3.15-	power := modpower(prime, width-1, mod);
    3.16+	power := modpower(prime, width, mod);
    3.17 say(sprint("power=%d", power));
    3.18 
    3.19 	for(i := 0; i < 256; i++) {
    3.20-		rcfg.tab[i] = (i * power) & (mod - 1);
    3.21+		rcfg.tab[i] = (i * power) & (mod-1);
    3.22 say(sprint("tab[%d] = %d", i, rcfg.tab[i]));
    3.23 	}
    3.24 say(sprint("mod=%d prime=%d width=%d mask=%d", rcfg.mod, rcfg.prime, rcfg.width, rcfg.mask));
    3.25@@ -60,14 +59,12 @@
    3.26 		if(ch == EOF)
    3.27 			break;
    3.28 		c.buf[c.n] = byte ch;
    3.29-
    3.30 say(sprint("i=%d prev=%d width=%d data[i]=%d modpower=%d prime=%d mod=%d", c.n, c.state, width, int c.buf[c.n], modpower(prime, width-1-c.n, mod), prime, mod));
    3.31-		c.state = (c.state + ch * modpower(prime, width-1-c.n, mod)) & (mod-1);
    3.32+		c.state += ch*modpower(prime, width-1-c.n, mod);
    3.33 		c.n++;
    3.34 	}
    3.35-
    3.36+	c.state &= mod-1;
    3.37 say(sprint("initial state=%d", c.state));
    3.38-
    3.39 	return (c, nil);
    3.40 }
    3.41 
    3.42@@ -86,7 +83,7 @@
    3.43 			return (d, off, nil);
    3.44 		}
    3.45 		c.buf[c.n] = byte ch;
    3.46-		new := (prime * (c.state - c.rcfg.tab[int c.buf[c.n-width]]) + ch) & (mod-1);
    3.47+		new := (prime*c.state + ch - c.rcfg.tab[int c.buf[c.n-width]]) & (mod-1);
    3.48 		c.n++;
    3.49 		c.state = new;
    3.50 		if(c.n-width >= c.max || (c.n-width >= c.min && (new & mask) == mask)) {