-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashLinear.js
52 lines (51 loc) · 1.52 KB
/
HashLinear.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const Hash = require('../../ED/src/Hash');
const createElement = function(key=(Number || String), value) {
let element = {
key : key,
value : value,
toString : () => { return `[${key} - ${value}]` }
}
return element;
}
const HashLinear = (() => {
class HashLinear{
constructor(){
super();
}
put(key=(Number || String), value){
let position = this.hashCode(key), index = position;
if(!this.table[position]){
let index = ++position;
while(this.table[index]){
index++;
}
position = index;
}
this.table[index] = createElement(key, element);
}
get(key){
let position = this.hashCode(key), element;
while(this.table[position]){
position++;
}
if(this.table[position].key === key){
element = this.table[positon];
}
return element;
}
remove(key){
let position = this.hashCode(key), element;
while(this.table[position].key !== key && this.table[position]){
position++;
}
if(this.table[position].key === key){
element = this.table[position];
this.table[position] = undefined;
}
return element;
}
}
return HashLinear;
})();
exports.default = HashLinear;
module.exports = exports['default'];