예제 #1
0
ImportInfo::ImportInfo( Dict & attrs ) : 
	attrs( attrs )
{
	Dict::iterator it = attrs.find( FROM );
	if ( it == attrs.end() ) {
		throw Mishap( "Missing attribute in import" ).culprit( "Attribute", FROM );
	}
	this->from = it->second;
	
	set< string > matches;
	set< string > intos;
	for (
		Dict::iterator it = attrs.begin();
		it != attrs.end();
		++it
	) {
		if ( it->first.compare( 0, MATCH_SIZE, MATCH ) == 0 ) {
			matches.insert( it->second );
		} else if ( it->first.compare( 0, INTO_SIZE, INTO ) == 0 ) {
			intos.insert( it->second );
		}
	}
	
	this->match_tags = fetchFacetSet( matches );
	this->into_tags = fetchFacetSet( intos );
}
TransactionType
transaction_type_from_verb(wxString const& p_phrase)
{
    typedef map<wxString, TransactionType> Dict;
    static Dict dict;
    static bool calculated_already = false;
    if (!calculated_already)
    {
        JEWEL_ASSERT (dict.empty());
        dict[expenditure_verb()] = TransactionType::expenditure;
        dict[revenue_verb()] = TransactionType::revenue;
        dict[balance_sheet_verb()] = TransactionType::balance_sheet;
        dict[envelope_verb()] = TransactionType::envelope;
        dict[generic_verb()] = TransactionType::generic;
        calculated_already = true;
    }
    JEWEL_ASSERT (!dict.empty());
    JEWEL_ASSERT
    (   dict.size() ==
        static_cast<Dict::size_type>(TransactionType::num_transaction_types)
    );
    Dict::const_iterator const it = dict.find(p_phrase);
    if (it == dict.end())
    {
        JEWEL_THROW
        (   InvalidTransactionTypeException,
            "wxString passed to transaction_type_from_verb does not "
            "correspond to any TransactionType."
        );
    }
    JEWEL_ASSERT (it != dict.end());
    return it->second;
}
예제 #3
0
파일: Variant.cpp 프로젝트: lailongwei/llbc
LLBC_Variant::LLBC_Variant(const Dict &dictVal)
{
    _holder.type = LLBC_VariantType::VT_DICT_DFT;
    if (!dictVal.empty())
    {
        _holder.dict= new Dict();
        _holder.dict->insert(dictVal.begin(), dictVal.end());
    }
}
예제 #4
0
파일: split.cpp 프로젝트: angilyu/Utility
// ---- Split ----
int getWord(const char* begin, const char* findAfter, const Dict& dict) {
    while (*findAfter != '\0') {
        string s(begin, findAfter + 1);
        if (dict.find(s) != dict.end())
            return findAfter - begin + 1;
        ++findAfter;
    }

    return -1;
}
예제 #5
0
FusionOperator IFusionOperator::fromString(const std::string& type)
{
    typedef map<string, FusionOperator, pfs::utils::StringUnsensitiveComp> Dict;
    static Dict v =
            map_list_of
            ("debevec", DEBEVEC)
            ("robertson", ROBERTSON)
            ("robertson-auto", ROBERTSON_AUTO)
            ;

    Dict::const_iterator it = v.find(type);
    if (it != v.end())
    {
        return it->second;
    }
    return DEBEVEC;
}
예제 #6
0
파일: Hello.cpp 프로젝트: wuhua988/icm
std::string
demo::__toString(const Dict& arg)
{
  std::string result = "{";
  for(Dict::const_iterator it = arg.begin(); it != arg.end(); ++it)
  {
    result += "<";
    result += __toString(it->first);
    result += ",";
    result += __toString(it->second);
    result += ">";
    result += " ";
  }
  trimEnd(result);
  result += "}";
  return result;
}
// Calcula a proporcao de palavras com ateh 5 letras
void calc_proporcao() {
	for(int i=0; i<6; i++)
    	qtd_palavra[i] = 0;
    
    Dict::iterator it;
    for(it=mydict.begin(); it!=mydict.end(); ++it) {
    	if(strlen(*it) <=5 ) {
    		qtd_palavra[strlen(*it)]++;
    		qtd_palavra[0]++;
    	}
    }
	
    for(int i=0; i<6; i++)
        cout << i << ":" << qtd_palavra[i] << endl;

	cout << "total prop: " << qtd_palavra[0] << endl;
    total_palavras = qtd_palavra[0];
}
예제 #8
0
bool test_dict_non_const_square_brackets_operator()
{
	cout << "Testing non const operator[] to ensure it is inserting values as expected" << endl << endl;
	map<string, EMObject> objects = get_test_dict_keys();

	Dict dict;

	// Here is where the insertion occurs
	map<string, EMObject>::const_iterator mapIt = objects.begin();
	for( ; mapIt != objects.end(); ++mapIt )
	{
		dict[mapIt->first] = mapIt->second;
	}

	bool success = true;


	for( mapIt = objects.begin(); mapIt != objects.end(); ++mapIt )
	{
		bool found = false;
		cout << "Testing the insertion of map key/value pair with key " << mapIt->first << " (inserted into Dict with operator[]) ..... ";
		for( Dict::const_iterator it = dict.begin(); it != dict.end(); ++it )
		{
			if ( it->first == mapIt-> first && it->second == mapIt->second )
			{
				found = true;
				break;
			}
		}

		if ( found )
			cout << "passed";
		else
		{
			cout << "FAILED";
			success = false;
		}

		cout << endl;
	}

	print_success_message(success);
	return success;
}
예제 #9
0
ResponseCurveType ResponseCurve::fromString(const std::string& type)
{
    typedef map<string, ResponseCurveType, pfs::utils::StringUnsensitiveComp> Dict;
    static Dict v =
            map_list_of
            ("log10", RESPONSE_LOG10)
            ("log", RESPONSE_LOG10)
            ("linear", RESPONSE_LINEAR)
            ("gamma", RESPONSE_GAMMA)
            ("srgb", RESPONSE_SRGB)
            ;

    Dict::const_iterator it = v.find(type);
    if ( it != v.end() )
    {
        return it->second;
    }
    return RESPONSE_LINEAR;
}
int main(int argc, char ** argv)
{
    DebugInfo::set_visible(true);
    Int io(19);
    cout << io << endl;
    int ii = io;
    cout << ii << endl;

    long int il = io;
    cout << il << endl;

    io = 9;
    cout << io << endl;

    Float fo(19.34);
    cout << fo << endl;
    int fi = fo;
    cout << fi << endl;

    double d = fo;
    cout << d << endl;

    Str so("ciao");
    cout << so << endl;
    std::string ss = so;
    cout << ss << endl;
    cout << so.str() << endl;
    cout << "str(" << so << "): " << str(so) << endl;
    cout << "repr(" << so << "): " << repr(so) << endl;

    List l;
    l.append(io);
    l.append(fo);
    l.append(Int(101));
    l.append(so);
    l.append(Float(1.01));
    cout << "======" << endl;
    cout << l[0] << endl;
    cout << l[1] << endl;
    cout << l[2] << endl;
    cout << l[3] << endl;
    cout << l[4] << endl;
    cout << "======" << endl;
    cout << l << '\n' << flush;
    cout << "======" << endl;
    l[2] = Float(4.567001);
    l[0] = Str("alfabeta");
    List ll;
    ll.append(Int(7));
    ll.append(Float(1.7));
    l.append(Tuple(ll));
    cout << l << '\n' << flush;
    cout << "======" << endl;
    Tuple t(l);
    cout << t << endl;
    cout << "======" << endl;

    Dict dct;
    dct[Str("alfa")] = Float(2.01);
    dct[Int(10)] = Str("Ciao");
    dct[Float(1.01)] = t;
    cout << dct << endl;
    
    dct[9.99] = "about ten";
    cout << dct << endl;
    dct["a random number"] = 0.3145678;
    dct["a list"] = List();
    dct["a list"].append("alfa");
    dct["a list"].append(0.01);
    dct["a subdict"] = Dict();
    dct["a subdict"][10] = "ten";
    dct["a subdict"]["ten"] = 10;
    dct["a subdict"]["a sublist"] = List();
    dct["a subdict"]["a sublist"].append(4);
    dct["a subdict"]["a sublist"].append("4");
    cout << "dct: " << dct << endl;
    cout << "dct[\"a subdict\"]: " << dct["a subdict"] << endl;
    cout << "dct[\"a subdict\"][\"a sublist\"]: " << dct["a subdict"]["a sublist"] << endl;
    cout << "is_instance<Dict>(dct[\"a subdict\"].get_object()) == " << is_instance<Dict>(dct["a subdict"].get_object()) << std::endl;
    cout << "is_instance<Dict>(dct[\"a list\"].get_object()) == " << is_instance<Dict>(dct["a list"].get_object()) << std::endl;
    cout << "is_instance<Dict>(dct[\"a subdict\"].get_object()) == " << is_instance<Dict>(dct) << std::endl;
    cout << "is_instance<Dict>(dct[\"a list\"].get_object()) == " << is_instance<Dict>(ll) << std::endl;
    cout << "is_instance<Dict>(dct[\"a subdict\"].get_object()) == " << is_instance<List>(dct) << std::endl;
    cout << "is_instance<Dict>(dct[\"a list\"].get_object()) == " << is_instance<List>(ll) << std::endl;

    for(Tuple::const_iterator i = t.begin(); i != t.end(); ++i)
    {
        cout << "|t|" << *i << endl;
    }
    for(Dict::const_iterator i = dct.begin(); i != dct.end(); ++i)
    {
        cout << "|d|" << i->first << " = " << i->second << endl;
    }
    cout << "NONE.is<None>() ->" << NONE.is<None>() << endl;
    cout << "NONE.is<Dict>() ->" << NONE.is<Dict>() << endl;
    cout << "dct.is<Dict>() ->" << dct.is<Dict>() << endl;
    cout << "NONE.class_name() ->" << NONE.class_name() << endl;
    cout << "dct.class_name() ->" << dct.class_name() << endl;
    cout << "l.class_name() ->" << l.class_name() << endl;

    cout << "NONE: " << bool(NONE) << endl;
    cout << "Int(1): " << bool(Int(1)) << endl;
    cout << "Int(0): " << bool(Int(0)) << endl;
    cout << "Float(1.0): " << bool(Float(1.0)) << endl;
    cout << "Float(0.0): " << bool(Float(0.0)) << endl;
    cout << "Str(\"ciao\"): " << bool(Str("ciao")) << endl;
    cout << "Str(): " << bool(Str()) << endl;
    Dict bd;
    cout << bd << ": " << bool(bd) << endl;
    bd[10] = 10;
    cout << bd << ": " << bool(bd) << endl;
    Dict bo;
    cout << bo << ": " << bool(bo) << endl;
    bo[10] = 10;
    cout << bo << ": " << bool(bo) << endl;
    Section bs;
    cout << bs << ": " << bool(bs) << endl;
    bs[10] = 10;
    cout << bs << ": " << bool(bs) << endl;

    Object bp;
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = Int(10);
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = Float(10);
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = Bool(TRUE);
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = Str();
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = bd;
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = bo;
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;
    bp = bs;
    cout << "Object(" << bp << "): " << flush << bool(bp) << endl;


    cout << "-----" << endl;
    Tuple t_t;
    cout << t_t << endl;
    t_t = unrepr("(1, 2, 3)");
    cout << t_t << endl;

    cout << "-----" << endl;
    Int   s_i(10);
    Float s_f(10.1);
    Bool  s_b(TRUE);
    Str   s_s("string");
    Tuple s_t("(1, 2, 3)");
    List  s_l("[1, 2, 3]");
    Dict  s_d("{\"a\": 0, \"b\": 1}");
    Dict  s_o("{\"a\": 0, \"b\": 1}");

    ReprType::enum_type rtype[3] = {ReprType::CONFIG, ReprType::CONFIGSPEC, ReprType::CPP};
    for(int i = 0; i < 3; ++i)
    {
        cout << "=== " << ReprType::label(rtype[i]) << endl;
        cout << "i:\t" << s_i << "\t:\t" << grepr(s_i, rtype[i]) << endl;
        cout << "f:\t" << s_f << "\t:\t" << grepr(s_f, rtype[i]) << endl;
        cout << "b:\t" << s_b << "\t:\t" << grepr(s_b, rtype[i]) << endl;
        cout << "s:\t" << s_s << "\t:\t" << grepr(s_s, rtype[i]) << endl;
        cout << "t:\t" << s_t << "\t:\t" << grepr(s_t, rtype[i]) << endl;
        cout << "l:\t" << s_l << "\t:\t" << grepr(s_l, rtype[i]) << endl;
        cout << "d:\t" << s_d << "\t:\t" << grepr(s_d, rtype[i]) << endl;
        cout << "o:\t" << s_o << "\t:\t" << grepr(s_o, rtype[i]) << endl;
    }

    cout << "=====" << endl;
    Object x = unrepr("\"alfabeta\"");
    Object y = unrepr("{1: 3, \"abc\": (2, 4.5, \"xxx\"), 4.5:{2:3}}");
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
    cout << "swap()..." << endl;
    swap(x, y);
    cout << "swapped." << endl;
    cout << "x = " << flush << x << endl;
    cout << "y = " << flush << y << endl;
}
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;
}
예제 #12
0
int main(int argc, char** argv)
{
	Dict data;

	FILE* fNumbers = fopen("numbers.txt", "r");
	FILE* fresult = fopen("run_result.txt", "w");

	int32_t currentNumber = 1;
	int ch;


	while((ch = getc(fNumbers)) != EOF) {
		if(ch == '\n') {
			uint32_t key1 = currentNumber / keymax2;
			uint32_t key2 = currentNumber % keymax2;
			Dict::iterator kit = data.find(key1);
			
			uint32_t* &subarray = data[key1];
			if(kit == data.end()) {
				subarray = new uint32_t[keymax2];
				memset(subarray, 0, sizeof(uint32_t) * keymax2);
			}
			
			uint32_t &currentCounter = subarray[key2];
			currentCounter += 1;
			if(currentCounter == 2) {
				resultHeader = new Result(currentNumber, &currentCounter, resultHeader);
			}

			currentNumber = 1;
		}
		else if(ch != '\r') {
			currentNumber = (currentNumber * 10) + A2I(ch);
		}
	}

	wLineBuffer[99] = 0;
	while(resultHeader != NULL) {
		char* chptr = &wLineBuffer[99];
		I2A(chptr, resultHeader->data);

		fputc('"', fresult);
		fputs(chptr + 1, fresult);
		fputs("\", ", fresult);

		chptr = &wLineBuffer[99];
		I2A(chptr, *resultHeader->countPtr);
		fputs(chptr, fresult);
		fputc('\n', fresult);

		Result* next = resultHeader->nextPtr;
		delete resultHeader;
		resultHeader = next;
	}

	fclose(fresult);
	fclose(fNumbers);
	

	for(Dict::iterator it = data.begin(); it != data.end(); it++) {
		delete[] it->second;
	}

	return 0;
}