javascript:HashMap.js[2]

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

本文简介:选择自 treeroot 的 blog

    this.getkey=getkey;
       function getkey() {
            return this.key;
       }
 
    this.getvalue=getvalue;
       function getvalue() {
            return this.value;
       }
       this.setvalue=setvalue;
       function setvalue(newvalue) {
            var oldvalue = this.value;
            this.value = newvalue;
            return oldvalue;
       }
  
    this.equals=equals;
       function equals(o) {
          var e = o;
          var k1 = this.getkey();
          var k2 = e.getkey();
    var v1 = this.getvalue();
          var v2 = e.getvalue();
          return (k1.equals(k2) && v1.equals(v2));
    }
 
    this.hashcode=hashcode;
       function hashcode() {
           return this.key.hashcode() ^ this.value.hashcode();
       }

    this.tostring=tostring;
       function tostring() {
            return this.getkey() + "=" + this.getvalue();
       }
 }


    function hashiterator(table,index,ne){

        this.table=table;
  this.ne=ne;                 
        this.index=index;           
        this.current=null;
  
  this.hasnext=hasnext;
  function hasnext() {
   return this.ne != null;
        }

        this.next=next;
  function next() {
   
            var e = this.ne;
            if (e == null)
                throw "no such element";
          
   var n = e.next;
            var t = this.table;
            var i = this.index;
            while (n == null && i > 0)
                n = t[--i];
            this.index = i;
            this.ne = n;
   this.current=e;

            return this.current;
        }
    }

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

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

go top