Skip to content

Commit 74c1829

Browse files
author
Wakidur Rahaman
committed
implement
1 parent c1e7aea commit 74c1829

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class HashTable {
2+
private data: number[];
3+
constructor(size: number) {
4+
this.data = new Array(size);
5+
}
6+
7+
_hash(key: string) {
8+
let hash = 0;
9+
for (let i = 0; i < key.length; i++) {
10+
hash = (hash + key.charCodeAt(i) * i) % this.data.length;
11+
}
12+
return hash;
13+
}
14+
}
15+
16+
const myHashTable = new HashTable(50);
17+
// myHashTable.set('grapes', 10000);
18+
// myHashTable.get('grapes');
19+
// myHashTable.set('apples', 9);
20+
// myHashTable.get('apples');

0 commit comments

Comments
 (0)