Skip to content
This repository was archived by the owner on Aug 12, 2018. It is now read-only.

Commit 49f79fe

Browse files
author
slmyers
committed
cleaning up
2 parents 3398aa2 + 3f1688d commit 49f79fe

File tree

8 files changed

+254
-45
lines changed

8 files changed

+254
-45
lines changed

CompareResults.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
import java.util.ArrayList;
12

23
public class CompareResults{
3-
public ResultSet set_1;
4-
public ResultSet set_2;
4+
public ResultSet hashSet;
5+
public ResultSet treeSet;
6+
public ArrayList<Result> difference;
57

6-
public CompareResults(ResultSet set_1, ResultSet set_2){
7-
this.set_1 = set_1;
8-
this.set_2 = set_2;
8+
public CompareResults(ResultSet hashSet, ResultSet treeSet){
9+
this.hashSet = hashSet;
10+
this.treeSet = treeSet;
11+
this.difference = new ArrayList<Result>();
912
}
1013

1114
public final boolean eqv(){
15+
for(Result r : treeSet.getResults()){
16+
if(!hashSet.getResults().contains(r)){
17+
difference.add(r);
18+
}
19+
}
20+
21+
if(difference.size() == 0){
22+
return true;
23+
}
24+
25+
System.out.println("=================================");
26+
System.out.println("there are " + difference.size() + " results found in tree that are not in hash");
27+
28+
for(Result r : difference){
29+
r.toString();
30+
}
1231
return false;
1332
}
1433
}

DataBase.java

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
public class DataBase{
1111
private static final int NO_RECORDS = 100000;
12+
private static final int NO_RECORDS_TEST = 10;
1213
public static final String DATABASE_DIR = "./tmp/user_db";
1314
public static final String PRIMARY_TABLE = "./tmp/user_db/primary_table_file1";
1415

@@ -33,7 +34,7 @@ protected DataBase(){
3334
}
3435

3536
}
36-
37+
//TODO ensure that DataBase.getInstance() does not open create database when unwanted
3738
public static DataBase getInstance(){
3839
if(db == null){
3940
db = new DataBase();
@@ -84,15 +85,46 @@ private final boolean createBase(){
8485
return false;
8586
}
8687
System.out.println(PRIMARY_TABLE + " has been created of type: " + dbConfig.getType());
87-
populateTable(this.database, NO_RECORDS);
88-
88+
//TODO change to populateTable after testing
89+
int count = populateTable(this.database, NO_RECORDS);
90+
//int count = populateTestTable(this.database, NO_RECORDS_TEST);
91+
System.out.println(PRIMARY_TABLE + " has been inserted with: " + count + " records");
8992
return true;
9093
}
94+
95+
static int populateTestTable(Database my_table, int nrecs){
96+
DatabaseEntry kdbt, ddbt;
97+
int count = 0;
98+
ddbt = new DatabaseEntry(new String("test").getBytes());
99+
ddbt.setSize(4);
100+
101+
102+
try {
103+
for(int i = 0; i < nrecs; i++){
104+
kdbt = new DatabaseEntry(new Character((char)(i + 97)).toString().getBytes());
105+
kdbt.setSize(1);
106+
OperationStatus result;
107+
result = my_table.exists(null, kdbt);
108+
if (!result.toString().equals("OperationStatus.NOTFOUND"))
109+
throw new RuntimeException("Key is already in the database!");
91110

92-
static void populateTable(Database my_table, int nrecs ) {
111+
/* to insert the key/data pair into the database */
112+
my_table.putNoOverwrite(null, kdbt, ddbt);
113+
count++;
114+
}
115+
}catch (DatabaseException dbe) {
116+
System.err.println("Populate the table: "+dbe.toString());
117+
System.exit(1);
118+
}
119+
return count;
120+
}
121+
122+
static int populateTable(Database my_table, int nrecs ) {
93123
int range;
94124
DatabaseEntry kdbt, ddbt;
95-
String s, key, data;
125+
126+
String s;
127+
96128
/*
97129
* generate a random string with the length between 64 and 127,
98130
* inclusive.
@@ -102,8 +134,8 @@ static void populateTable(Database my_table, int nrecs ) {
102134
Random random = new Random(1000000);
103135

104136
try {
105-
for (int i = 0; i < nrecs; i++) {
106-
137+
138+
for (int i = 0; i < nrecs; i++) {
107139
/* to generate a key string */
108140
range = 64 + random.nextInt( 64 );
109141
s = "";
@@ -114,7 +146,7 @@ static void populateTable(Database my_table, int nrecs ) {
114146
kdbt = new DatabaseEntry(s.getBytes());
115147
kdbt.setSize(s.length());
116148

117-
149+
118150

119151
/* to generate a data string */
120152
range = 64 + random.nextInt( 64 );
@@ -123,11 +155,7 @@ static void populateTable(Database my_table, int nrecs ) {
123155
s+=(new Character((char)(97+random.nextInt(26)))).toString();
124156
data = s;
125157

126-
if(i <= 10){
127-
System.out.println(key);
128-
System.out.println(data);
129-
System.out.println();
130-
}
158+
131159
/* to create a DBT for data */
132160
ddbt = new DatabaseEntry(s.getBytes());
133161
ddbt.setSize(s.length());
@@ -138,14 +166,16 @@ static void populateTable(Database my_table, int nrecs ) {
138166
if (!result.toString().equals("OperationStatus.NOTFOUND"))
139167
throw new RuntimeException("Key is already in the database!");
140168

141-
/* to insert the key/data pair into the database */
142-
my_table.putNoOverwrite(null, kdbt, ddbt);
169+
/* to insert the key/data pair into the database */
170+
my_table.putNoOverwrite(null, kdbt, ddbt);
171+
count++;
143172
}
144173
}
145174
catch (DatabaseException dbe) {
146175
System.err.println("Populate the table: "+dbe.toString());
147-
System.exit(1);
176+
System.exit(1);
148177
}
178+
return count;
149179
}
150180

151181
public void close(){
@@ -162,6 +192,7 @@ public void close(){
162192
fnfe.printStackTrace();
163193
}
164194
database = null;
195+
db = null;
165196
}
166197

167198
}

Interval.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
public class Interval{
33
public static final String LOWER_LIMIT = "aaaapjjknhqcfdaoxdbghixrpkjnvautkjsjkqqbxhcgbgozowkpldjqnwfkhbveggqkbgtrnwruakhumnwguck";
4-
public static final String UPPER_LIMIT = "abagbejpsnfdhfdjoqlombtlbzdkvxsbhatvndnurlvwirthlqfgprswqohspxgwxcpxeexldavtkmgvpqscwiocgnktencfuunmouaulaeexojxmeltffxmkxonmyh";
4+
public static final String UPPER_LIMIT = "aaqumsxzjosfiqvtvtrnpncocpfcspahelkqvhraitrpcsmktpcvhdvjkzxozunocdoesndqffqqmjlrkfshnnpvzjycymnbtvrljhytirvpfzmwvnwfsmxuvoumlel";
5+
public static final String TEST_LOWER_LIMIT = "a";
6+
public static final String TEST_UPPER_LIMIT = "d";
57
public static final int KEYS_IN_INTERVAL = 150;
68
}

Menu.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
public class Menu{
23
Scan scan;
34
public Menu(){
@@ -38,15 +39,14 @@ public void makeSelection(){
3839
makeSelection();
3940
break;
4041
case 2 :
41-
System.out.println("Retrieving records with given key");
42+
System.out.println("Option 2 executed");
4243
KeyRetrieve kr = new KeyRetrieve();
4344
kr.getRecords();
4445
printHeader();
4546
makeSelection();
4647
break;
4748
case 3:
48-
System.out.println("Option 3 executed");
49-
System.out.println(Pref.getDbType());
49+
System.out.println("Option 3 executed");
5050
DataRetrieve dr = new DataRetrieve();
5151
dr.getRecords();
5252
printHeader();
@@ -55,12 +55,13 @@ public void makeSelection(){
5555
case 4:
5656
System.out.println("Option 4 executed");
5757
RangeSearch rs = new RangeSearch();
58+
//rs.compare();
5859
rs.execute();
5960
printHeader();
6061
makeSelection();
6162
break;
6263
case 5:
63-
System.out.println("Database is destroyed");
64+
System.out.println("Option 5 executed");
6465
IndexFile.getInstance().close();
6566
if(DataBase.getInstance().getPrimaryDb() != null){
6667
DataBase.getInstance().close();
@@ -69,6 +70,7 @@ public void makeSelection(){
6970
this.makeSelection();
7071
break;
7172
case 6:
73+
//TODO ensure that DataBase.getInstance() does not open create database when unwanted
7274
System.out.println("Exiting data base");
7375
IndexFile.getInstance().close();
7476
DataBase.getInstance().close();

0 commit comments

Comments
 (0)