File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
src/_DataStructures_/HashTable Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 11class HashEntry {
2- constructor ( key , value ) {
2+ constructor ( { key, value } ) {
33 this . key = key ;
44 this . value = value ;
55 this . next = null ;
Original file line number Diff line number Diff line change 1- const { Node } = require ( '../LinkedList ' ) ;
1+ const HashEntry = require ( './HashEntry ' ) ;
22
33class HashTable {
44 constructor ( slots ) {
@@ -37,7 +37,7 @@ class HashTable {
3737 * Util to add a SSL to the index in case of more than once
3838 * value for the same key exixts
3939 */
40- const node = new Node ( value ) ;
40+ const node = new HashEntry ( value ) ;
4141 if ( ! this . bucket [ index ] ) {
4242 this . bucket [ index ] = node ;
4343 this . size += 1 ;
@@ -62,8 +62,8 @@ class HashTable {
6262 const res = [ ] ;
6363 let head = this . bucket [ index ] ;
6464 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 ) ;
6767 }
6868 head = head . next ;
6969 }
@@ -96,7 +96,7 @@ class HashTable {
9696 }
9797}
9898
99- // const ht = new HashTable();
99+ // const ht = new HashTable(5 );
100100// ht.set('hello', 'I am a new value');
101101// ht.set('hello', 'I am a yet another value');
102102// ht.set('maroon', 'I maroon');
You can’t perform that action at this time.
0 commit comments