-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchainedhashing.js
More file actions
67 lines (67 loc) · 1.46 KB
/
chainedhashing.js
File metadata and controls
67 lines (67 loc) · 1.46 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const linkedlist=require('./linkedlist.js');
class chain{
constructor(size){
this.table=[];
this.size=size;
for(let i=0;i<this.size;i++){
this.table.push(null);
}
}
insert(value){
let g=value%this.size;
if(g<0){
g=0;
}
if(this.table[g]==null){
this.table[g]=new linkedlist.structure(value);
}
else{
this.table[g].insert(value);
}
}
delete(value){
let g=value%this.size;
if(g<0){
g=0;
}
if(this.table[g]==null){
return;
}
else{
this.table[g].delete(value);
}
}
find(value){
let g=value%this.size;
if(g<0){
g=0;
}
if(this.table[g]==null){
console.log(false);
return false;
}
else{
return this.table[g].find(value);
}
}
print(){
for(let i=0;i<this.size;i++){
if(this.table[i]!=null){
this.table[i].print();
}
}
}
}
module.exports={
structure:chain,
description:"Chained Hashing",
methods:{
insert:"Inserts a value into the hash table",
delete:"Deletes a value from the hash table",
find:"Finds a value in the hash table",
print:"Prints the hash table"
},
properties:{
size:"The size of the hash table"
}
};