예제 #1
0
         $word = strtolower($word);
         if (array_key_exists($word, $dictionary)) {
             $l = $dictionary[$word];
             array_push($l, $doc);
             $contentlist = array($word => $l);
             $dictionary = array_replace($dictionary, $contentlist);
         } else {
             $dictionary[$word] = array($doc);
         }
     }
 }
 /*create dictionary ends*/
 /*btree creation starts*/
 foreach ($dictionary as $w => $d) {
     $item = array($w, $d);
     $btree->insert($item);
 }
 $t_create_end = microtime(true);
 /*btree creation ends*/
 /*searching starts*/
 $t_search_start = microtime(true);
 $x = array();
 echo "<br>We have";
 foreach ($keys as $keyword) {
     echo ", {$keyword}";
     $keyword = strtolower($keyword);
     $temp = $btree->currentNode();
     $d = $btreeop->search($temp, $keyword);
     foreach ($d as $w) {
         array_push($x, $w);
     }
예제 #2
0
파일: BTree.php 프로젝트: byjg/xmlnuke
 public static function load($filename)
 {
     $btree = null;
     if (!file_exists($filename)) {
         return null;
     }
     $lines = file($filename);
     foreach ($lines as $i => $linha) {
         if (substr($linha, 0, 1) != '+') {
             $bnode = new BTreeNode($linha);
             $btree = BTree::insert($bnode, $btree);
         } else {
             $bnode->addValue(substr($linha, 1));
         }
     }
     return $btree;
 }