コード例 #1
0
ファイル: Demo5.php プロジェクト: EdenChan/Instances
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on succes; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Demonstration program number 5.\n");
     $status = 0;
     GeneralTree::main($args);
     BinaryTree::main($args);
     NaryTree::main($args);
     BinarySearchTree::main($args);
     AVLTree::main($args);
     MWayTree::main($args);
     BTree::main($args);
     return $status;
 }
コード例 #2
0
<?php

include 'db.php';
include 'queries.php';
include 'classes.php';
if (isset($_POST['keyword'])) {
    $keyword = $_POST['keyword'];
    $keys = explode(' ', $keyword);
    /*create dictionary starts*/
    $t_create_start = microtime(true);
    $qobj = new Queries();
    $btree = new BTree();
    $btreeop = new BOperation();
    $content = array();
    $contentlist = array();
    $docidlist = array();
    $doclist = $qobj->retrieve_documents($conn);
    while ($row = $doclist->fetch()) {
        echo $row['doc_id'] . " => ";
        echo $row['content'];
        $content = explode(' ', $row['content']);
        array_push($docidlist, $row['doc_id']);
        array_push($contentlist, $content);
        echo "<br>";
    }
    $collection = array_combine($docidlist, $contentlist);
    $dictionary = array();
    $l = array();
    // create dictionary list
    foreach ($collection as $doc => $content) {
        foreach ($content as $i => $word) {
コード例 #3
0
ファイル: BTree.php プロジェクト: EdenChan/Instances
 /**
  * Inserts the specified object and B-tree into this B-tree node.
  *
  * @param object IComparable $obj
  * A key smaller than all the keys in the specified B-tree.
  * @param object BTree $child The specified B-tree.
  */
 protected function insertPair(IComparable $obj, BTree $child)
 {
     $index = $this->findIndex($obj);
     if (!$this->isFull()) {
         $this->insertPairAt($index + 1, $obj, $child);
         ++$this->count;
     } else {
         list($extraKey, $extraTree) = $this->insertPairAt($index + 1, $obj, $child);
         if ($this->parent === NULL) {
             $left = new BTree($this->getM());
             $right = new BTree($this->getM());
             $left->attachLeftHalfOf($this);
             $right->attachRightHalfOf($this);
             $right->insertPair($extraKey, $extraTree);
             $this->attachSubtree(0, $left);
             $this->key[1] = $this->key[intval(($this->getM() + 1) / 2)];
             $this->attachSubtree(1, $right);
             $this->count = 1;
         } else {
             $this->count = intval(($this->getM() + 1) / 2 - 1);
             $right = new BTree($this->getM());
             $right->attachRightHalfOf($this);
             $right->insertPair($extraKey, $extraTree);
             $this->parent->insertPair($this->key[intval(($this->getM() + 1) / 2)], $right);
         }
     }
 }
コード例 #4
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;
 }