예제 #1
0
	bool build(Dict &_front, Dict &_back, Dict &dict, Tree &tree, bool flag)
	{
		if (_front.empty()) return false;
		if (_front.size() > _back.size())
			return build(_back, _front, dict, tree, !flag);
		for (auto &word : _front) dict.erase(word);
		for (auto &word : _back) dict.erase(word);
		Dict hoge;
		bool piyo = false;
		for (auto &i : _front)
		{
			string word = i;
			for (auto &c : word)
			{
				char fuga = c;
				for (c = 'a'; c <= 'z'; c++)
				{
					if (c == fuga) continue;
					if (_back.count(word))
					{
						piyo = true;
						!flag ? tree[i].push_back(word): tree[word].push_back(i);
					}
					else if (!piyo && dict.count(word))
					{
						hoge.insert(word);
						!flag ? tree[i].push_back(word): tree[word].push_back(i);
					}
				}
				c = fuga;
			}
		}
		return piyo || build(hoge, _back, dict, tree, flag);
	}
예제 #2
0
int main (){
    cout << boolalpha;

    // constructor
    Dict<string,long> d;
    // add
    d.add("bill", 10);
    d.add("rich", 20);
    // output
    cout << d << endl << endl;

    //copy
    Dict<string,long> d2(d);
    cout << d2 << endl << endl;

    // add to existing key
    d2.add("bill", 100);
    // copy working?
    cout << d << endl << endl;
    cout << d2 << endl << endl;
    cout << "CHECK THIS ^^" << endl;

    // exists
    cout << "Exists bill:"<<d.exists("bill")<<endl;
    cout << "Exists john:"<<d.exists("john")<<endl;
    // get_value
    cout << "Value of bill:"<<d.get_value("bill")<<endl;
    // get_value throws on bad key
    try{
	d.get_value("john");
    }
    catch (range_error &e){
	cout << "bad get_value "<<e.what()<<endl;
    }

    // make the array grow
    d.add("fred", 30);
    d.add("bob", 40);
    d.add("irving", 50);
    d.add("john",60);
    cout << endl;
    cout << d << endl<<endl;

    // assignment
    Dict<string,long> d3;
    d3 = d;

    // erase
    d.erase("bob");
    // assignment working?
    cout << d << endl<<endl;
    cout << d3 << endl<<endl;
    cout << "D2: " << endl;
    cout << d2 << endl;

}
예제 #3
0
// *****************************************************************************
EntityPtrs Shotgun::entityFactoryFind(const std::string &entityType, 
                                      Dict &findMap,
                                      const int limit)
{
    EntityPtrs entities;

    // Find the registered functions for the given type of class.
    ClassRegistry::iterator foundRegistryIter = m_classRegistry.find(entityType);

    if (foundRegistryIter == m_classRegistry.end())
    {
        throw SgEntityNotRegisteredError(entityType);
    }

    // The set of registered functions 
    RegistryFuncs registryFuncs = (*foundRegistryIter).second;

    // ------------------------------------------------------------------------
    // If the given findMap already has a "return_fields", merge its contents 
    // with the poupulated default return Fields of the given entity type. 
    // Shotgun will ignore the duplicated fields when it returns the search result. 
    // To update the findMap's "return_fields", erase it first since the 
    // xmlrpc_c::value type can't be reassigned once it's been instantiated. 
    // ------------------------------------------------------------------------

    // Populate the default return fields and add the extra return fields
    // before passing them to the findMap
    List returnFields = (*(registryFuncs.defaultReturnFieldsFunc))();
    try
    {
        // Check to see if the findMap has "return_fields" already
        returnFields.extend(findMap.value<List>("return_fields"));
        findMap.erase("return_fields");
    }
    catch (SgDictKeyNotFoundError)
    {
        // Do nothing
    }

    findMap.add("return_fields", returnFields);

    // If the findMap already has a "type" field, override it with the
    // given entityType to ensure that the type will not conflict with 
    // the factory function.
    if (findMap.find("type"))
    {
        findMap.erase("type");
    }
    findMap.add("type", entityType);

    // Find the shotgun entities by the findMap
    List xmlrpcFindResult = Entity::findSGEntities(this, findMap, limit); 
    
    // Create entity class object.
    for (size_t i = 0; i < xmlrpcFindResult.size(); i++)
    {
        entities.push_back((*(registryFuncs.factoryFunc))(this, xmlrpcFindResult[i]));
    }

    return entities;
}
int main(int argc, char* argv[]) {

	if(argc != 2) {
		cout << "Uso: " << argv[0] << " palavras.txt" << endl;
		exit(-1);
	}
	//Inicializa o dicionario
	init_dict(argv[1]);	

	//Gera as palavras com até cinco letras
	Dict::iterator itset;
	tic();
	while(true) {
		int tamanho = gera_tamanho_palavra();
		char *new_word = gera_palavra(tamanho);

		itset = mydict.find(new_word);

		if(itset != mydict.end()) {
			mydict_found.insert(*itset);
			mydict.erase(*itset);
			qtd_encontradas++;
			
			imprime_prop();

			float prop = qtd_encontradas / (float) total_palavras;
			if(prop >= 1.0)
				break;
		}
		
		free(new_word);
	}

	cout << mydict_found.size() << ":" << mydict.size() << endl;

	total_palavras = mydict.size();

	controle=1;

	// Junta duas palavras para gerar palavras maiores
	Dict::iterator it[2];
	char* combined[2];
	for(it[0] = mydict_found.begin(); it[0]!=mydict_found.end(); ++it[0]) {
		for(it[1] = mydict_found.begin(); it[1]!=mydict_found.end(); ++it[1]) {
			combined[0] = mystrcat(*it[0], *it[1]);
			combined[1] = mystrcat(*it[1], *it[0]);
			
			for(int i=0; i<2; i++) {
				itset = mydict.find(combined[i]);
				if(itset != mydict.end()) {
					//cout << qtd_encontradas << " - combined: " << combined[i] << endl;
					mydict_found.insert(*itset);
					mydict.erase(*itset);
					qtd_encontradas++;

					imprime_prop();

					float prop = qtd_encontradas / (float) total_palavras;
					if(prop >= 1.0)
						break;
				}
				free(combined[i]);
			}
		}
	}
		
	fclose(arq_palavras);
	cout << "elapsed time: " << toc() << endl;

	return 0;
}