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

📄 urlqucon.java

📁 这是一个URL检索的算法
💻 JAVA
字号:
import java.io.*;
public class URLqucon{
public static void main(String []args)
	{	
		   String s=new String();int size=297143;
		   int count=0;int hashcode;int hashnum=0;int stringnum=0;
		  URLqucon hash=new URLqucon();
		   //String sbuff[]=new String[size];
		   Node  sbuff[]=new Node[size];
		   long start=0;
		   Node p,q,p1;
           
           for (int i=0;i<size;i++)
           { sbuff[i]=new Node();}
           
     
     	try		{
			File f=new File("D:\\download\\temp\\temp0011.txt");
			FileInputStream fint=new FileInputStream(f);
            BufferedInputStream bint=new BufferedInputStream(fint);
			DataInputStream  in=new DataInputStream (bint);
			   
	        File f2=new File("D:\\download\\temp\\temp0013.txt");
			FileOutputStream fout=new FileOutputStream(f2);
            BufferedOutputStream bout=new BufferedOutputStream(fout);
			DataOutputStream  out=new DataOutputStream (bout);
    
	   
            System.out.println("parent path"+f.getParent());
		    //long start=System.currentTimeMillis();
	        System.out.println("parent path: "+f.getName());
	        System.out.println("file  length: "+f.length());
	        start=System.currentTimeMillis();
		    while((s=in.readLine())!=null)//&&(count<=140))
		   	  {
		    
		      hashcode=hash.Hfip(s,size);
		     if (sbuff[hashcode].s==null) { sbuff[hashcode].s=s;out.writeBytes(s);
		                                       out.write(13);out.write(10);}
		      else {
		      	   if ((sbuff[hashcode].s).equals(s)==false)
	                  { //System.out.println(sbuff[hashcode]+"  and  "+s);
	   	    	    	  
	   	    	    	  p=new Node();q=new Node();
	   	    	    	  p=sbuff[hashcode];
	   	    	    	  while (p!=null)
	   	    	    	  { if ((p.s).equals(s)==true) {stringnum++;break;}
	   	    	    	    q=p;
	   	    	    	    p=p.next;
	   	    	    	  	}
	   	    	    	  if (p==null) { p1=new Node();p1.s=s;
	   	    	    	                  out.writeBytes(s);
	   	    	    	                  out.write(13);out.write(10);
	   	    	    	                  q.next=p1;
	   	    	    	                 
	   	    	    	                  hashnum++;}
	   	    	    	  
	   	    	    }
	   	    	    else { stringnum++;}
	   	    	    
	   	    	     //  else {// System.out.println(sbuff[hashcode]+"  and  "+s);
		    	     //      hashnum++;}
		            }//else
			  count++;
			}//while
		
			out.flush();
				
			in.close();bint.close();fint.close();
			out.close();bout.close();fout.close();
		}//try
		catch(IOException ioe)		{System.out.println(ioe);}
		System.out.println("time had "+(System.currentTimeMillis()-start));
		System.out.println("count is "+count);
		System.out.println("stringnum is "+stringnum);
	    System.out.println("hashnum is "+hashnum);
	    
	    Node p2=new Node();int n2=0;float a=0;
	    for (int i=0;i<size;i++)
	    {
	    	n2=0;
	    	if (sbuff[i].s!=null) 
	    	{ p2=sbuff[i];
	    	  while(p2!=null)
	    	  { //System.out.println("s is "+p2.s);
	    	  	p2=p2.next; n2=n2+1;}
	    	  
	        }
	     //System.out.println("n2 is "+n2);
	    a=a+n2*(n2+1)/2;
	   
	   }//endfor
	   
	    a=a/size;
	    System.out.println("a is "+a);
	   
	}




int Hfip(String url,int size)
	{
	  int n=0;
	  byte []b=new byte[4];
	  
		
		int m=n;
		for (int i=0;i<4;i++)
		{
			b[i]=(byte)((m>>8*(3-i))&0xFF);
					
		}
		
		for (int i=0;i<url.length();i++)
		{
			b[i%4]^=url.charAt(i);
					
		}
		
		n=b[0]<<24|b[1]<<16|b[2]<<8|b[3];
		
		
	 if (n>0)	  return n%size;
		  else 
		  {
		  	int tempa=n;long j=1;long a3=0;int t;
	       for(int k=0;k<32;k++,j=(long)Math.pow(2,k))
	        {t=tempa&0x01;
	         a3=a3+t*j;
	          tempa=tempa>>1;
	          
	          }
	          
	        
		  	return (int)(a3%size);
		
			
	        }
	        
	     }


	int ELFhash(String url,int size)
		{ 
		  int h=0;
		  int i=0;
		  while (i<url.length())
		  {
		  	h=(h<<4)+(int)url.charAt(i);
		  	i++;
		  	int g=h&0xF0000000;
		  	if (g!=0)
		  	h^=g>>24;
		  	h&=~g;
		  }
		  
		   if (h>0)	  return h%size;
		  else 
		  {
		  	int tempa=h;long j=1;long a3=0;int t;
	       for(int k=0;k<32;k++,j=(long)Math.pow(2,k))
	        {t=tempa&0x01;
	         a3=a3+t*j;
	          tempa=tempa>>1;
	          
	          }
	          
	          
		  	
		  	return (int)(a3%size);
		  	}
		  
      }

	int hf(String url,int size)
	{
		int result=0;
	    String ptr=new String(url);
	    int c;
	    for(int i=1;i<=ptr.length();i++)
	    {
	    	c=ptr.charAt(i-1);
	    	result +=c*3*i;
	    }
	    if (result<0)
	    result=-result;
	    return result%size;	
	    
	
	}


}



class Node
{  
String s;
Node next;
public Node(){}

}





		
	       
    

⌨️ 快捷键说明

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