Пример #1
0
 public function test($repeat = 100)
 {
     while ($repeat--) {
         $keep1 = array();
         $keep2 = array();
         $ll1 = new HyperLogLog\MinHash();
         $ll2 = new HyperLogLog\MinHash();
         $total = 0;
         while (1) {
             $total++;
             $rand = $this->random();
             $keep1[$rand] = 1;
             $ll1->add($rand);
             $rand = $this->random();
             $keep2[$rand] = 1;
             $ll2->add($rand);
             if (($count = count($keep2)) >= $this->i) {
                 break;
             }
         }
         $intersection = \HyperLogLog\Utils\MinHashIntersector::count(array($ll1, $ll2));
         $actual = count(array_intersect_key($keep1, $keep2));
         if ($actual == 0 || $intersection == 0) {
             continue;
         }
         $ll1->union($ll2);
         $total = $ll1->count();
         $this->average[0] += $actual;
         $this->average[1] += $intersection;
         $this->average[2] += $total;
         $this->results[] = array($actual, $intersection, $total);
     }
 }
Пример #2
0
 public function test($repeat = 100)
 {
     while ($repeat--) {
         $ll1 = new HyperLogLog\MinHash();
         $ll2 = new HyperLogLog\MinHash();
         $i = 100000000 + $this->random();
         $r = mt_rand(1, 4);
         $end = $i + $this->i * $r;
         $actual = 0;
         $overlap = 0;
         while ($i <= $end) {
             $ll1->add($i);
             if (++$overlap === 2) {
                 $overlap = 0;
                 $ll2->add($i);
                 $actual++;
             }
             $i += $r;
         }
         $intersection = \HyperLogLog\Utils\MinHashIntersector::count(array($ll1, $ll2));
         $ll1->union($ll2);
         $total = $ll1->count();
         $this->average[0] += $actual;
         $this->average[1] += $intersection;
         $this->average[2] += $total;
         $this->results[] = array($actual, $intersection, $total);
     }
 }