TrieNode* findCh(char ch)
	{
		TrieNode* p = firstChild;

		while (nullptr != p)
		{
			if (ch == p->getValue())
				return p;
			else
				p = p->nextBrother;
		}

		return nullptr;
	}
示例#2
0
Symtab::index_t Symtab::operator[](const string& symbol) {
  TrieNode<index_t>* node = &root;
  for(char c : symbol) {
    node = (*node)[c];
  }
  if (!node->hasValue()) {
    /* Assert that an overflow will not occured. */
    assert(counter != 0);
    node->setValue(counter);
    /* Perhaps this is not the most efficient approach! */
    symbols.push_back(symbol);
    counter++;
  }
  /*debug << symbol << " = " << node->getValue() << std::endl;*/
  return node->getValue();
}