-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtreesearch.java
More file actions
93 lines (63 loc) · 2.63 KB
/
treesearch.java
File metadata and controls
93 lines (63 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.io.*;
import java.util.*;
public class treesearch{
public static void main(String args[]) throws IOException{
//this initialises input and output files and streams
FileHandler fh = new FileHandler(args[0],"output_file.txt");
BPlusTree bpt;
//TODO , implement something so that filePath can be
//out of directory as well
//OR NOT
ArrayList<String> sentences;
sentences = fh.readInput();
//first line in input file is the order int
int order = Integer.parseInt(sentences.get(0));
//initialise bplustree
bpt = new BPlusTree(order);
for(int i=1;i<sentences.size();i++){
//represents a line gotten from the input file
String line = sentences.get(i);
//tokentised the line based on the following delimiters
StringTokenizer st = new StringTokenizer(line,"(,)");
//operation is either Insert or Search
String operation = st.nextToken();
//parameter list will be used to provide inputs and
//distinguish between different types of searches
Vector<String> parameterList = new Vector<String>();
while(st.hasMoreTokens()){
parameterList.add(st.nextToken());
}
if(operation.equals("Insert")){
//inserting key value pair into the tree for insert op
bpt.insertPair(Double.parseDouble(parameterList.get(0)),parameterList.get(1));
}
else if(operation.equals("Search")){
if(parameterList.size()==1){
String toWrite;
toWrite = bpt.getSearch(Double.parseDouble(parameterList.get(0)),bpt.root);
//writing the output of search on one key, to the file
fh.writeOutput(toWrite);
}
else if(parameterList.size()==2){
String toWrite;
try{
toWrite = bpt.rangeSearch(Double.parseDouble(parameterList.get(0)),Double.parseDouble(parameterList.get(1)));
//writing the output of range search to the output file
fh.writeOutput(toWrite);
}catch(NullPointerException e){}
}
else{
//will be intered of there is a discrepency in the number of
//search parameters
System.out.println("wrong number of parameters in search");
// System.out.println(parameterList.size());
// for(int s=0;s<parameterList.size();s++)
// System.out.println(parameterList.get(s));
}
}
}
fh.closeOutputBuffer();
// System.out.println("LIST-++++++____++++");
// bpt.printLL();
}
}