Skip to content
Snippets Groups Projects
Commit 946e972b authored by Ray Liu's avatar Ray Liu
Browse files
web

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
parents a01b15e5 d2004c92
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -3,12 +3,23 @@ package search;
import java.util.ArrayList;
import data.Record;
<<<<<<< HEAD
import sort.GeneralRange;
=======
import java.lang.Math;
>>>>>>> branch 'web' of git@gitlab.cas.mcmaster.ca:schankuc/2XB3.git
public class BasicSearchResult {
private ArrayList<Record> results;
private final double time;
private BST<Integer, Integer> histogram;
private Integer sum;
private
public static void main(String[] args) {
//Graph g = new Graph();
}
public BasicSearchResult(ArrayList<Record> results, double time) {
this.results = results;
......@@ -16,7 +27,7 @@ public class BasicSearchResult {
}
public Iterable<Record> results() {
return (Iterable<Record>) results;
return (Iterable<Record>) results;
}
public int n() {
......@@ -41,4 +52,27 @@ public class BasicSearchResult {
}
return this.sum;
}
<<<<<<< HEAD
/**
*
* @param area
*/
public Iterable<RecordCluster> cluster(double area){
}
private ArrayList<GeneralRange> ranges(double lat, double lon, double area){
ArrayList<GeneralRange>()
}
=======
private double lngRange(double dist, double lat){
return dist/(Math.cos(lat)*222);
}
private double latRange(double dist){
return (dist/111)/2;
}
>>>>>>> branch 'web' of git@gitlab.cas.mcmaster.ca:schankuc/2XB3.git
}
......@@ -8,13 +8,7 @@ public class Graph {
public static void main(String[] args) {
Graph g = new Graph(5);
g.addEdge(4, 3);
g.addEdge(2, 3);
g.addEdge(1, 2);
g.addEdge(0, 2);
for(int i = 0; i < 5; i++)
System.out.println(g.adj(i));
}
public Graph(int V){
......
......@@ -16,9 +16,22 @@ public class RedBlackTree<Key, Value> {
Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}};
RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1);
for(int i = 0; i < x.length; i++){
// Add first 5 nodes, expected get(6) result is null
for(int i = 0; i < 4; i++){
myTree.put(x[i]);
}
assert(myTree.get((Comparable<Integer>) 6) == null);
// Add remaining nodes, expected get(6) result is {6, 6}
for(int i = 5; i < x.length; i++){
//System.out.println(x[i][0]);
myTree.put(x[i]);
}
System.out.println("Root: " + myTree.root().key());
System.out.println("myTree.get(6).key(): " + (Integer) myTree.get((Comparable<Integer>) 6).key());
Node h = myTree.root();
System.out.println(h.key());
while (h.left() != null) {
......@@ -26,6 +39,11 @@ public class RedBlackTree<Key, Value> {
h = h.left();
}
}
<<<<<<< HEAD
=======
>>>>>>> 459508d... get method added to redBlackTree
/**
......@@ -38,6 +56,41 @@ public class RedBlackTree<Key, Value> {
field = fld;
}
/**
* Wrapper method for retrieving the node that matches a desired key
* @param key Key pointing to the desired node
* @return A node containing who's key matches the input
*/
public Node<Key, Value> get(Comparable<Key> key) {
return get(this.root, key);
}
/**
* Finds the node in a tree whose key matches a desired key (if the matching node exists)
* @param node Root of the subtree being searched
* @param key Desired key to be searched for in a tree
* @return The node containing the key, returns null if the key is not found
*/
private Node<Key, Value> get(Node<Key, Value> node, Comparable<Key> key) {
if (node.key() == key)
return node;
// If key is greater than current node, look right
if (this.compare.compare(node.key(), key) < 0)
if (node.right() != null)
return get(node.right(), key);
else
return null;
// If key is smaller than current node, look left
else if (this.compare.compare(node.key(), key) > 0)
if (node.left() != null)
return get(node.left(), key);
else
return null;
// If node == null, key does not exist in the tree
return null;
}
/**
* Getter method for the root of a tree
* @return The root of a tree object
......
/**
*
*/
package search;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author HaleyGlavina
*
*/
public class RedBlackTreeTest {
private GeneralCompare<Integer> b1;
private Field<Integer, Integer[]> fld;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
b1 = (a1, a2) -> (Integer) a1 - (Integer) a2;
fld = (a1) -> (Integer) a1[0];
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
/**
* Test method for {@link search.RedBlackTree#root()}.
*/
@Test
public void testRoot() {
Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}};
RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1);
// Add first 5 nodes, expected root is 2
for(int i = 0; i < 4; i++){
myTree.put(x[i]);
}
assert((Integer) myTree.root().key() == 2);
// Add remaining nodes, expected root is 4
for(int i = 5; i < x.length; i++){
myTree.put(x[i]);
}
assert((Integer) myTree.root().key() == 4);
}
/**
* Test method for {@link search.RedBlackTree#get(Node<Key, Value> node, Comparable<Key> key)}.
*/
@Test
public void testGet() {
Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}};
RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1);
// Add first 5 nodes, expected get(6) result is null
for(int i = 0; i < 4; i++){
myTree.put(x[i]);
}
assert(myTree.get((Comparable<Integer>) 6) == null);
// Add remaining nodes, expected get(6) result is {6, 6}
for(int i = 5; i < x.length; i++){
myTree.put(x[i]);
}
assert(myTree.get(6).key() == (Comparable<Integer>) 6);
}
/**
* Test method for {@link search.RedBlackTree#put(java.lang.Object)}.
*/
@Test
public void testPut() {
Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}};
RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1);
for(int i = 0; i < x.length; i++){
myTree.put(x[i]);
}
Node h = myTree.root();
// Check if right-most branch of tree matches what is expected
Integer[] expect = {4, 6, 7, 8, 9};
for (int i = 0 ; i < expect.length ; i++) {
assert(expect[i] == h.key());
h = h.right();
}
}
/**
* Test method for {@link search.RedBlackTree#rotateLeft(search.Node)}.
*/
@Test
public void testRotateLeft() {
RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1);
Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}};
myTree.put(x[0]);
myTree.put(x[1]);
assert((Integer) myTree.root().key() == 1);
// Check if left rotation changes the root of the tree as expected
myTree.put(x[2]);
myTree.put(x[3]);
assert((Integer) myTree.root().key() == 2);
}
/**
* Test method for {@link search.RedBlackTree#rotateRight(search.Node)}.
*/
@Test
public void testRotateRight() {
RedBlackTree<Integer, Integer[]> myTree = new RedBlackTree<Integer, Integer[]>(fld, b1);
Integer[][] x = {{1, 1}, {2, 2}, {3, 3}, {4, 4}};
myTree.put(x[3]);
myTree.put(x[2]);
assert((Integer) myTree.root().key() == 4);
// Check if right rotation changes the root of the tree as expected
myTree.put(x[1]);
myTree.put(x[0]);
assert((Integer) myTree.root().key() == 3);
}
}
......@@ -33,11 +33,18 @@ function callUpdateSci(object){
function populateDropdown(childTagID, nodeList, subnode){
var x, y, content="";
for (var i in nodeList[subnode]["taxonName"]){
x = nodeList[subnode]["taxonId"][i];
y = nodeList[subnode]["taxonName"][i];
content += '"<option value="' + x + '">' + y + '</option>';
console.log(nodeList[subnode]);
if(nodeList[subnode] != null){
for (var i in nodeList[subnode]["taxonName"]){
x = nodeList[subnode]["taxonId"][i];
y = nodeList[subnode]["taxonName"][i];
content += '"<option value="' + x + '">' + y + '</option>';
}
}
// else {
// content
// }
document.getElementById(childTagID).innerHTML = content;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment