I like your idea. Errors are important data structures, and I had a pleasant experience working with <> s cards as efficient containers.
Just some notes: if your compiler supports it, you can avoid memory loss with a separate allocation for each node.
template< typename T > struct NodeTrie { NodeTrie(const T& val = T(), bool isWord = bool() ) : val(val), isWord(isWord) {} std::map<char, NodeTrie> span; T val; bool isWord; };
To use this method:
int main() { typedef NodeTrie<int> iTree; iTree t(0); t.span['a'] = iTree(3); ... }
I also changed the val element to become a construct for copying: using the link here seems to be the wrong design for me ...
source share