Skip to content

Instantly share code, notes, and snippets.

@ivmarkp
Last active March 17, 2017 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivmarkp/90a6af732cc53f4acece4bc51ab35038 to your computer and use it in GitHub Desktop.
Save ivmarkp/90a6af732cc53f4acece4bc51ab35038 to your computer and use it in GitHub Desktop.
unordered_map<string, int> word_to_occurrence;
// Build map before line 755 in query.cc by calling the method build_word_map.
void build_word_map(const string& list) {
string word;
int count = 0;
for (size_t i = 0; i <= list.length(); ++i)
{
if (list[i] == '\t' || list[i] == '\0')
{
if (word_to_occurrence.find(word) == word_to_occurrence.end())
{
word_to_occurrence[word] = count++;
word.clear();
}
} else
word += list[i];
}
}
static int word_in_list(const string& word)
{
if (word_to_occurrence.find(word) != word_to_occurrence.end())
return word_to_occurrence[word];
else
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment