日期:2014-05-16 浏览次数:20328 次
var table = new HashTable(); table.put(jsObjKey,jsObjValue); var arrayList = new ArrayList(); arrayList.add(jsObj); ... arrayList.size();
// StringBuffer. function StringBuffer(){ this.array = new Array(); } StringBuffer.prototype.append = function (content){ this.array[eval(this.array.length)] = content; } StringBuffer.prototype.toString = function (){ return this.array.join(""); } // ArrayList. function ArrayList(){ this.index = -1; this.array = new Array(); } ArrayList.prototype.add = function (obj){ this.index = this.index + 1; this.array[eval(this.index)] = obj; } ArrayList.prototype.get = function (index){return this.array[eval(index)];} ArrayList.prototype.size = function (){return this.index+1;} ArrayList.prototype.remove = function (index){ var j = 0; var arrThis = this.array; var arrTemp = new Array(); for(w=0;w<arrThis.length;w++){ if (eval(index)!=eval(w)) { arrTemp[j] = arrThis[w]; j++; } } this.array = arrTemp; this.index = eval(j-1); } // HashTable Object 注意哦,T 可是大些的 function HashTable(){ this.arrValues = new ArrayList(); } function HashTable_Map(){ var key = null; var value = null; } HashTable.prototype.put = function (objKey,objValue){ var isAdd = true; var arrThis = this.arrValues; for(i=0;i<arrThis.size();i++){ var map = arrThis.get(i); if (map.key==objKey){ map.value = objValue; isAdd = false; } } if (isAdd){ var Map = new HashTable_Map(); Map.key = objKey; Map.value = objValue; this.arrKeys = objKey; this.arrValues.add(Map); } } HashTable.prototype.get = function (objKey){ var arrThis = this.arrValues; for(i=0;i<arrThis.size();i++){ var map = arrThis.get(i); if (map.key==objKey) return map.value; } return null; } HashTable.prototype.keys = function (){ var arrKeys = new Array(); var arrThis = this.arrValues; for(i=0;i<arrThis.size();i++){ var map = arrThis.get(i); arrKeys[i] = map.key; } return arrKeys; } HashTable.prototype.remove = function (objKey){ for(i=0;i<this.arrValues.size();i++){ var map = this.arrValues.get(i); if (objKey == map.key){ this.arrValues.remove(i); } } }
var table = new HashTable(); table.put(jsObjKey,jsObjValue); var arrayList = new ArrayList(); arrayList.add(jsObj); ... arrayList.size();
// StringBuffer. function StringBuffer(){ this.array = new Array(); } StringBuffer.prototype.append = function (content){ this.array[eval(this.array.length)] = content; } StringBuffer.prototype.toString = function (){ return this.array.join(""); } // ArrayList. function ArrayList(){ this.index = -1; this.array = new Array(); } ArrayList.prototype.add = function (obj){ this.index = this.index + 1; this.array[eval(this.index)] = obj; } ArrayList.prototype.get = function (index){return this.array[eval(index)];} ArrayList.prototype.size = function (){return this.index+1;} ArrayList.prototype.remove = function (index){ var j = 0; var arrThis = this.array; var arrTemp = new Array(); for(w=0;w<arrThis.length;w++){ if (eval(index)!=eval(w)) { arrTemp[j] = arrThis[w]; j++; } } this.array = arrTemp;