I have the following c++ method:
typedef unsigned long p3tOffsetType;
p3tOffsetType buildString(std::string string)
{
for (stringMap::const_iterator string_iterator = strings.begin(); string_iterator != strings.end(); ++string_iterator)
{
if (string_iterator->second == string)
return string_iterator->first;
}
p3tOffsetType new_string_offset = string_offset;
strings[string_offset] = string;
string_offset += string.size() + 1;
return new_string_offset;
}
What does the function do? I can give more of the code if needed.
The code is a snippet from a P3T file packer found in the source P3TBuilder (version 2.7).
I need to know this because I am trying to
Assuming that
stringsis amap<p3tOffsetType, std::string>and thatstring_offsetis initialized to zero, it seems to do the following: Imagine that you call the method a few times with, say,"Hello","Hi", and"Hey", and that you would treat all these strings as C-strings and store them in the samechararray. The array elements would then be{'H', 'e', 'l', 'l', 'o', '\0', 'H', 'i', '\0', 'H', 'e', 'y', '\0'}. The starting indices of the three strings are 0, 6, and 9, respectively. What the method does is to create a map that maps these starting indices to the strings, sostrings[0] == "Hello",strings[6] == "Hi", andstrings[9] == "Hey". Also, it eliminates duplicates, so calling the method again with"Hello"would leave the map unchanged.