javascript:HashMap.js[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 treeroot 的 blog

/**
* used like java.lang.hashmap
*/
function testhashmap(){
 alert("hashmap test begin:");
 try{

 }
 catch(e){
  alert(e);
 }
 alert("hashmap test end");
}


function hashmap()
{
 private:
 this.len=8;
 this.table=new array();
 this.length=0;
 this.hash=hash;
    function hash(x){
        var h = x.hashcode();
        h += ~(h << 9);
        h ^=  (h >>> 14);
        h +=  (h << 4);
        h ^=  (h >>> 10);
        return h;
    }

 this.rehash=rehash;
 function rehash() {
       
        var oldtable = this.table;  
   
        this.table=new array();
       
  //transfer       
        for (var i = 0; i< oldtable.length; i++) {
            var e = oldtable[i];
            if (e != null) {
                oldtable[i] = null;
                do {
                    var next = e.next;
                    var j = this.indexfor(e.hash); 
                    e.next = this.table[j];
                    this.table[j] = e;
                    e = next;
                } while (e != null);
            }
        }
  //alert("rehash to :"+this.len);
    }
 


 this.indexfor=indexfor;
    function indexfor(h) {

  var index= h & (this.len-1);
  return index;
    }
 
 function entry(h,k,v,n){
     
       this.value = v;
       this.next = n;
       this.key = k;
       this.hash = h;

本文关键:javascript:HashMap.js
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top