/** * This method tests if the TreeMap is sorted * correctly by the passed Comparator. * * return void */ public function testSortedByComparator() { // initialize a new TreeMap $map = new TreeMap(new TestComparator()); // add several values $map->add(0, 3); $map->add(1, 2); $map->add(2, 1); // initialize the values $counter = 1; $keys = 0; // check the sort order foreach ($map as $key => $value) { $this->assertEquals($keys++, $key); $this->assertEquals($counter++, $value); } }
function main($node = 0, $width = 300, $height = 300, $callback = '') { global $db; // Create some data for us to plot $items = array(); // 0 = life $subtree_root = $node; if ($node == 0) { $label = 'Life'; $parent_id = 0; $path = "/"; } else { // get parent and label for this node $sql = 'SELECT parent_id, path FROM col_tree WHERE col_tree.record_id = ' . $subtree_root . ' LIMIT 1'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __LINE__ . "]: " . $sql); } $parent_id = $result->fields['parent_id']; $path = $result->fields['path']; $sql = 'SELECT `name` FROM taxa WHERE record_id = ' . $subtree_root . ' LIMIT 1'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __LINE__ . "]: " . $sql); } $label = $result->fields['name']; } // Get children of this node $sql = 'SELECT * FROM col_tree INNER JOIN taxa USING(record_id) WHERE col_tree.parent_id = ' . $subtree_root . ' AND (col_tree.record_id <> 0) ORDER BY taxa.name'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __LINE__ . "]: " . $sql); } while (!$result->EOF) { $c = num_documents($result->fields['record_id']); /* if ($c > 0) { $c = log10($c)+1; }*/ $i = new Item(log10($result->fields['weight'] + 1), $result->fields['name'] . ' ' . $c, $result->fields['record_id'], $result->fields['right_id'] - $result->fields['left_id'] == 1, n2colour($c)); array_push($items, $i); $result->MoveNext(); } // Treemap bounds $tm = new TreeMap(0, 0, $width, $height, $items); $tm->compute(); $obj = new stdclass(); $obj->panels = $tm->drawme; $obj->width = $width; $obj->height = $height; $obj->id = $node; $obj->parent_id = $parent_id; $obj->label = $label; $obj->path = $path; $json = json_encode($obj); if ($callback != '') { echo $callback . '('; } echo $json; if ($callback != '') { echo ')'; } }