# change version number in hashes.c !!!

package.checkclib('hashes');  # has C dynamic link library been found ?

hashes.collisions := proc(s :: sequence, f :: procedure, iters, factor) is
   local n, slots, b, p, q, t0, t1;
   if unassigned bags then import bags fi;
   n, slots -> size s;
   if not math.isprime(n) then
      slots := math.nextprime(n)
   fi;
   if unassigned iters then
      iters := 1
   elif iters :- number and not isnonposint(iters) then
      error('Error in `hashes.collision`: third argument is not a positive integer.')
   fi;
   if unassigned factor then
      factor := 2
   elif factor :- number and not isnonposint(factor) then
      error('Error in `hashes.collision`: fourth argument is not a positive integer.')
   fi;
   mul slots, factor;
   t0 := time();
   to iters do
      b := bags.bag();
      for i in s do
         bags.include(b, f(i, slots))
      od
   od;
   t1 := time();
   p, q := bags.attrib(b);
   return q/p, t1 - t0
end;