From ecbd52040570449b5a3201fe54b8ab15d9b62160 Mon Sep 17 00:00:00 2001 From: limw Date: Thu, 14 Jul 2011 21:52:14 +0000 Subject: [PATCH] Fixed more compilation issues. --- .../Scheduling/GC/NON_BAMBOO/MTree/Node.java | 114 +++++++++++++++++ .../GC/NON_BAMBOO/MTree/TestRunner.java | 117 +----------------- 2 files changed, 117 insertions(+), 114 deletions(-) create mode 100644 Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/Node.java diff --git a/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/Node.java b/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/Node.java new file mode 100644 index 00000000..62968488 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/Node.java @@ -0,0 +1,114 @@ +package MTree; + +public class Node { + int m_key; + int m_value; + Node m_left; + Node m_right; + Node m_parent; + + public Node() { + // an empty node + this.m_key = -1; + this.m_value = -1; + this.m_left = null; + this.m_right = null; + this.m_parent = null; + } + + public Node(int key, + int value) { + this.m_key = key; + this.m_value = value; + this.m_left = null; + this.m_right = null; + this.m_parent = null; + } + + public int getKey() { + return this.m_key; + } + + public void setParent(Node p) { + this.m_parent = p; + } + + public void setLeftChild(int key, + int value) { + Node n = new Node(key, value); + this.m_left = n; + n.setParent(this); + } + + public void setRightChild(int key, + int value) { + Node n = new Node(key, value); + this.m_right = n; + n.setParent(this); + } + + public boolean insert(int key, + int value, + boolean candelete) { + if(this.m_key == -1) { + // empty tree + this.m_key = key; + this.m_value = value; + } else { + if(this.m_key == key) { + // collision + replace(key, value); + return false; + } else if(this.m_key > key) { + if(this.m_left == null) { + // no left subtree + if(candelete) { + // replace this node with the new node + replace(key, value); + return false; + } else { + setLeftChild(key, value); + } + } else { + // insert into the left subtree + return this.m_left.insert(key, value, candelete); + } + } else if(this.m_key < key) { + if(this.m_right == null) { + // no right subtree + if(candelete) { + replace(key, value); + return false; + } else { + setRightChild(key, value); + } + } else { + // insert into the right subtree + return this.m_right.insert(key, value, candelete); + } + } + } + return true; + } + + public void replace(int key, + int value) { + Node n = new Node(key, value); + n.m_left = this.m_left; + n.m_right = this.m_right; + n.m_parent = this.m_parent; + if(this.m_parent != null) { + if(this.m_parent.getKey() > key) { + this.m_parent.m_left = n; + } else { + this.m_parent.m_right = n; + } + } + if(this.m_left != null) { + this.m_left.m_parent = n; + } + if(this.m_right != null) { + this.m_right.m_parent = n; + } + } +} diff --git a/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/TestRunner.java b/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/TestRunner.java index 746ea133..9189df39 100644 --- a/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/TestRunner.java +++ b/Robust/src/Benchmarks/Scheduling/GC/NON_BAMBOO/MTree/TestRunner.java @@ -1,3 +1,5 @@ +package MTree; + public class TestRunner extends Thread { int m_index; @@ -32,126 +34,13 @@ public class TestRunner extends Thread { } } - class Node { - int m_key; - int m_value; - Node m_left; - Node m_right; - Node m_parent; - - public Node() { - // an empty node - this.m_key = -1; - this.m_value = -1; - this.m_left = null; - this.m_right = null; - this.m_parent = null; - } - - public Node(int key, - int value) { - this.m_key = key; - this.m_value = value; - this.m_left = null; - this.m_right = null; - this.m_parent = null; - } - - public int getKey() { - return this.m_key; - } - - public void setParent(Node p) { - this.m_parent = p; - } - - public void setLeftChild(int key, - int value) { - Node n = new Node(key, value); - this.m_left = n; - n.setParent(this); - } - - public void setRightChild(int key, - int value) { - Node n = new Node(key, value); - this.m_right = n; - n.setParent(this); - } - - public boolean insert(int key, - int value, - boolean candelete) { - if(this.m_key == -1) { - // empty tree - this.m_key = key; - this.m_value = value; - } else { - if(this.m_key == key) { - // collision - replace(key, value); - return false; - } else if(this.m_key > key) { - if(this.m_left == null) { - // no left subtree - if(candelete) { - // replace this node with the new node - replace(key, value); - return false; - } else { - setLeftChild(key, value); - } - } else { - // insert into the left subtree - return this.m_left.insert(key, value, candelete); - } - } else if(this.m_key < key) { - if(this.m_right == null) { - // no right subtree - if(candelete) { - replace(key, value); - return false; - } else { - setRightChild(key, value); - } - } else { - // insert into the right subtree - return this.m_right.insert(key, value, candelete); - } - } - } - return true; - } - - public void replace(int key, - int value) { - Node n = new Node(key, value); - n.m_left = this.m_left; - n.m_right = this.m_right; - n.m_parent = this.m_parent; - if(this.m_parent != null) { - if(this.m_parent.getKey() > key) { - this.m_parent.m_left = n; - } else { - this.m_parent.m_right = n; - } - } - if(this.m_left != null) { - this.m_left.m_parent = n; - } - if(this.m_right != null) { - this.m_right.m_parent = n; - } - } - } - public static void main(String[] args) { int threadnum = 62; // 56; int size = 40000; int nodenum = size*10; for(int i = 0; i < threadnum; ++i) { TestRunner tr = new TestRunner(i, size, nodenum); - tr.run(); + tr.start(); } } } -- 2.34.1