整个代码还没写完,但是在readfile()函数中,读完文件后,for中操作的很慢,不知道为什么,求解释。
读的文件内容格式是:
……
WT28-B01-91 WT28-B01-92
WT28-B01-93 WT28-B01-92
WT28-B01-25 WT28-B01-93
……
将文件内容放在了vector中,然后再用for读出来,并将每条记录切分成两部分(原内容以'\t'隔开),同样存起来。
import java.io.*;
import java.util.Vector;public class Mypagerank 
{
static int M = 30;
static int N = 0;
static double alf = 0.2;
static int m = 0;
static Vector<String>data = new Vector<String>();
static Vector<String>page = new Vector<String>();
static Vector<Integer>outdegree = new Vector<Integer>();
static Vector<String>Ipage = new Vector<String>();
public static void main(String args[])
{
Mypagerank prank = new Mypagerank();
prank.readfile();
}
public void readfile()
{
File file = new File("..\\a.txt");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String temp ="";
System.out.println("begin read file!");
while((temp = reader.readLine())!= null)
{
data.add(temp);
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
System.out.println("size of data = "+data.size());
String d[];
int index;
for(int i=0;i<data.size();i++)//////这部分操作很慢
{
d = data.get(i).split("\t");

index = page.indexOf(d[0]);
if(index !=-1)
{
int t = outdegree.get(index);
outdegree.set(index, t+1);
}
else
{
page.add(d[0]);
outdegree.add(1);
}
index = page.indexOf(d[1]);
if(index == -1)
{
page.add(d[1]);
outdegree.add(0);
}
}
N = page.size();
System.out.println("read file over!");
System.out.println("size of page = "+N);
}
}