/
SecondaryIndex.java
87 lines (75 loc) · 1.77 KB
/
SecondaryIndex.java
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
import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.lang.*;
import java.util.Arrays;
public class SecondaryIndex {
public static String[] arr;
public static long stind;
public static void secondaryindexcreation() throws Exception
{
FileOutputStream out=new FileOutputStream("./index/sIndex");
PrintStream p = new PrintStream(out);
try {
int ct=0;
long len,l1;
String temp;
File file = new File("./index/pIndex");
RandomAccessFile raf = new RandomAccessFile(file, "r");
raf.seek(0);
len=raf.length();
String str;
int flag=0;
l1=new Long(raf.getFilePointer());
str=raf.readLine();
ct++;
while(str!=null)
{
if(ct==1)
{
arr=str.split("\\s+");
str=raf.readLine();
ct++;
}
if(ct==5000 || str==null)
{
long offset=new Long(raf.getFilePointer()-1);
offset=offset-l1+1;
p.println(arr[0]+":"+l1+":"+offset);
p.flush();
l1=new Long(raf.getFilePointer());
if(str!=null)
{
str=raf.readLine();
ct=1;
}
}
else{
long offset=new Long(raf.getFilePointer()-1);
str=raf.readLine();
ct++;
if(str==null)
{
offset=offset-l1+1;
p.println(arr[0]+":"+l1+":"+offset);
p.flush();
break;
}
}
}
raf.close();
} catch (Exception e) {
System.out.println("IOException:");
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
System.out.println("secondary index creation started");
SecondaryIndex si=new SecondaryIndex();
si.secondaryindexcreation();
/*SecondaryMap sm=new SecondaryMap();
sm.secondarymapindex();*/
System.out.println("ended successfully");
}
}