示例#1
0
void ComponentRepeat::notePositions(GlushkovBuildState &bs) {
    assert(m_max > 0);
    assert(m_max == NoLimit || m_max < MAX_MAX_BOUND);

    /* Note: We can construct smaller subgraphs if we're not maintaining edge
     * priorities. */

    // We create one copy only through a recursive call to notePositions(),
    // first() and last(). Then we clone its positions and store the
    // appropriate firsts and lasts values for the copies.
    posFirst = bs.getBuilder().numVertices();
    sub_comp->notePositions(bs);

    u32 copies = m_max < NoLimit ? m_max : MAX(m_min, 1);
    DEBUG_PRINTF("building %u copies of repeated region\n", copies);
    m_firsts.clear();
    m_lasts.clear();
    m_firsts.resize(copies);
    m_lasts.resize(copies);

    m_firsts[0] = sub_comp->first();
    m_lasts[0] = sub_comp->last();

    postSubNotePositionHook();

    posLast = bs.getBuilder().numVertices() - 1;
    u32 vcount = posLast + 1 - posFirst;

    // If we're making more than one copy, then our firsts and lasts must only
    // contain vertices inside [posFirst, posLast]: anything else means we have
    // an embedded anchor or otherwise weird situation.
    if (copies > 1) {
        checkPositions(m_firsts[0], bs);
        checkPositions(m_lasts[0], bs);
    }

    // Avoid enormous expansions
    if (vcount * copies > MAX_POSITIONS_EXPANDED) {
        throw ParseError("Bounded repeat is too large.");
    }

    // Add positions for the rest of the copies
    size_t copyPositions = vcount * (copies - 1);
    bs.getBuilder().makePositions(copyPositions);

    // Calculate our firsts and lasts for the copies
    for (u32 i = 1; i < copies; ++i) {
        m_firsts[i] = m_firsts[0];
        m_lasts[i] = m_lasts[0];
        u32 base = i * vcount;
        addBase(base, m_firsts[i], m_lasts[i]);
    }

    recordPosBounds(posFirst, bs.getBuilder().numVertices());
    precalc_firsts(); /* ComponentRepeat requires firsts to be calculated ahead
                       * of time and cached due to expense */
}
示例#2
0
void AsciiComponentClass::notePositions(GlushkovBuildState &bs) {
    // We should always be finalized by now.
    assert(finalized);

    NFABuilder &builder = bs.getBuilder();
    position = builder.makePositions(1);

    builder.addCharReach(position, cr);
    builder.setNodeReportID(position, 0 /* offset adj */);
    recordPosBounds(position, position + 1);
}