示例#1
0
    // TODO: shortcut number of comparisons
    Interval::IntervalComparison Interval::compare(const Interval& other) const {

        //
        // Intersect cases
        //

        if (intersects(*this, other)) {
            if (exact(*this, other)) {
                return INTERVAL_EQUALS;
            }
            if (within(*this, other)) {
                return INTERVAL_WITHIN;
            }
            if (within(other, *this)) {
                return INTERVAL_CONTAINS;
            }
            if (precedes(*this, other)) {
                    return INTERVAL_OVERLAPS_BEFORE;
            }
            return INTERVAL_OVERLAPS_AFTER;
        }

        //
        // Non-intersect cases
        //

        if (precedes(*this, other)) {
            return INTERVAL_PRECEDES;
        }
        return INTERVAL_SUCCEDS;
    }
示例#2
0
    // TODO: shortcut number of comparisons
    Interval::IntervalComparison Interval::compare(const Interval& other) const {
        //
        // Intersect cases
        //

        // TODO: rewrite this to be member functions so semantics are clearer.
        if (intersects(*this, other)) {
            if (exact(*this, other)) {
                return INTERVAL_EQUALS;
            }
            if (within(*this, other)) {
                return INTERVAL_WITHIN;
            }
            if (within(other, *this)) {
                return INTERVAL_CONTAINS;
            }
            if (precedes(*this, other)) {
                return INTERVAL_OVERLAPS_BEFORE;
            }
            return INTERVAL_OVERLAPS_AFTER;
        }

        //
        // Non-intersect cases
        //

        if (precedes(*this, other)) {
            if (0 == end.woCompare(other.start, false)) {
                return INTERVAL_PRECEDES_COULD_UNION;
            }
            return INTERVAL_PRECEDES;
        }

        return INTERVAL_SUCCEEDS;
    }
void tst_PluginDependencyGraph::treeDependencyTest()
{
	auto graph = treeGraph();

	auto p1Dependencies = graph.findDependencies("p1");
	auto p1Dependents = graph.findDependents("p1");

	auto p6Dependencies = graph.findDependencies("p6");
	auto p6Dependents = graph.findDependents("p6");

	QCOMPARE(p1Dependencies.size(), 5);
	QVERIFY(!contains(p1Dependencies, "p1"));
	QVERIFY(contains(p1Dependencies, "p2"));
	QVERIFY(contains(p1Dependencies, "p3"));
	QVERIFY(contains(p1Dependencies, "p4"));
	QVERIFY(contains(p1Dependencies, "p5"));
	QVERIFY(contains(p1Dependencies, "p6"));
	QVERIFY(precedes(p1Dependencies, "p6", "p5"));
	QVERIFY(precedes(p1Dependencies, "p5", "p4"));
	QVERIFY(precedes(p1Dependencies, "p5", "p3"));
	QVERIFY(precedes(p1Dependencies, "p4", "p2"));
	QVERIFY(precedes(p1Dependencies, "p3", "p2"));

	QCOMPARE(p1Dependents.size(), 0);
	QCOMPARE(p6Dependencies.size(), 0);

	QCOMPARE(p6Dependents.size(), 5);
	QVERIFY(contains(p6Dependents, "p1"));
	QVERIFY(contains(p6Dependents, "p2"));
	QVERIFY(contains(p6Dependents, "p3"));
	QVERIFY(contains(p6Dependents, "p4"));
	QVERIFY(contains(p6Dependents, "p5"));
	QVERIFY(!contains(p6Dependents, "p6"));
	QVERIFY(precedes(p6Dependents, "p1", "p2"));
	QVERIFY(precedes(p6Dependents, "p2", "p3"));
	QVERIFY(precedes(p6Dependents, "p2", "p4"));
	QVERIFY(precedes(p6Dependents, "p3", "p5"));
	QVERIFY(precedes(p6Dependents, "p4", "p5"));
}
示例#4
0
    // TODO: shortcut number of comparisons
    Interval::IntervalComparison Interval::compare(const Interval& other) const {
        //
        // Intersect cases
        //

        // TODO: rewrite this to be member functions so semantics are clearer.
        if (intersects(*this, other)) {
            if (exact(*this, other)) {
                return INTERVAL_EQUALS;
            }
            if (within(*this, other)) {
                return INTERVAL_WITHIN;
            }
            if (within(other, *this)) {
                return INTERVAL_CONTAINS;
            }
            if (precedes(*this, other)) {
                return INTERVAL_OVERLAPS_BEFORE;
            }
            return INTERVAL_OVERLAPS_AFTER;
        }

        //
        // Non-intersect cases
        //

        if (precedes(*this, other)) {
            // It's not possible for both endInclusive and other.startInclusive to be true because
            // the bounds would intersect. Refer to section on "Intersect cases" above.
            if ((endInclusive || other.startInclusive) && 0 == end.woCompare(other.start, false)) {
                return INTERVAL_PRECEDES_COULD_UNION;
            }
            return INTERVAL_PRECEDES;
        }

        return INTERVAL_SUCCEEDS;
    }
示例#5
0
/* The actual algorithm */
int findOptimalScore(Querymatch* matches, const unsigned int* matches_size, 
    Info* info) {

    /* Loop vars for C89 compiler */
    int i;
    int j;

    int match_num = *matches_size;

    int score[match_num];

    int totalmaxscore = 0;
    int bestmatch = -1;

    for(j = 0; j < match_num; j++) {

        unsigned int maxscore = matches[j].score;

        for(i = 0; i < j; i++) {

            int newscore = score[i] + matches[j].score;

            if(precedes(matches[i], matches[j]) && maxscore < newscore) {
                maxscore = newscore; 
                matches[j].prec = i; // setting predecessor index
            }
        }

        score[j] = maxscore;

        if(totalmaxscore < maxscore) {
            totalmaxscore = maxscore;
            bestmatch = j;
        }
    }

    info->overallmaxscore = totalmaxscore;

    return bestmatch;
}
示例#6
0
int main(){
    struct stack s;
    s.top = -1;

    char expression[MAXSIZE];
    char result[MAXSIZE];
    int i=0, resp=0, ch=0;
    while((ch = getchar()) != '\n')
        expression[i++] = ch;
    expression[i] = '\0';

    for(i=0; expression[i]; i++){
        if (isoperator(expression[i])){
            if(precedes(stacktop(&s), expression[i])){
                if((stacktop(&s) != '(') && (stacktop(&s) != ')'))
                    result[resp++] = pop(&s);
                else
                    pop(&s);
            }
            push(&s, expression[i]);
            printf("Pushed %c to stack. Result: %s\n", expression[i], result);
        }
        else{
            result[resp++] = expression[i];
        }
    }
    while(!empty(&s)){
        if ((stacktop(&s) != '(') && (stacktop(&s) != ')'))
            result[resp++] = pop(&s);
        else
            pop(&s);
    }

    result[resp] = '\0';

    printf("Result is: %s\n", result);
    exit(0);
}
示例#7
0
/// This takes a token that refers to a variable and it will return the token
/// to the expression that the variable is assigned to. If its not valid to
/// make such substitution then it will return the original token.
static const Token * followVariableExpression(const Token * tok, bool cpp, const Token * end = nullptr)
{
    if (!tok)
        return tok;
    // Skip following variables that is across multiple files
    if (end && end->fileIndex() != tok->fileIndex())
        return tok;
    // Skip array access
    if (Token::Match(tok, "%var% ["))
        return tok;
    // Skip pointer indirection
    if (tok->astParent() && tok->isUnaryOp("*"))
        return tok;
    // Skip following variables if it is used in an assignment
    if (Token::Match(tok->next(), "%assign%"))
        return tok;
    const Variable * var = tok->variable();
    const Token * varTok = getVariableInitExpression(var);
    if (!varTok)
        return tok;
    // Bailout. If variable value depends on value of "this".
    if (exprDependsOnThis(varTok))
        return tok;
    // Skip array access
    if (Token::simpleMatch(varTok, "["))
        return tok;
    if (var->isVolatile())
        return tok;
    if (!var->isLocal() && !var->isConst())
        return tok;
    if (var->isStatic() && !var->isConst())
        return tok;
    if (var->isArgument())
        return tok;
    const Token * lastTok = precedes(tok, end) ? end : tok;
    // If this is in a loop then check if variables are modified in the entire scope
    const Token * endToken = (isInLoopCondition(tok) || isInLoopCondition(varTok) || var->scope() != tok->scope()) ? var->scope()->bodyEnd : lastTok;
    if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, tok->varId(), false, nullptr, cpp)))
        return tok;
    if (precedes(varTok, endToken) && isAliased(varTok, endToken, tok->varId()))
        return tok;
    // Start at beginning of initialization
    const Token * startToken = varTok;
    while (Token::Match(startToken, "%op%|.|(|{") && startToken->astOperand1())
        startToken = startToken->astOperand1();
    // Skip if the variable its referring to is modified
    for (const Token * tok2 = startToken; tok2 != endToken; tok2 = tok2->next()) {
        if (Token::simpleMatch(tok2, ";"))
            break;
        if (tok2->astParent() && tok2->isUnaryOp("*"))
            return tok;
        if (tok2->tokType() == Token::eIncDecOp ||
            tok2->isAssignmentOp() ||
            Token::Match(tok2, "%name% .|[|++|--|%assign%")) {
            return tok;
        }

        if (const Variable * var2 = tok2->variable()) {
            if (!var2->scope())
                return tok;
            const Token * endToken2 = var2->scope() != tok->scope() ? var2->scope()->bodyEnd : endToken;
            if (!var2->isLocal() && !var2->isConst() && !var2->isArgument())
                return tok;
            if (var2->isStatic() && !var2->isConst())
                return tok;
            if (!var2->isConst() && (!precedes(tok2, endToken2) || isVariableChanged(tok2, endToken2, tok2->varId(), false, nullptr, cpp)))
                return tok;
            if (precedes(tok2, endToken2) && isAliased(tok2, endToken2, tok2->varId()))
                return tok;
            // Recognized as a variable but the declaration is unknown
        } else if (tok2->varId() > 0) {
            return tok;
        } else if (tok2->tokType() == Token::eName && !Token::Match(tok2, "sizeof|decltype|typeof") && !tok2->function()) {
            return tok;
        }
    }
    return varTok;
}