It is a common task to manipulate strings. Here, we'll see how an operation of string comparison can be done quickly using some simple tricks. This recipe is a trampoline for the next one, where the techniques described here will be used to achieve constant time-complexity searches.
So, we need to make some class that is capable of quickly comparing strings for equality. We'll make a template function to measure the speed of comparison:
#include <string>
template <class T>
std::size_t test_default() {
// Constants
const std::size_t ii_max = 200000;
const std::string s(
"Long long long string that "
"will be used in tests to compare "
"speed of equality comparisons."
);
// Making some data, that will be
// used in comparisons.
const T data1...