Exemplo n.º 1
0
/**
 * Go through nodes vector and eliminate entries that have zero children,
 * that is, are not connected to any others.
 * Need to clean up 'children_' list.
 *
 * static func
 */
unsigned int NeuroNode::removeDisconnectedNodes( 
				vector< NeuroNode >& nodes )
{
	vector< NeuroNode > temp;
	vector< unsigned int > nodeMap( nodes.size() );

	unsigned int j = 0;
	for ( unsigned int i = 0; i < nodes.size(); ++i ) {
		if ( nodes[i].children_.size() > 0 ) {
			temp.push_back( nodes[i] );
			nodeMap[i] = j;
			++j;
		} else {
			nodeMap[i] = ~0;
		}
	}
	for ( unsigned int i = 0; i < temp.size(); ++i ) {
		vector< unsigned int >& c = temp[i].children_;
		for ( vector< unsigned int >::iterator 
						j = c.begin(); j != c.end(); ++j ) {
			assert( nodeMap[ *j ] != ~0U );
			*j = nodeMap[ *j ];
		}
	}
	unsigned int numRemoved = nodes.size() - temp.size();
	nodes = temp;
	return numRemoved;
}
Exemplo n.º 2
0
Node<U> *nodeMap(Node<T> *node, std::function<U(T)> cls) {
    if (node == 0) {
        return 0;
    } else {
        Node<U> *tmp = new Node<U>();
        tmp->value = cls(node->value);
        tmp->next = nodeMap(node->next, cls);
        return tmp;
    }
}
Exemplo n.º 3
0
DoubleLinkedList<U> *map(DoubleLinkedList<T> *list, std::function<U(T)> cls) {
    return new DoubleLinkedList<U>(
            nodeMap(list->first, cls)
    );
}