-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuscalc.java
More file actions
247 lines (206 loc) · 5.18 KB
/
Copy pathBuscalc.java
File metadata and controls
247 lines (206 loc) · 5.18 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package buscalc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;
import java.util.Scanner;
public class Buscalc {
private static int BIT_ARRAY_LENGTH = 10*1000;
private HashMap<String, Integer> map;
//private HashMap<Integer, mapNode> maps[];
private List<mapNode> lists[];
private byte matrix[][];
private boolean matrixLine[][];
public static void main(String[] args) throws FileNotFoundException
{
//System.out.print("Hello,world!!");
/*File file=new File("E:\\buscalc\\src\\buscalc\\buslines.dat");
if(!file.exists()||file.isDirectory())
throw new FileNotFoundException();
FileInputStream fis=new FileInputStream(file);
Scanner reader=new Scanner(fis);
reader.nextLine();
//while(reader.hasNext())
{
//int i=reader.nextInt();
//System.out.print(i);
String str=reader.nextLine();
String arry[]=str.split("\\s+");
//int i = Integer.parseInt(arry[0]);
System.out.print(arry[2]);
}
byte ba[] = new byte[10000 * 80000];
Scanner reader = new Scanner(System.in);
reader.next();
System.out.print(4 >> 2);*/
Buscalc bc = new Buscalc();
//byte bf[][] = new byte[80000][10000];
bc.constructMatrix("E:\\buscalc\\src\\buscalc\\buslines.dat"); //read file and construct matrix
System.out.println("after construct");
//bc.calculate();
//System.out.println("after calculate");
}
public Buscalc()
{
int i, j;
map = new HashMap<String, Integer>();
//matrix = new byte[80000][10000];
//lists = new List[3000];
/*for(i = 0; i < 3000; i++)
{
lists[i] = new ArrayList<mapNode>();
}
matrixLine = new boolean[3000][3000];
for(i = 0; i < 3000; i++)
{
for(j = 0; j < 3000; j++)
{
matrixLine[i][j] = false;
}
}*/
}
public void constructMatrix(String filename) throws FileNotFoundException
{
int i = 0, id = 0;
File file=new File(filename);
if(!file.exists()||file.isDirectory())
throw new FileNotFoundException();
FileInputStream fis=new FileInputStream(file);
Scanner reader=new Scanner(fis);
reader.nextLine();
while(reader.hasNext())
{
String str=reader.nextLine();
String arry[]=str.split("\\s+");
int xid = Integer.parseInt(arry[0]);
int pm = Integer.parseInt(arry[1]);
int kind = Integer.parseInt(arry[3]);
String zhan = arry[2];
//mapNode mn = new mapNode(pm, kind, zhan);
//lists[xid].add(mn);
if(!map.containsKey(zhan))
{
map.put(zhan, i);
i++;
}
}
/*System.out.println(lists.length);
for(i = 0; i < lists.length; i++)
{
for(j = 0; j < lists.length; j++)
{
for(k = 0; k < lists[i].size(); k++)
{
for(l = 0; l < lists[j].size(); l++)
{
if(lists[i].get(k).zhan == lists[j].get(l).zhan)
{
matrixLine[i][j] = true;
}
}
}
}
}*/
}
/*public void constructMatrix(String filename) throws FileNotFoundException
{
//File file=new File("E:\\buscalc\\src\\buscalc\\buslines.dat");
int i = 0, j, id = 0;
//HashMap<Integer, mapNode> map = new HashMap<Integer, mapNode>();
File file=new File(filename);
if(!file.exists()||file.isDirectory())
throw new FileNotFoundException();
FileInputStream fis=new FileInputStream(file);
Scanner reader=new Scanner(fis);
reader.nextLine();
while(reader.hasNext())
//while(i < 1000)
{
//int i=reader.nextInt();
//System.out.print(i);
String str=reader.nextLine();
String arry[]=str.split("\\s+");
int xid = Integer.parseInt(arry[0]);
int pm = Integer.parseInt(arry[1]);
int kind = Integer.parseInt(arry[3]);
String zhan = arry[2];
mapNode mn = new mapNode(xid, pm, kind, zhan);
//System.out.println(mp.zhan);
if(xid != id)
{
id = xid;
}
else
{
setBit(i, i - 1);
}
map.put(i, mn);
i++;
}
System.out.println(map.size());
//int num = 0;
/*for(i = 0; i < map.size(); i++)
{
for(j = 0; j < map.size(); j++)
{
if(map.get(j).xid == map.get(i).xid)
{
//setBit(i, j);
if(j % 10000 == 0)
System.out.println("i="+i+" j="+j);
}
//num = num + i +j;
}
}
}*/
public void setBit(int row, int col)
{
int i = col/8%BIT_ARRAY_LENGTH;
int j = col%8;
//char c = (char *) bf;
//printf("i: %d, j: %d\n", i, j);
//printf("c[i] : %2x\n", c[i]);
matrix[row][i] = (byte)((1 << j) | matrix[row][i]);
//printf("c[i] : %2x\n", c[i]);
}
/*int getBit(int row, int col)
{
int i = row/8%BIT_ARRAY_LENGTH;
int j = row%8;
//char *c = (char *) bf;
if ((matrix[row][i] & (1 << j)) == 0)
return 0;
else
return 1;
}*/
public void calculate()
{
int i, j, k;
for(k = 0; k < 3000; k++)
{
for(i = 0; i < 3000; i++)
{
for(j = 0; j < 3000; j++)
{
if(matrixLine[i][k] && matrixLine[k][j])
matrixLine[i][j] = true;
}
}
}
}
}
class mapNode{
int pm, kind;
String zhan;
public mapNode(int p, int k, String z)
{
//xid = x;
pm = p;
kind =k;
zhan = z;
}
}