src/Generic/xdoc/TokenSubsetTrees.cpp
// _allNodes must be ordered from children to parent. 
// For each node, determines and sets the unambiguous leaf-most
// child the node is connected to, if there is one.

_allNodes must be ordered from children to parent.
For each node, determines and sets the unambiguous leaf-most
child the node is connected to, if there is one.
_allNodes must be ordered from children to parent . For each node determines and sets the unambiguous leaf - most child the node is connected to if there is one .
BOOST_FOREACH(TSTNode *node, _allNodes) {
		if (node->children.size() == 0)
			node->unambiguousLeaf = node;
		else {
			set<TSTNode *> childLeafs;
			BOOST_FOREACH(TSTNode *child, node->children) 
				childLeafs.insert(child->unambiguousLeaf);
			if (childLeafs.find(0) != childLeafs.end() || childLeafs.size() != 1) 
				continue;
			TSTNode *onlyChildLeaf = *(childLeafs.begin());
			node->unambiguousLeaf = onlyChildLeaf;
			if (_unambiguousLeaf2NodeMap.find(onlyChildLeaf) == _unambiguousLeaf2NodeMap.end())
				_unambiguousLeaf2NodeMap[onlyChildLeaf] = vector<TSTNode*>();
			_unambiguousLeaf2NodeMap[onlyChildLeaf].push_back(node);
		}
	}
BOOST_FOREACH ( TSTNode * node , _allNodes ) { if ( node -> children . size ( ) == 0 ) node -> unambiguousLeaf = node ; else { set < TSTNode * > childLeafs ; BOOST_FOREACH ( TSTNode * child , node -> children ) childLeafs . insert ( child -> unambiguousLeaf ) ; if ( childLeafs . find ( 0 ) != childLeafs . end ( ) || childLeafs . size ( ) != 1 ) continue ; TSTNode * onlyChildLeaf = * ( childLeafs . begin ( ) ) ; node -> unambiguousLeaf = onlyChildLeaf ; if ( _unambiguousLeaf2NodeMap . find ( onlyChildLeaf ) == _unambiguousLeaf2NodeMap . end ( ) ) _unambiguousLeaf2NodeMap [ onlyChildLeaf ] = vector < TSTNode * > ( ) ; _unambiguousLeaf2NodeMap [ onlyChildLeaf ] . push_back ( node ) ; } }
_allNodes must be ordered from children to parent.
_allNodes must be ordered from children to parent .
//std::cout << "Unambiguous leaf of " << UnicodeUtil::toUTF8StdString(node->value) << " is " << UnicodeUtil::toUTF8StdString(node->unambiguousLeaf->value) << "\n";
