data-footstone
Advanced tools
Comparing version 0.1.11 to 0.1.12
@@ -27,6 +27,2 @@ 'use strict'; | ||
this.hash = hash; | ||
// this._put = () => {} | ||
// this._hashFn = () => '' | ||
// this._get = () => {} | ||
// this._remove = () => {} | ||
switch (kind) { | ||
@@ -36,8 +32,15 @@ case 'separate': | ||
this._put = (k, v) => { | ||
let p = this.hashFn(k); | ||
if (this.box[p] === undefined) { | ||
this.box[p] = new chain.SingleChain(); | ||
let node = this._get(k); | ||
if (node) { | ||
node.value = v; | ||
} | ||
this._size++; | ||
return this.box[p].append(this.createNode(k, v)); | ||
else { | ||
let p = this.hashFn(k); | ||
if (this.box[p] === undefined) { | ||
this.box[p] = new chain.SingleChain(); | ||
} | ||
this.box[p].append(this.createNode(k, v)); | ||
this._size++; | ||
} | ||
return this._size; | ||
}; | ||
@@ -54,3 +57,5 @@ this._get = (k) => { | ||
if (cur.value.key === k) { | ||
res = cur.value.value; | ||
// res = cur.value.value | ||
// 改为返回节点 | ||
res = cur.value; | ||
break; | ||
@@ -87,7 +92,15 @@ } | ||
this._put = (k, v) => { | ||
let p = this.hashFn(k); | ||
while (this.box[p] !== undefined) { | ||
p++; | ||
let node = this._get(k); | ||
if (node) { | ||
node.value = v; | ||
} | ||
this.box[p] = this.createNode(k, v); | ||
else { | ||
let p = this.hashFn(k); | ||
while (this.box[p] !== undefined) { | ||
p++; | ||
} | ||
this.box[p] = this.createNode(k, v); | ||
this._size++; | ||
} | ||
return this._size; | ||
}; | ||
@@ -99,3 +112,5 @@ this._get = (k) => { | ||
if (this.box[p].key === k) { | ||
res = this.box[p].value; | ||
// res = this.box[p].value | ||
// 改为返回节点 | ||
res = this.box[p]; | ||
break; | ||
@@ -118,2 +133,3 @@ } | ||
} | ||
this._size--; | ||
return res; | ||
@@ -140,6 +156,7 @@ }; | ||
put(k, v) { | ||
this._put(k, v); | ||
return this._put(k, v); | ||
} | ||
get(k) { | ||
return this._get(k); | ||
let res = this._get(k); | ||
return res ? res.value : undefined; | ||
} | ||
@@ -146,0 +163,0 @@ remove(k) { |
@@ -25,6 +25,2 @@ import { SingleChain } from './chain.js'; | ||
this.hash = hash; | ||
// this._put = () => {} | ||
// this._hashFn = () => '' | ||
// this._get = () => {} | ||
// this._remove = () => {} | ||
switch (kind) { | ||
@@ -34,8 +30,15 @@ case 'separate': | ||
this._put = (k, v) => { | ||
let p = this.hashFn(k); | ||
if (this.box[p] === undefined) { | ||
this.box[p] = new SingleChain(); | ||
let node = this._get(k); | ||
if (node) { | ||
node.value = v; | ||
} | ||
this._size++; | ||
return this.box[p].append(this.createNode(k, v)); | ||
else { | ||
let p = this.hashFn(k); | ||
if (this.box[p] === undefined) { | ||
this.box[p] = new SingleChain(); | ||
} | ||
this.box[p].append(this.createNode(k, v)); | ||
this._size++; | ||
} | ||
return this._size; | ||
}; | ||
@@ -52,3 +55,5 @@ this._get = (k) => { | ||
if (cur.value.key === k) { | ||
res = cur.value.value; | ||
// res = cur.value.value | ||
// 改为返回节点 | ||
res = cur.value; | ||
break; | ||
@@ -85,7 +90,15 @@ } | ||
this._put = (k, v) => { | ||
let p = this.hashFn(k); | ||
while (this.box[p] !== undefined) { | ||
p++; | ||
let node = this._get(k); | ||
if (node) { | ||
node.value = v; | ||
} | ||
this.box[p] = this.createNode(k, v); | ||
else { | ||
let p = this.hashFn(k); | ||
while (this.box[p] !== undefined) { | ||
p++; | ||
} | ||
this.box[p] = this.createNode(k, v); | ||
this._size++; | ||
} | ||
return this._size; | ||
}; | ||
@@ -97,3 +110,5 @@ this._get = (k) => { | ||
if (this.box[p].key === k) { | ||
res = this.box[p].value; | ||
// res = this.box[p].value | ||
// 改为返回节点 | ||
res = this.box[p]; | ||
break; | ||
@@ -116,2 +131,3 @@ } | ||
} | ||
this._size--; | ||
return res; | ||
@@ -138,6 +154,7 @@ }; | ||
put(k, v) { | ||
this._put(k, v); | ||
return this._put(k, v); | ||
} | ||
get(k) { | ||
return this._get(k); | ||
let res = this._get(k); | ||
return res ? res.value : undefined; | ||
} | ||
@@ -144,0 +161,0 @@ remove(k) { |
{ | ||
"name": "data-footstone", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "data structure", | ||
@@ -75,3 +75,3 @@ "author": "feigebaobei <18515195415@163.com>", | ||
}, | ||
"gitHead": "3c32fa18edb1159d85dee53f1428ee2459a7ec18" | ||
"gitHead": "95f949439a162635ee92bb2b0660ba9fe5a1237a" | ||
} |
@@ -24,6 +24,2 @@ import { SingleChain } from './chain'; | ||
this.hash = hash; | ||
// this._put = () => {} | ||
// this._hashFn = () => '' | ||
// this._get = () => {} | ||
// this._remove = () => {} | ||
switch (kind) { | ||
@@ -33,8 +29,15 @@ case 'separate': | ||
this._put = (k, v) => { | ||
let p = this.hashFn(k); | ||
if (this.box[p] === undefined) { | ||
this.box[p] = new SingleChain(); | ||
let node = this._get(k); | ||
if (node) { | ||
node.value = v; | ||
} | ||
this._size++; | ||
return this.box[p].append(this.createNode(k, v)); | ||
else { | ||
let p = this.hashFn(k); | ||
if (this.box[p] === undefined) { | ||
this.box[p] = new SingleChain(); | ||
} | ||
this.box[p].append(this.createNode(k, v)); | ||
this._size++; | ||
} | ||
return this._size; | ||
}; | ||
@@ -51,3 +54,5 @@ this._get = (k) => { | ||
if (cur.value.key === k) { | ||
res = cur.value.value; | ||
// res = cur.value.value | ||
// 改为返回节点 | ||
res = cur.value; | ||
break; | ||
@@ -84,7 +89,15 @@ } | ||
this._put = (k, v) => { | ||
let p = this.hashFn(k); | ||
while (this.box[p] !== undefined) { | ||
p++; | ||
let node = this._get(k); | ||
if (node) { | ||
node.value = v; | ||
} | ||
this.box[p] = this.createNode(k, v); | ||
else { | ||
let p = this.hashFn(k); | ||
while (this.box[p] !== undefined) { | ||
p++; | ||
} | ||
this.box[p] = this.createNode(k, v); | ||
this._size++; | ||
} | ||
return this._size; | ||
}; | ||
@@ -96,3 +109,5 @@ this._get = (k) => { | ||
if (this.box[p].key === k) { | ||
res = this.box[p].value; | ||
// res = this.box[p].value | ||
// 改为返回节点 | ||
res = this.box[p]; | ||
break; | ||
@@ -115,2 +130,3 @@ } | ||
} | ||
this._size--; | ||
return res; | ||
@@ -137,6 +153,7 @@ }; | ||
put(k, v) { | ||
this._put(k, v); | ||
return this._put(k, v); | ||
} | ||
get(k) { | ||
return this._get(k); | ||
let res = this._get(k); | ||
return res ? res.value : undefined; | ||
} | ||
@@ -143,0 +160,0 @@ remove(k) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
361161
5815