_binary From a61b4e6f0f9709819844251a52c920af05af4bd9 Mon Sep 17 00:00:00 2001
From: Akshat Kukreti <akshatkukreti@gmail.com>
Date: Thu, 23 May 2013 14:11:29 -0700
Subject: [PATCH] changes

---
 bin/queue_server.php |  4 ++--
 lib/btree.php        | 64 ++++++++++++++++++++++++++++++++++++++++++++--------
 tests/btree_test.php | 10 ++++----
 3 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/bin/queue_server.php b/bin/queue_server.php
index a2270eb..edc5a4d 100755
--- a/bin/queue_server.php
+++ b/bin/queue_server.php
@@ -1652,7 +1652,7 @@ class QueueServer implements CrawlConstants, Join
         foreach($cache_page_validation_data as $data) {
             $link = $data[0];
             $value = $data[1];
-            $key = crawlHash($link);
+            $key = crawlHash($link, true);
             $entry = array($key, $value);
             $this->btree->insert($entry);
         }
@@ -2216,7 +2216,7 @@ class QueueServer implements CrawlConstants, Join
                   found, the ETag is appended to the URL so that it can be
                   processed by the fetcher.
                  */
-                $key = crawlHash($url);
+                $key = crawlHash($url, true);
                 $value = $this->btree->findValue($key);
                 if($value !== null) {
                     $cache_validation_data = $value[1];
diff --git a/lib/btree.php b/lib/btree.php
index b2442e3..6f494ab 100644
--- a/lib/btree.php
+++ b/lib/btree.php
@@ -33,11 +33,6 @@
  */

 /**
- * Load Node class
- */
-require_once(BASE_DIR.'/lib/btree_node.php');
-
-/**
  * Default value of minimum degree. The minimum degree determines the minimum
  * and maximum number of keys and child nodes, for nodes
  * other than root node
@@ -103,7 +98,7 @@ class BTree
             $this->id_count = unserialize(file_get_contents($this->dir.
                 "/count.txt"));
         } else {
-            $this->root = new Node();
+            $this->root = new BTNode();
             $this->root->id = "root";
             $this->id_count = 1;
         }
@@ -295,7 +290,7 @@ class BTree
     function bTreeSplitChild($parent, $i, $child)
     {
         $this->id_count += 1;
-        $temp = new Node();
+        $temp = new BTNode();
         $temp->id = $this->id_count;
         $this->saveNodeCount();
         $temp->is_leaf = $child->is_leaf;
@@ -346,7 +341,7 @@ class BTree
     function createEmptyParentNode()
     {
         $this->id_count += 1;
-        $temp = new Node();
+        $temp = new BTNode();
         $temp->id = $this->id_count;
         $this->saveNodeCount();
         $temp->is_leaf = false;
@@ -753,4 +748,55 @@ class BTree
         }
         return $siblings;
     }
-}
\ No newline at end of file
+}
+
+/**
+ * This class implements B-Tree nodes used in the B-Tree implementation in
+ * btree.php
+ */
+
+class BTNode
+{
+    /**
+     * Storage for id of a B-Tree node
+     * @var int
+     */
+    var $id;
+
+    /**
+     * Flag for checking if node is a leaf node or internal node
+     * @var boolean
+     */
+    var $is_leaf;
+
+    /**
+     * Storage for keeping track of node ids
+     * @var int
+     */
+    var $count;
+
+    /**
+     * Storage for key-value pairs in a B-Tree node
+     * @var array
+     */
+    var $keys;
+
+    /**
+     * Storage for links to child nodes in a B-Tree node
+     * @var array
+     */
+    var $links;
+
+    /**
+     * Creates and initializes an empty leaf node with id -1
+     * @var int
+     */
+    function __construct()
+    {
+        $this->id = -1;
+        $this->is_leaf = true;
+        $this->count = 0;
+        $this->keys = null;
+        $this->links = null;
+    }
+}
diff --git a/tests/btree_test.php b/tests/btree_test.php
index d870a19..b9cf949 100644
--- a/tests/btree_test.php
+++ b/tests/btree_test.php
@@ -170,8 +170,8 @@
     {
         //Insert values
         for($i = 1;$i <= NUM_VALS;$i++) {
-            $value = crawlHash(rand(1, 1000));
-            $key = crawlHash($value);
+            $value = crawlHash(rand(1, 1000), true);
+            $key = crawlHash($value, true);
             $this->test_objects['FILE1']->insert(array($key, $value));
         }

@@ -198,8 +198,8 @@
         //Insert values
         $key_value_pairs = array();
         for($i = 1;$i <= NUM_VALS;$i++) {
-            $value = crawlHash(rand(1, 1000));
-            $key = crawlHash($value);
+            $value = crawlHash(rand(1, 1000), true);
+            $key = crawlHash($value, true);
             $this->test_objects['FILE1']->insert(array($key, $value));
             $key_value_pairs[] = array($key, $key);
         }
@@ -222,4 +222,4 @@
         }
     }

- }
\ No newline at end of file
+ }
--
1.7.11.msysgit.1

