Skip to content

Commit 80641c0

Browse files
committed
Updated hash table
1 parent 907e036 commit 80641c0

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

Hash Table/hashTable.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ var HashTable = function(){
66

77
HashTable.prototype.insert = function(k, v){
88
var i = getIndexBelowMaxForKey(k, this._limit);
9-
var bucket = this._storage.get(i);
9+
var bucket = this._storage.get(i);
1010

11-
this._count++;
12-
if (bucket) {
13-
var tuple = _.find(bucket, function (tuple) {
14-
return tuple[0] === k;
15-
});
16-
if (tuple) tuple[1] = v
17-
else {
18-
bucket.push([k, v]);
19-
if (this._count > (this._limit * 0.75))
20-
this.resize(this._limit * 2);
21-
}
22-
} else this._storage.set(i, [[k, v]]);
11+
this._count++;
12+
if (bucket) {
13+
var tuple = _.find(bucket, function (tuple) {
14+
return tuple[0] === k;
15+
});
16+
if (tuple) tuple[1] = v
17+
else {
18+
bucket.push([k, v]);
19+
if (this._count > (this._limit * 0.75))
20+
this.resize(this._limit * 2);
21+
}
22+
} else this._storage.set(i, [[k, v]]);
2323
};
2424

2525
HashTable.prototype.retrieve = function(k){
26-
var i = getIndexBelowMaxForKey(k, this._limit);
27-
var bucket = this._storage.get(i);
28-
if (bucket) {
29-
var tuple = _.find(bucket, function (tuple) {
30-
return tuple[0] === k;
31-
});
32-
if (tuple) return tuple[1];
33-
} else return null;
26+
var i = getIndexBelowMaxForKey(k, this._limit);
27+
var bucket = this._storage.get(i);
28+
if (bucket) {
29+
var tuple = _.find(bucket, function (tuple) {
30+
return tuple[0] === k;
31+
});
32+
if (tuple) return tuple[1];
33+
} else return null;
3434
};
3535

3636
HashTable.prototype.remove = function(k){

0 commit comments

Comments
 (0)