template <typename C> ostream & operator << (ostream & salida, const Grafo<C> & grafo)
{
	list<int> vertices;   //Recorremos todos los vertices
	grafo.devolverVertices(vertices);
	list<int>::iterator v;
	v = vertices.begin();
	cout << endl;
	while (v != vertices.end())
	{
		salida << "Vertice: " << *v << endl;  // Recorremos todos los adyacentes de cada vertice
		list<typename Grafo<C>::Arco> adyacentes;
		grafo.devolverAdyacentes(*v, adyacentes);
		typename list<typename Grafo<C>::Arco>::iterator ady;
		ady = adyacentes.begin();
		while (ady != adyacentes.end())
		{
			salida << "            " << "-> " << ady->devolverAdyacente() << " con costo: (" << ady->costo << ")" << endl;
			ady++;
		}
		v++;
		cout << endl;
	}
	cout << endl;
	return salida;
}
void ORNode<T> :: copyUp ()
{
	if(_sub_trees.size()) { return;}

	// an OR node must not be empty.
	assert(_base::begin() != _base::end());

	T data = _base::begin()->data;

	// label
	_baseTreeNode::_cat = data.getSig().label;
	// if this is a leaf, the _cat and _word will be the same.
	if(_base::size() == 0){ _baseTreeNode::_word = data.getSig().label;
	} else { _baseTreeNode::_word = ""; }

	// span.
	_e_span = data.getSig().span;
	//cerr<<_e_span.first<<":"<<_e_span.second<<" ++\n";
	
	// head word indexes --- set them to be dummy. 
	_head_index = 0;
	_head_string_pos = 0;

//	_parent = NULL;
	// parent and children.
	// parent is always the OR node of the real parent.
	//_parent = grandParent(); ////
	typename list<ANDNode<T> >::iterator it;
	for(it = _base::begin(); it != _base::end(); ++it){
		_sub_trees.push_back((TreeNode*)&(*it));
		it->parent() = this->parent();
		it->setImdPar(this);
		it->copyUp();
	}
}
Beispiel #3
0
    void ClsTypeManager<T>::loadTypes(string _strDirectory)
    {
	list<string> listTypes = getListLibraries(_strDirectory);
	
	typename list<string>::iterator it;
	for (it = listTypes.begin(); it != listTypes.end(); ++it) {
	    string strFileName = it->data();
	    string strType = fileName2typeName(strFileName);
	    string strPath = getPathToFile(_strDirectory, 
					   strFileName);
	    try {
		string strLabel = loadType(strType, strPath);

		// Guard against duplicate label.
		typename TypeLabelMap::iterator entry;
		entry = mapLabelLookup.find(strLabel);
		if (entry != mapLabelLookup.end()) {
		    cerr << "WARNING: duplicate label "
			 << strLabel
			 << ", scanning for new label:"
			 << endl;
		    
		    int i = 1;
		    ostringstream tmp;
		    do {
			tmp.str("");
			++i;
			tmp << strLabel << " #" << i;
		    } while (mapLabelLookup.find(tmp.str()) 
			     != mapLabelLookup.end());
		    strLabel = tmp.str();
		}

		mapLabelLookup.insert(make_pair(strLabel, strType));
		listLabels.push_back(strLabel);
		
		if (bDebugTypeManager) {
		    cout << "Loaded " 
			 << strLabel
			 << ", stored as "
			 << strType
			 << endl;
		}
	    }
	    catch (iqrcommon::LoadTypeError &e) {
		cerr << getName()
		     << ": couldn't load "
		     << strFileName
		     << endl
		     << "    "
		     << e.what()
		     << endl;
	    }
	}

	// Sort the list of names alphabetically.
	listLabels.sort();
    }
Beispiel #4
0
list<T> tops(list<stack<T>>& stackList) {
    list<T> result;

    typename list<stack<T>>::iterator it;

    for (it = stackList.begin(); it != stackList.end(); it++) {
        //result.push_back((*it).top());    // Same as below
        result.push_back(it->top());
    }
    return result;
}
Beispiel #5
0
V Hash<V>::get(string key) {
 int hashed = hash(key);
 if(!table[hashed].empty()) {                                       // If the spot in the table is not empty...
  typename list< Entry<V> >::iterator it;                             //
  for(it = table[hashed].begin(); it != table[hashed].end(); it++) {  // it = Entry obj in list
   std::cout << hashed << std::endl;
   if(it->getKey() == key)                                          // And the key is the same...
    return it->getValue();                                          // return the value.
  }
 }                                                                  //else the key was not present in the table
 return (V)0;
}
Beispiel #6
0
void Hash<V>::remove(string key) {
 if(!table[hash(key)].empty()){ // Non empty spot, no need to remove if empty
  bool erased = false;
  typename list< Entry<V> >::iterator it;
  for(it = table[hash(key)].begin(); it != table[hash(key)].end() && erased == false; it++) {
    if(it->getKey() == key) {
     it = table[hash(key)].erase(it); // Erase it!
     erased == true;
   }
  }
 }
}
Beispiel #7
0
bool isSingleSubSetSequence(const list<S>& s1, const list<set<S> >& s2)
{
    if (s1.empty())
        return true;
    typename list<S>::const_iterator it1 = s1.begin();
    typename list<set<S> >::const_iterator it2 = s2.begin();
    for (; it2 != s2.end(); ++it2)
        if (it2->find(*it1) != it2->end())
            if (++it1 == s1.end())
                return true;
    return false;
}
   	T &  at(int i, int j){
   		entries_no++;

        if(grid.empty()){
            list<node<T> > dummy_row;
            node<T>* dummy_node = new node<T>(i, j);
            dummy_row.push_back(*dummy_node);
            grid.push_back(dummy_row);
            col_no=1;
            return ((grid.front()).front()).val ;
        }
        else{
        	typename list< list<node<T> > >::iterator itr_row = grid.begin();
        	for(;itr_row!=grid.end();itr_row++){
        		if( (*(*itr_row).begin()).row == i){

        			typename list<node <T > >::iterator itr_col = itr_row.begin();
        			for(; itr_col != (*itr_row).end(); itr_col++){
        				if(*itr_col == j)
        					return (*itr_col).val;
        				else if(*itr_col > j){
        					node<T>* dummy_node = new node<T>(i, j);
        					typename list<node<T> >::iterator to_be_return = (*itr_row).insert(itr_col, *dummy_node);
        					return (*to_be_return).val;
        				}
        			}
        			if(itr_col == itr_row.end()){
        				node<T>* dummy_node = new node<T>(i, j);
        				(*itr_row).push_back(*dummy_node);
        				return (*((*itr_row).back())).val;
        			}
        		}

        		else if( (*(*itr_row).begin()).row > i){
        			list<node<T> > dummy_row;
            		node<T>* dummy_node = new node<T>(i, j);
            		dummy_row.push_back(*dummy_node);
                    typename list<list<node<T> > >::iterator to_be_return = grid.insert(itr_row, dummy_row);
            		row_no++;
            		return  (*((*to_be_return ).front())).val;
        		}

        	}
        	if(itr_row==grid.end()){
        		list<node<T> > dummy_row;
            	node<T>* dummy_node = new node<T>(i, j);
            	dummy_row.push_back(*dummy_node);
            	grid.push_back(dummy_row);
            	row_no++;
            	return  ((grid.back()).back()).val;
        	}
        }
    }
Beispiel #9
0
void Hash<V>::print() {
 std::cout << "[ " ;
 for(int i = 0; i < height; i++) {
  std::cout << "{ " ; 
   if(!table[i].empty()){
   typename list< Entry<V> >::iterator it;
   for(it = table[i].begin(); it != table[i].end(); it++) {
    std::cout << "(" << it->getKey() << ", " << it->getValue() << ") " ;
   }
  }
 std::cout << " }";
 if(i+1 != height)
  std::cout << std::endl;
 }
 std::cout << " ]" << std::endl;
}
Beispiel #10
0
void Hash<V>::insert(string key, V v) {
 if(table[hash(key)].empty()) //empty spot
  table[hash(key)].push_back(Entry<V>(key,v));
 else{ //non-empty spot
  typename list< Entry<V> >::iterator it;
  bool inserted = false;
  for(it = table[hash(key)].begin(); it != table[hash(key)].end() && inserted == false; it++) {
    if(it->getKey() == key) {
    it->setValue(v);
    inserted = true;
   }
  }
  if(inserted == false) { //non-empty and non-duplicate.
   table[hash(key)].push_back(Entry<V>(key,v));
  }
 }
}
Beispiel #11
0
void HashTable<V>::remove(string k) {

  int hash = hashFunction(k);
  list<Entry<V> > &hList = vecTable[hash];
  typename list<Entry<V> >::iterator it;

  for (it=hList.begin(); it!=hList.end(); it++) {
    if (it->getKey() == k) {
      hList.erase(it);
      return;
    }
  }

  // if no key == k in the hash table return
  return;

}
Beispiel #12
0
V* HashTable<V>::find(string k) {
  
  int hash = hashFunction(k);
  list<Entry<V> > &hList = vecTable[hash];
  typename list<Entry<V> >::iterator it;

  for (it=hList.begin(); it!=hList.end(); it++) {
    if (it->getKey() == k) {
      // return &(it->getValue());
      return it->getValuePtr();
    }
  }

  // if no key == k in the hash table
  return 0;

}
Beispiel #13
0
void HashTable<V>::insert(string k, V v) {

  int hash = hashFunction(k);
  list<Entry<V> > &hList = vecTable[hash];
  typename list<Entry<V> >::iterator it;

  for (it=hList.begin(); it!=hList.end(); it++) {
    if (it->getKey() == k) {
      it->setValue(v);
      return;
    }
  }

  // if no key == k in the hash table create a new Entry
  Entry<V> newEntry(k,v);
  hList.push_back(newEntry); 
  return;

}
Beispiel #14
0
void HashTable<V>::print() {

  typename list<Entry<V> >::iterator it;

  cout << endl;
  for (int i=0; i<SIZE; i++) {
    
    cout << i << ": ";
    list<Entry<V> > &hList = vecTable[i];

    for (it=hList.begin(); it!=hList.end(); it++) {
      cout << "[" << it->getKey() << "," << it->getValue() << "]";
    }

    cout << endl;

  }

  cout << endl;

  return;
}
Beispiel #15
0
static void AutoBindMappers(list<T>* refMappers, list<T>* modMappers)
{
  for(typename list<T>::iterator itModMappers = modMappers->begin(); itModMappers!=modMappers->end(); ++itModMappers)
  {
    bool bound = false;
    string modLabel = itModMappers->GetLabel();

    transform(modLabel.begin(), modLabel.end(), modLabel.begin(), (int(*)(int)) tolower);

    list<string> modTokens = split(modLabel, ',');

    for(list<string>::iterator itModTokens = modTokens.begin(); itModTokens != modTokens.end(); ++itModTokens)
    {
      if(!itModTokens->empty() && *itModTokens != "not found" && *itModTokens != "duplicate")
      {
        typename list<T>::iterator itRefMappers;
        for(itRefMappers = refMappers->begin(); itRefMappers!=refMappers->end(); ++itRefMappers)
        {
          string refLabel = itRefMappers->GetLabel();

          transform(refLabel.begin(), refLabel.end(), refLabel.begin(), (int(*)(int)) tolower);

          list<string> refTokens = split(refLabel, ',');

          if(find(refTokens.begin(), refTokens.end(), *itModTokens) != refTokens.end())
          {
            itModMappers->SetDevice(*itRefMappers->GetDevice());
            itModMappers->SetEvent(*itRefMappers->GetEvent());
            if(itRefMappers->GetLabel().find(", found") != string::npos)
            {
              if(itModMappers->GetLabel().find(", duplicate") == string::npos)
              {
                itModMappers->SetLabel(itModMappers->GetLabel() + ", duplicate");
              }
            }
            else
            {
              itRefMappers->SetLabel(itRefMappers->GetLabel() + ", found");
            }
            break;
          }
        }
        if(itRefMappers != refMappers->end())
        {
          bound = true;
          break;
        }
      }
    }
    if(!bound && !itModMappers->GetLabel().empty() && itModMappers->GetLabel().find(", not found") == string::npos)
    {
      itModMappers->SetLabel(itModMappers->GetLabel() + ", not found");
    }
  }
}