本文整理汇总了C++中CharReach类的典型用法代码示例。如果您正苦于以下问题:C++ CharReach类的具体用法?C++ CharReach怎么用?C++ CharReach使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CharReach类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBackwardReach
static
void getBackwardReach(const NGHolder &g, ReportID report, u32 lag,
map<s32, CharReach> &look) {
ue2::flat_set<NFAVertex> curr, next;
for (auto v : inv_adjacent_vertices_range(g.accept, g)) {
if (contains(g[v].reports, report)) {
curr.insert(v);
}
}
for (u32 i = lag + 1; i <= MAX_BACK_LEN; i++) {
if (curr.empty() || contains(curr, g.start) ||
contains(curr, g.startDs)) {
break;
}
next.clear();
CharReach cr;
for (auto v : curr) {
assert(!is_special(v, g));
cr |= g[v].char_reach;
insert(&next, inv_adjacent_vertices(v, g));
}
assert(cr.any());
look[0 - i] |= cr;
curr.swap(next);
}
}
示例2: TEST
TEST(ReverseTruffle, ExecMatch3) {
m128 mask1, mask2;
CharReach chars;
chars.set('a');
chars.set('B');
truffleBuildMasks(chars, (u8 *)&mask1, (u8 *)&mask2);
/* 0123456789012345678901234567890 */
char t1[] = "bbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaBbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
size_t len = strlen(t1);
for (size_t i = 0; i < 16; i++) {
const u8 *rv = rtruffleExec(mask1, mask2, (u8 *)t1, (u8 *)t1 + len - i);
ASSERT_NE((const u8 *)t1 - 1, rv); // not found
EXPECT_EQ('B', (char)*rv);
ASSERT_EQ((const u8 *)t1 + 32, rv);
}
// check that we match the 'a' bytes as well.
ASSERT_EQ('B', t1[32]);
t1[32] = 'b';
for (size_t i = 0; i < 16; i++) {
const u8 *rv = rtruffleExec(mask1, mask2, (u8 *)t1, (u8 *)t1 + len - i);
ASSERT_NE((const u8 *)t1 - 1, rv); // not found
EXPECT_EQ('a', (char)*rv);
ASSERT_EQ((const u8 *)t1 + 31, rv);
}
}
示例3: describeEdge
void describeEdge(FILE *f, const u16 *t, u16 i) {
for (u16 s = 0; s < N_CHARS; s++) {
if (!t[s]) {
continue;
}
u16 ss;
for (ss = 0; ss < s; ss++) {
if (t[s] == t[ss]) {
break;
}
}
if (ss != s) {
continue;
}
CharReach reach;
for (ss = s; ss < 256; ss++) {
if (t[s] == t[ss]) {
reach.set(ss);
}
}
fprintf(f, "%u -> %u [ label = \"", i, t[s]);
describeClass(f, reach, 5, CC_OUT_DOT);
fprintf(f, "\" ];\n");
}
}
示例4: getForwardReach
static
void getForwardReach(const raw_dfa &rdfa, map<s32, CharReach> &look) {
if (rdfa.states.size() < 2) {
return;
}
ue2::flat_set<dstate_id_t> curr, next;
curr.insert(rdfa.start_anchored);
for (u32 i = 0; i < MAX_FWD_LEN && !curr.empty(); i++) {
next.clear();
CharReach cr;
for (const auto state_id : curr) {
const dstate &ds = rdfa.states[state_id];
if (!ds.reports.empty() || !ds.reports_eod.empty()) {
return;
}
for (unsigned c = 0; c < N_CHARS; c++) {
dstate_id_t succ = ds.next[rdfa.alpha_remap[c]];
if (succ != DEAD_STATE) {
cr.set(c);
next.insert(succ);
}
}
}
assert(cr.any());
look[i] |= cr;
curr.swap(next);
}
}
示例5: findStopAlphabet
/** Find the set of characters that are not present in the reachability of
* graph \p g after a certain depth (currently 8). If a character in this set
* is encountered, it means that the NFA is either dead or has not progressed
* more than 8 characters from its start states. */
CharReach findStopAlphabet(const NGHolder &g, som_type som) {
const depth max_depth(MAX_STOP_DEPTH);
const InitDepths depths(g);
const map<NFAVertex, BoundedRepeatSummary> no_vertices;
CharReach stopcr;
for (auto v : vertices_range(g)) {
if (is_special(v, g)) {
continue;
}
if (depths.maxDist(g, v) >= max_depth) {
if (som == SOM_NONE) {
stopcr |= reduced_cr(v, g, no_vertices);
} else {
stopcr |= g[v].char_reach;
}
}
}
// Turn alphabet into stops.
stopcr.flip();
return stopcr;
}
示例6: TEST
TEST(ng_charreach, bitwise) {
CharReach cr;
CharReach cr2;
CharReach cr3;
CharReach cr4;
cr.set('a');
cr2.set('z');
cr3.set('a');
cr3.set('z');
ASSERT_TRUE(cr < cr3);
cr4 |= cr;
cr4 |= cr2;
ASSERT_TRUE(cr3 == cr4);
ASSERT_TRUE(cr3 == (cr | cr2));
ASSERT_TRUE(cr4 == (cr | cr2));
ASSERT_TRUE(cr == (cr & cr3));
ASSERT_TRUE(cr2 == (cr2 & cr3));
cr3 &= cr;
ASSERT_FALSE(cr3.test('z'));
}
示例7: describeEdge
static
void describeEdge(FILE *f, const mcsheng *m, const u16 *t, u16 i) {
for (u16 s = 0; s < N_CHARS; s++) {
if (!t[s]) {
continue;
}
u16 ss;
for (ss = 0; ss < s; ss++) {
if (t[s] == t[ss]) {
break;
}
}
if (ss != s) {
continue;
}
CharReach reach;
for (ss = s; ss < 256; ss++) {
if (t[s] == t[ss]) {
reach.set(ss);
}
}
fprintf(f, "%u -> %u [ ", i, t[s]);
if (i < m->sheng_end && t[s] < m->sheng_end) {
fprintf(f, "color = red, fontcolor = red ");
}
fprintf(f, "label = \"");
describeClass(f, reach, 5, CC_OUT_DOT);
fprintf(f, "\" ];\n");
}
}
示例8: make_pattern
// Ugly but simple.
string make_pattern() {
std::ostringstream oss;
oss << "^[";
for (size_t i = reach.find_first(); i != CharReach::npos;
i = reach.find_next(i)) {
oss << "\\x" << std::hex << std::setw(2) << std::setfill('0')
<< (unsigned)(i & 0xff) << std::dec;
}
oss << "]{" << min << "," << max << "}";
return oss.str();
}
示例9: mcclellanStartReachSize
u32 mcclellanStartReachSize(const raw_dfa *raw) {
if (raw->states.size() < 2) {
return 0;
}
const dstate &ds = raw->states[raw->start_anchored];
CharReach out;
for (unsigned i = 0; i < N_CHARS; i++) {
if (ds.next[raw->alpha_remap[i]] != DEAD_STATE) {
out.set(i);
}
}
return out.count();
}
示例10: nfaExecLbrTruf_dump
void nfaExecLbrTruf_dump(const NFA *nfa, const string &base) {
assert(nfa);
assert(nfa->type == LBR_NFA_TRUF);
StdioFile f(base + ".txt", "w");
const lbr_truf *lt = (const lbr_truf *)getImplNfa(nfa);
lbrDumpCommon(<->common, f);
CharReach cr = truffle2cr((const u8 *)<->mask1,
(const u8 *)<->mask2);
fprintf(f, "TRUFFLE model, scanning for: %s (%zu chars)\n",
describeClass(cr, 20, CC_OUT_TEXT).c_str(), cr.count());
fprintf(f, "\n");
dumpTextReverse(nfa, f);
}
示例11: nfaExecLbrShuf_dump
void nfaExecLbrShuf_dump(const NFA *nfa, const string &base) {
assert(nfa);
assert(nfa->type == LBR_NFA_SHUF);
StdioFile f(base + ".txt", "w");
const lbr_shuf *ls = (const lbr_shuf *)getImplNfa(nfa);
lbrDumpCommon(&ls->common, f);
CharReach cr = shufti2cr((const u8 *)&ls->mask_lo,
(const u8 *)&ls->mask_hi);
fprintf(f, "SHUF model, scanning for: %s (%zu chars)\n",
describeClass(cr, 20, CC_OUT_TEXT).c_str(), cr.count());
fprintf(f, "\n");
dumpTextReverse(nfa, f);
}