Skip to content

Commit b337fe8

Browse files
committed
chapter 07: [Dictionaries and Hashes]
1 parent f01fe09 commit b337fe8

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

examples/chapter07/02-HashTable.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ console.log(hash.toString());
3333

3434
console.log('**** Get **** ');
3535

36-
console.log(hash.get('Gandalf')); // gandalf@email.com
37-
console.log(hash.get('Loiane')); // undefined
36+
console.log(hash.get('Ygritte')); // ygritte@email.com
37+
console.log(hash.get('Loiane')); // jasmine@email.com
3838

3939
console.log('**** Remove **** ');
4040

41-
hash.remove('Gandalf');
42-
console.log(hash.get('Gandalf')); // undefined
41+
hash.remove('Ygritte');
42+
console.log(hash.get('Ygritte')); // undefined
4343

4444
console.log(hash.toString());
45-
// {5 => [#Sue: sue@email.com]},{10 => [#Nathan: nathan@email.com]},{13 => [#Ana: ana@email.com]},{16 => [#Aaron: aaron@email.com]},{29 => [#John: johnsnow@email.com]},{32 => [#Paul: paul@email.com]}
45+
// {5 => [#Aethelwulf: aethelwulf@email.com]},{7 => [#Athelstan: athelstan@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Sargeras: sargeras@email.com]}

examples/chapter07/03-HashCollisionSeparateChaining.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ const { HashTableSeparateChaining } = PacktDataStructuresAlgorithms;
22

33
const hashTable = new HashTableSeparateChaining();
44

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');
5+
hashTable.put('Ygritte', 'ygritte@email.com');
116
hashTable.put('Jonathan', 'jonathan@email.com');
127
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');
8+
hashTable.put('Jack', 'jack@email.com');
9+
hashTable.put('Jasmine', 'jasmine@email.com');
10+
hashTable.put('Jake', 'jake@email.com');
1611
hashTable.put('Nathan', 'nathan@email.com');
12+
hashTable.put('Athelstan', 'athelstan@email.com');
13+
hashTable.put('Sue', 'sue@email.com');
14+
hashTable.put('Aethelwulf', 'aethelwulf@email.com');
15+
hashTable.put('Sargeras', 'sargeras@email.com');
1716

1817
console.log('**** Printing Hash **** ');
1918

2019
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]}
20+
// {4 => [#Ygritte: ygritte@email.com]},{5 => [#Jonathan: jonathan@email.com],[#Jamie: jamie@email.com],[#Sue: sue@email.com],[#Aethelwulf: aethelwulf@email.com]},{7 => [#Jack: jack@email.com],[#Athelstan: athelstan@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com],[#Sargeras: sargeras@email.com]}
2221

2322
console.log('**** Get **** ');
2423

@@ -29,19 +28,19 @@ console.log(hashTable.get('Loiane')); // undefined
2928

3029
console.log('**** Remove **** ');
3130

32-
console.log(hashTable.remove('Gandalf')); // true
33-
console.log(hashTable.get('Gandalf')); // undefined
31+
console.log(hashTable.remove('Ygritte')); // true
32+
console.log(hashTable.get('Ygritte')); // undefined
3433
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]}
34+
// {5 => [#Jonathan: jonathan@email.com],[#Jamie: jamie@email.com],[#Sue: sue@email.com],[#Aethelwulf: aethelwulf@email.com]},{7 => [#Jack: jack@email.com],[#Athelstan: athelstan@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com],[#Sargeras: sargeras@email.com]}
3635

3736
console.log(hashTable.remove('Sue')); // true
3837
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]}
38+
// {5 => [#Jonathan: jonathan@email.com],[#Jamie: jamie@email.com],[#Aethelwulf: aethelwulf@email.com]},{7 => [#Jack: jack@email.com],[#Athelstan: athelstan@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com],[#Sargeras: sargeras@email.com]}
4039

4140
console.log(hashTable.remove('Jamie')); // true
4241
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]}
42+
// {5 => [#Jonathan: jonathan@email.com],[#Aethelwulf: aethelwulf@email.com]},{7 => [#Jack: jack@email.com],[#Athelstan: athelstan@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com],[#Sargeras: sargeras@email.com]}
4443

45-
console.log(hashTable.remove('Donnie')); // true
44+
console.log(hashTable.remove('Aethelwulf')); // true
4645
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]}
46+
// {5 => [#Jonathan: jonathan@email.com]},{7 => [#Jack: jack@email.com],[#Athelstan: athelstan@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com],[#Sargeras: sargeras@email.com]}

examples/chapter07/04-HashCollisionLinearProbing.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,41 @@ const { HashTableLinearProbing } = PacktDataStructuresAlgorithms;
22

33
const hashTable = new HashTableLinearProbing();
44

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');
5+
hashTable.put('Ygritte', 'ygritte@email.com');
116
hashTable.put('Jonathan', 'jonathan@email.com');
127
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');
8+
hashTable.put('Jack', 'jack@email.com');
9+
hashTable.put('Jasmine', 'jasmine@email.com');
10+
hashTable.put('Jake', 'jake@email.com');
1611
hashTable.put('Nathan', 'nathan@email.com');
12+
hashTable.put('Athelstan', 'athelstan@email.com');
13+
hashTable.put('Sue', 'sue@email.com');
14+
hashTable.put('Aethelwulf', 'aethelwulf@email.com');
15+
hashTable.put('Sargeras', 'sargeras@email.com');
1716

1817
console.log('**** Printing Hash **** ');
1918

2019
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-
20+
// {4 => [#Ygritte: ygritte@email.com]},{5 => [#Jonathan: jonathan@email.com]},{6 => [#Jamie: jamie@email.com]},{7 => [#Jack: jack@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com]},{11 => [#Athelstan: athelstan@email.com]},{12 => [#Sue: sue@email.com]},{13 => [#Aethelwulf: aethelwulf@email.com]},{14 => [#Sargeras: sargeras@email.com]}
2321
console.log('**** Get **** ');
2422

2523
console.log(hashTable.get('Nathan')); // nathan@email.com
2624
console.log(hashTable.get('Loiane')); // undefined
2725

2826
console.log('**** Remove **** ');
2927

30-
hashTable.remove('Gandalf');
31-
console.log(hashTable.get('Gandalf')); // undefined
28+
hashTable.remove('Ygritte');
29+
console.log(hashTable.get('Ygritte')); // undefined
3230
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]}
31+
// {5 => [#Jonathan: jonathan@email.com]},{6 => [#Jamie: jamie@email.com]},{7 => [#Jack: jack@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com]},{11 => [#Athelstan: athelstan@email.com]},{12 => [#Sue: sue@email.com]},{13 => [#Aethelwulf: aethelwulf@email.com]},{14 => [#Sargeras: sargeras@email.com]}
3432

3533
console.log('**** Remove Test 2 **** ');
3634
console.log('Removing Jonathan', hashTable.remove('Jonathan')); // true
3735
console.log('**** Print **** ');
3836
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]}
37+
// {5 => [#Jamie: jamie@email.com]},{6 => [#Sue: sue@email.com]},{7 => [#Jack: jack@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com]},{11 => [#Athelstan: athelstan@email.com]},{12 => [#Aethelwulf: aethelwulf@email.com]},{13 => [#Sargeras: sargeras@email.com]}
4038

4139
console.log(hashTable.get('Jamie')); // jamie@email.com
4240
console.log('**** Print **** ');
4341
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]}
42+
// {5 => [#Jamie: jamie@email.com]},{6 => [#Sue: sue@email.com]},{7 => [#Jack: jack@email.com]},{8 => [#Jasmine: jasmine@email.com]},{9 => [#Jake: jake@email.com]},{10 => [#Nathan: nathan@email.com]},{11 => [#Athelstan: athelstan@email.com]},{12 => [#Aethelwulf: aethelwulf@email.com]},{13 => [#Sargeras: sargeras@email.com]}

0 commit comments

Comments
 (0)