⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rabintest.java

📁 这是一个URL检索的算法
💻 JAVA
字号:
import java.io.File;
import java.io.FileInputStream;
import java.io.RandomAccessFile;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;

public class Rabintest

{
   public static void main(String []args)
   {
   Rabintest rabintest=new Rabintest(); 
   MyRabin myrabin=new MyRabin();
   
   String s1="http://www.gxu.edu.cn/040310/text.css";
   
   	byte buf5[]=new byte[4];
   	byte temp,lowp,highp;  int sum=0;byte j=0; int local;
   	byte b1[]=new byte[150];
    int count=0;   	long start=0;
   	
   	//open the URL file
   try 
   {
   	File f1=new File("D:\\download\\temp\\temp0012.txt");
	FileInputStream fint=new FileInputStream(f1);
    BufferedInputStream bint=new BufferedInputStream(fint);
	DataInputStream  in=new DataInputStream (bint);
   	
   	start=System.currentTimeMillis();
   	 while(((s1=in.readLine())!=null) &&(count<=200000))
   	 { 
   	
   	//将URL字符串转换为URL字节数组
   	rabintest.stringtobyte(s1,b1);	   	
   	
   	
      	//得出Rabin值
   		
   	myrabin.engineUpdate(b1,0,s1.length());
   	buf5=myrabin.engineDigest();
    sum=0;j=0;
   	//得出URL在二进制库的位置
   	for (int i=0;i<3;i++)
   	{   //System.out.print(buf5[i]+"   ");
   	    temp=buf5[i];
   	    lowp=(byte)(buf5[i]&0x0f);
   	    highp=(byte)((temp>>4)&0x0f);
   	   // System.out.println("lowp is "+lowp);
   	  // System.out.println("highp is "+highp);
   	    
   	    local=(int)(highp*Math.pow(16,(6-j)))+(int)(lowp*Math.pow(16,(6-j-1)));
   	    sum=sum+local;
   	    j=(byte)(j+2);
   	}//endfor
   		temp=buf5[3];
   		lowp=(byte)(buf5[3]&0x0f);
   		highp=(byte)((temp>>4)&0x0f);
   		sum=sum+highp;
   	if (sum<0)	System.out.println("had a error");
   	//	System.out.println("sum is "+sum);
   	//	System.out.println("lowp is "+lowp);
   		
   	   		
   		//在二进制库检索URL是否存在,URL二进制库以文件形式存放
     rabintest.treeprocess(sum,lowp);  	
     count++;
  }//end while 
  
}//end try 
catch(IOException e) {System.out.println("this is main "+e);}
     
     
 System.out.println("time had "+(System.currentTimeMillis()-start));
     
     
     
     	
   	}//endmain
   	
  void stringtobyte(String s,byte[]b)
    { for (int i=0;i<s.length();i++)
   	{b[i]=(byte)s.charAt(i);}
   	
   	}
   	
   	
   	
   	
 void treeprocess(int m1,byte m2)
  {
  	char buf=0,temp;
    try{
    RandomAccessFile f=new RandomAccessFile("D:\\download\\hashtempFile1.txt","rw");
//	System.out.println("this is "+f.length());
    f.seek(m1*2);
    buf=f.readChar();    
    temp=buf;
    if (((temp>>m2)&0x01)==1){ // System.out.println("the URL had trieved");
                               }
     else {//System.out.println("the URL hadnot trieved,put to URLqueue");
          buf=(char)(buf|(1<<m2));
          f.seek(m1*2);
          f.writeChar(buf);
           }//endif 
       
	f.close(); 
	 } //end try
	catch(IOException e)	{System.out.println("this is treeprocess"+e);}
	
	//return buf;
} //end treeprocess
   	
   	
   	
}	//end class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -