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