Example #1
0
 /**
  * @return SocketMemcached
  */
 public function setTimeout($microseconds)
 {
     Assert::isGreater($microseconds, 0);
     $this->timeout = $microseconds;
     if ($this->alive) {
         $seconds = floor($microseconds / 1000);
         $fraction = $microseconds - $seconds * 1000;
         stream_set_timeout($this->link, $seconds, $fraction);
     }
     return $this;
 }
Example #2
0
 public static function getMmult(array $list1, array $list2)
 {
     $list1Size = count($list1);
     $list2Size = count($list2);
     Assert::isGreater($list1Size, 0, "Can't multiply empty matrix");
     Assert::isGreater($list2Size, 0, "Can't multiply empty matrix");
     $list2Width = count($list2[0]);
     $result = [];
     for ($i = 0; $i < $list1Size; $i++) {
         for ($j = 0; $j < $list2Width; $j++) {
             $x = 0;
             for ($k = 0; $k < $list2Size; $k++) {
                 if (isset($list1[$i][$k])) {
                     $l1 = $list1[$i][$k];
                 } else {
                     $l1 = 0;
                 }
                 if (isset($list2[$k][$j])) {
                     $l2 = $list2[$k][$j];
                 } else {
                     $l2 = 0;
                 }
                 $x += $l1 * $l2;
             }
             $result[$i][$j] = $x;
         }
     }
     return $result;
 }
Example #3
0
 public function sort()
 {
     Assert::isGreater(count($this->keys), 0);
     Assert::isNotEmptyArray($this->vector);
     usort($this->vector, [$this, "compare"]);
 }