Pages

Sunday, 10 April 2022

Chapter 23 // Exercise 5 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 5

Find a large email message file (thousands of messages) and then time it as written with a multimap and with multimap replaced by an unordered_multimap. Note that our application does not take advantage of the ordering of the multimap.


This one was interesting. I used my random email generator to create a text file with 5555 emails in it.

Then created 2 functions and timed them as he shows on page 1015.

The multimap took 12.591 seconds.
The unordered multimap took 12.48 seconds. 

Saturday, 9 April 2022

Chapter 23 // Exercise 4 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 4

Find a real email message file (containing real email messages) and modify the email example to extract subject lines from sender names taken as input from the user.


I converted an email from my own account to text (hotmail) and it was very basic with just
From: Name <email>
Sent: DD Month YYYY HH:MM
To: Name <email>
Subject: Subject Message

Message

When a message is forwarded it's exactly the same but Fw: is added after Subject:

So, seeing as how the next exercise needs a text file with thousands of messages I decided to quickly create a "random email generator": 

You can use this to create a text file containing as many email messages as you want for testing.

I then went about changing everything to use wide strings instead so most currency symbols would work. I briefly tried to make emojis work but couldn't be bothered going down that rabbit hole.




Thursday, 7 April 2022

Chapter 23 // Exercise 3 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 3

Modify the email example from section 23.4 to use regular expressions to find the subject and sender.


So for this I used the site Regex101 to help craft the regex I needed:

This site is great as it gives explanations of what each part of the regex is doing and you can step through matches in the debugger.

For the subject, I assumed that we are finding it only in English and based off the email examples in the section. I got a bit annoyed as apparently std::regex doesn't support the very handy lookbehind feature. So I ended up just searching for "Subject:" then creating a string with everything in the message line after those 9 characters.

I then did the same for the sender.