File tree 2 files changed +6
-6
lines changed
src/_DataStructures_/HashTable
2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 1
1
class HashEntry {
2
- constructor ( key , value ) {
2
+ constructor ( { key, value } ) {
3
3
this . key = key ;
4
4
this . value = value ;
5
5
this . next = null ;
Original file line number Diff line number Diff line change 1
- const { Node } = require ( '../LinkedList ' ) ;
1
+ const HashEntry = require ( './HashEntry ' ) ;
2
2
3
3
class HashTable {
4
4
constructor ( slots ) {
@@ -37,7 +37,7 @@ class HashTable {
37
37
* Util to add a SSL to the index in case of more than once
38
38
* value for the same key exixts
39
39
*/
40
- const node = new Node ( value ) ;
40
+ const node = new HashEntry ( value ) ;
41
41
if ( ! this . bucket [ index ] ) {
42
42
this . bucket [ index ] = node ;
43
43
this . size += 1 ;
@@ -62,8 +62,8 @@ class HashTable {
62
62
const res = [ ] ;
63
63
let head = this . bucket [ index ] ;
64
64
while ( head !== null ) {
65
- if ( head . data . key === key ) {
66
- res . push ( head . data . value ) ;
65
+ if ( head . key === key ) {
66
+ res . push ( head . value ) ;
67
67
}
68
68
head = head . next ;
69
69
}
@@ -96,7 +96,7 @@ class HashTable {
96
96
}
97
97
}
98
98
99
- // const ht = new HashTable();
99
+ // const ht = new HashTable(5 );
100
100
// ht.set('hello', 'I am a new value');
101
101
// ht.set('hello', 'I am a yet another value');
102
102
// ht.set('maroon', 'I maroon');
You can’t perform that action at this time.
0 commit comments