#!/bin/sh
dieusage() {
echo usage: $0 ALGO [-a AVGSIZE] [-m MINSIZE] [-M MAXSIZE] FILE [FILE2]
exit 1
}
if test $# -le 1; then dieusage; fi
algo="$1"
shift
if test ! -e ./test-"$algo"; then
echo $0: fatal: test-$algo not found >&2
exit 1
fi
calcdedup() {
minus=0
if test "$1" = "-1"; then minus=1; fi
dedup=0
while read -r count hash size <&0; do
count=$(($count - $minus))
size=$(($count * $size))
dedup=$(($dedup + $size))
done
echo dedup: $dedup
}
args=
for arg; do
case "$arg" in
-a|-m|-M)
args="$args $arg $2"
shift 2
;;
-a*|-m*|-M*)
args="$args $arg"
shift
;;
-*)
dieusage
;;
esac
done
echo "* $algo:"
echo $1
./test-$algo $args -H "$1" | sort > $algo.1
uniq -cd $algo.1 | calcdedup -1
if test -n "$2"; then
echo $2
./test-$algo $args -H "$2" | sort | comm -12 $algo.1 - | uniq -c | calcdedup
fi
rm $algo.1