当前位置: 首页>>代码示例>>C++>>正文


C++ DFA::size方法代码示例

本文整理汇总了C++中DFA::size方法的典型用法代码示例。如果您正苦于以下问题:C++ DFA::size方法的具体用法?C++ DFA::size怎么用?C++ DFA::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DFA的用法示例。


在下文中一共展示了DFA::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TEST_F(TestDFA, Equivalence) {
    instance << "q0";
    instance << "q1";
    instance.addTransition("q0", "q1", 'a');
    instance.accept("q1");

    DFA copy;
    ASSERT_NO_THROW(copy = ~~instance);
    ASSERT_EQ(instance.size(), copy.size());

    DFA almostEqual;
    almostEqual << "q0";
    almostEqual << "q1";
    almostEqual.addTransition("q0", "q1", 'b');
    almostEqual.accept("q1");

    bool r;
    ASSERT_NO_THROW(r = (copy == instance));
    EXPECT_TRUE(r);
    EXPECT_EQ(2, instance.size());
    EXPECT_EQ(2, copy.size());

    ASSERT_NO_THROW(r = (almostEqual == instance));
    EXPECT_FALSE(r);
    EXPECT_EQ(2, instance.size());
    EXPECT_EQ(2, almostEqual.size());
}
开发者ID:Ghabriel,项目名称:FormalLanguageUtils,代码行数:27,代码来源:DFA_test.cpp

示例2: to_string

TEST_F(TestDFA, MinimizationStress) {
    auto fn = [](unsigned i) -> std::string {
        return std::to_string(i);
    };

    unsigned limit = 999;
    instance.reserve(limit);
    for (unsigned i = 0; i < limit; i++) {
        instance << ("q" + fn(i));
    }

    instance.accept("q" + fn(limit - 2));
    instance.accept("q" + fn(limit - 1));
    instance.addTransition("q0", "q1", 'a');
    instance.addTransition("q0", "q2", 'b');
    for (unsigned i = 1; i < limit - 2; i += 2) {
        unsigned next = (i + 1) % limit;
        instance.addTransition("q" + fn(i), "q" + fn(next), 'a');
        instance.addTransition("q" + fn(next), "q" + fn(i), 'a');
        instance.addTransition("q" + fn(i), "q" + fn((i + 2) % limit), 'b');
        instance.addTransition("q" + fn(next), "q" + fn((i + 3) % limit), 'b');
    }

    DFA other;
    ASSERT_NO_THROW(other = instance.minimized());
    EXPECT_EQ((limit + 1)/2, other.size());
}
开发者ID:Ghabriel,项目名称:FormalLanguageUtils,代码行数:27,代码来源:DFA_test.cpp

示例3: add

bool DFAMerger::add(const DFA& dfa) {
	if (_start == -1) {
		_start = new_state();
	}
	assert(_start >= 0);

	size_t size = dfa.size();
	size_t base = _trans.size();
	_trans.resize(base + size);

	for (size_t i = 0; i < size; i++) {
		const DFATran& tran = dfa[i];
		for (DFATran::const_iterator it = tran.begin();
				it != tran.end(); ++it) {
			_trans[base + i][it->first].insert(base + it->second);
		}
		const Tag& tag = dfa.tags(i);
		if (!tag.empty()) {
			Tag& to = _tags[base + i];
			to.insert(tag.begin(), tag.end());
		}
	}


	_trans[_start][EPSILON].insert(base + dfa.start());

	const States& last = dfa.last();
	for (States::const_iterator it = last.begin();
		it != last.end(); ++it) {
		_last.insert(base + *it);
	}

	return true;
}
开发者ID:LelouchHe,项目名称:mpl,代码行数:34,代码来源:dfa_merger.cpp

示例4: parse_regex_group

unsigned long regex_parser::parse_regex_group(FILE *file, int group[]){
	unsigned long size = _INFINITY;
	do {
		NFA *nfa = group_regex(file, group);
		nfa->remove_epsilon();
		nfa->reduce();
		DFA *dfa = nfa->nfa2dfa();
		delete nfa;
		size = dfa->size();
		delete dfa;
	} while (0);

	return size;
}
开发者ID:bunnywj,项目名称:GProject,代码行数:14,代码来源:parser.c

示例5: print_dfa

void print_dfa(const DFA& dfa) {
	cout << "start  : " << dfa.start() << endl;
	cout << "last   : ";
	const ::mpl::lexer::detail::States& last = dfa.last();
	print_set(last);
	cout << endl;

	for (size_t i = 0; i < dfa.size(); i++) {
		const ::mpl::lexer::detail::DFATran& tran = dfa[i];
		for (::mpl::lexer::detail::DFATran::const_iterator it = tran.begin();
			it != tran.end(); ++it) {
			cout << i << "(";
			if (it->first == ::mpl::lexer::detail::EPSILON) {
				cout << "\\0";
			} else if (it->first == ::mpl::lexer::detail::OTHER) {
				cout << "-1";
			} else {
				//cout << it->first;
				cout << "0x" << hex << (int)(it->first & 0xFF) << dec;
			}
			cout << ")";
			cout << "\t->\t";
			cout << it->second;
			cout << endl;
		}
	}

	for (::mpl::lexer::detail::States::const_iterator it = last.begin();
		it != last.end(); ++it) {
		const ::mpl::lexer::detail::Tag& tag = dfa.tags(*it);

		cout << *it << ": ";
		print_set(tag);
		cout << endl;
	}
}
开发者ID:LelouchHe,项目名称:mpl,代码行数:36,代码来源:dfa.cpp


注:本文中的DFA::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。