|
| 1 | +const { HashTableSeparateChaining } = PacktDataStructuresAlgorithms; |
| 2 | + |
| 3 | +const hashTable = new HashTableSeparateChaining(); |
| 4 | + |
| 5 | +hashTable.put('Gandalf', 'gandalf@email.com'); |
| 6 | +hashTable.put('John', 'johnsnow@email.com'); |
| 7 | +hashTable.put('Tyrion', 'tyrion@email.com'); |
| 8 | +hashTable.put('Aaron', 'aaron@email.com'); |
| 9 | +hashTable.put('Donnie', 'donnie@email.com'); |
| 10 | +hashTable.put('Ana', 'ana@email.com'); |
| 11 | +hashTable.put('Jonathan', 'jonathan@email.com'); |
| 12 | +hashTable.put('Jamie', 'jamie@email.com'); |
| 13 | +hashTable.put('Sue', 'sue@email.com'); |
| 14 | +hashTable.put('Mindy', 'mindy@email.com'); |
| 15 | +hashTable.put('Paul', 'paul@email.com'); |
| 16 | +hashTable.put('Nathan', 'nathan@email.com'); |
| 17 | + |
| 18 | +console.log('**** Printing Hash **** '); |
| 19 | + |
| 20 | +console.log(hashTable.toString()); |
| 21 | +// {5 => [#Jonathan: jonathan@email.com],[#Jamie: jamie@email.com],[#Sue: sue@email.com]},{10 => [#Nathan: nathan@email.com]},{13 => [#Donnie: donnie@email.com],[#Ana: ana@email.com]},{16 => [#Tyrion: tyrion@email.com],[#Aaron: aaron@email.com]},{19 => [#Gandalf: gandalf@email.com]},{29 => [#John: johnsnow@email.com]},{32 => [#Mindy: mindy@email.com],[#Paul: paul@email.com]} |
| 22 | + |
| 23 | +console.log('**** Get **** '); |
| 24 | + |
| 25 | +console.log(hashTable.get('Jamie')); // jamie@email.com |
| 26 | +console.log(hashTable.get('Sue')); // sue@email.com |
| 27 | +console.log(hashTable.get('Jonathan')); // jonathan@email.com |
| 28 | +console.log(hashTable.get('Loiane')); // undefined |
| 29 | + |
| 30 | +console.log('**** Remove **** '); |
| 31 | + |
| 32 | +console.log(hashTable.remove('Gandalf')); // true |
| 33 | +console.log(hashTable.get('Gandalf')); // undefined |
| 34 | +console.log(hashTable.toString()); |
| 35 | +// {5 => [#Jonathan: jonathan@email.com],[#Jamie: jamie@email.com],[#Sue: sue@email.com]},{10 => [#Nathan: nathan@email.com]},{13 => [#Donnie: donnie@email.com],[#Ana: ana@email.com]},{16 => [#Tyrion: tyrion@email.com],[#Aaron: aaron@email.com]},{29 => [#John: johnsnow@email.com]},{32 => [#Mindy: mindy@email.com],[#Paul: paul@email.com]} |
| 36 | + |
| 37 | +console.log(hashTable.remove('Sue')); // true |
| 38 | +console.log(hashTable.toString()); |
| 39 | +// {5 => [#Jonathan: jonathan@email.com],[#Jamie: jamie@email.com]},{10 => [#Nathan: nathan@email.com]},{13 => [#Donnie: donnie@email.com],[#Ana: ana@email.com]},{16 => [#Tyrion: tyrion@email.com],[#Aaron: aaron@email.com]},{29 => [#John: johnsnow@email.com]},{32 => [#Mindy: mindy@email.com],[#Paul: paul@email.com]} |
| 40 | + |
| 41 | +console.log(hashTable.remove('Jamie')); // true |
| 42 | +console.log(hashTable.toString()); |
| 43 | +// {5 => [#Jonathan: jonathan@email.com]},{10 => [#Nathan: nathan@email.com]},{13 => [#Donnie: donnie@email.com],[#Ana: ana@email.com]},{16 => [#Tyrion: tyrion@email.com],[#Aaron: aaron@email.com]},{29 => [#John: johnsnow@email.com]},{32 => [#Mindy: mindy@email.com],[#Paul: paul@email.com]} |
| 44 | + |
| 45 | +console.log(hashTable.remove('Donnie')); // true |
| 46 | +console.log(hashTable.toString()); |
| 47 | +// {5 => [#Jonathan: jonathan@email.com]},{10 => [#Nathan: nathan@email.com]},{13 => [#Ana: ana@email.com]},{16 => [#Tyrion: tyrion@email.com],[#Aaron: aaron@email.com]},{29 => [#John: johnsnow@email.com]},{32 => [#Mindy: mindy@email.com],[#Paul: paul@email.com]} |
0 commit comments