void GetkMax(NodeVec& rtv, int k)
{
	int i ;
	for( i = 0 ; i < k ; ++i) rtv.push_back(i);
	make_heap(rtv.begin(), rtv.end(), compare());
	while(i < MaxN)
	{
		if(compare()(i, rtv[0]))
		{
			pop_heap(rtv.begin(), rtv.end(), compare());
			rtv.pop_back();
			rtv.push_back(i);
			push_heap(rtv.begin(), rtv.end(), compare());
		}
		++i;
	}
}
Example #2
0
/*
 * DeleteCFG()
 *  Remove one CFG.
 */
void DeleteCFG(GraphNode *Root)
{
    NodeVec VisitStack;
    NodeSet Visited;
    
    VisitStack.push_back(Root);
    while(VisitStack.size())
    {
        GraphNode *Parent = VisitStack.back();
        VisitStack.pop_back();
        
        if (Visited.count(Parent))
            continue;
        
        Visited.insert(Parent);
        NodeVec &Child = Parent->getSuccessor();
        for (int i = 0, e = Child.size(); i < e; i++)
            VisitStack.push_back(Child[i]);
    }

    for (NodeSet::iterator I = Visited.begin(), E = Visited.end(); I != E; I++)
        delete *I;
}