public function initializeStrategy(DistanceInterface $d, array &$docs)
    {
        // the number of documents and the dimensions of the matrix
        $this->L = count($docs);
        // just to hold which document has been removed
        $this->removed = array_fill_keys(range(0, $this->L-1), false);
        // how many distances we must compute
        $elements = (int) ($this->L*($this->L-1))/2;
        // the containers that will hold the distances
        $this->dm = new \SplFixedArray($elements);
        $this->queue = new \SplPriorityQueue();
        $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);

        // for each unique pair of documents calculate the distance and
        // save it in the heap and distance matrix
        for ($x=0;$x<$this->L;$x++) {
            for ($y=$x+1;$y<$this->L;$y++) {
                $index = $this->packIndex($y,$x);
                $tmp_d = $d->dist($docs[$x],$docs[$y]);
                $this->dm[$index] = $tmp_d;
                $this->queue->insert($index, -$tmp_d);
            }
        }
    }
public function initializeStrategy(DistanceInterface $d, array &$docs)
    {
        // the number of documents and the dimensions of the matrix
        $this->L = count($docs);
        // just to hold which document has been removed
        $this->removed = array_fill_keys(range(0, $this->L-1), false);
        // how many distances we must compute
        $elements = (int) ($this->L*($this->L-1))/2;
        // the containers that will hold the distances
        $this->dm = new \SplFixedArray($elements);
        $this->queue = new \SplPriorityQueue();
        $this->queue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);

        // for each unique pair of documents calculate the distance and
        // save it in the heap and distance matrix
        for ($x=0;$x<$this->L;$x++) {
            for ($y=$x+1;$y<$this->L;$y++) {
                $index = $this->packIndex($y,$x);
                $tmp_d = $d->dist($docs[$x],$docs[$y]);
                $this->dm[$index] = $tmp_d;
                $this->queue->insert($index, -$tmp_d);
            }
        }
    }
public function initializeStrategy ( DistanceInterface $ d , array & $ docs ) { // the number of documents and the dimensions of the matrix $ this -> L = count ( $ docs ) ; // just to hold which document has been removed $ this -> removed = array_fill_keys ( range ( 0 , $ this -> L - 1 ) , false ) ; // how many distances we must compute $ elements = ( int ) ( $ this -> L * ( $ this -> L - 1 ) ) / 2 ; // the containers that will hold the distances $ this -> dm = new \ SplFixedArray ( $ elements ) ; $ this -> queue = new \ SplPriorityQueue ( ) ; $ this -> queue -> setExtractFlags ( \ SplPriorityQueue :: EXTR_BOTH ) ; // for each unique pair of documents calculate the distance and // save it in the heap and distance matrix for ( $ x = 0 ; $ x < $ this -> L ; $ x ++ ) { for ( $ y = $ x + 1 ; $ y < $ this -> L ; $ y ++ ) { $ index = $ this -> packIndex ( $ y , $ x ) ; $ tmp_d = $ d -> dist ( $ docs [ $ x ] , $ docs [ $ y ] ) ; $ this -> dm [ $ index ] = $ tmp_d ; $ this -> queue -> insert ( $ index , - $ tmp_d ) ; } } }
Initialize the distance matrix and any other data structure needed
to calculate the merges later.

@param DistanceInterface $d    The distance metric used to calculate the distance matrix
@param array             $docs The docs to be clustered
Initialize the distance matrix and any other data structure needed to calculate the merges later .