Ejemplo n.º 1
0
str *commonprefix(list<str *> *m) {
    /**
    Given a list of pathnames, returns the longest common leading component
    */
    list<str *> *__24;
    list<str *>::for_in_loop __123;
    __ss_int __26, __27, __28, i;
    str *item, *prefix;

    if ((!___bool(m))) {
        return const_1;
    }
    prefix = m->__getfast__(0);

    FOR_IN(item,m,24,26,123)

        FAST_FOR(i,0,len(prefix),1,27,28)
            if (__ne(prefix->__slice__(2, 0, (i+1), 0), item->__slice__(2, 0, (i+1), 0))) {
                prefix = prefix->__slice__(2, 0, i, 0);
                if ((i==0)) {
                    return const_1;
                }
                break;
            }
        END_FOR

    END_FOR

    return prefix;
}
Ejemplo n.º 2
0
str *realpath(str *filename) {
    /**
    Return the canonical path of the specified filename, eliminating any
    symbolic links encountered in the path.
    */
    list<str *> *bits;
    str *component, *newpath, *resolved;
    __ss_int __40, __41, i;

    if (isabs(filename)) {
        bits = ((new list<str *>(1, const_4)))->__add__((filename->split(const_4))->__slice__(1, 1, 0, 0));
    }
    else {
        bits = filename->split(const_4);
    }

    FAST_FOR(i,2,(len(bits)+1),1,40,41)
        component = joinl(bits->__slice__(3, 0, i, 0));
        if (islink(component)) {
            resolved = _resolve_link(component);
            if ((resolved==0)) {
                return abspath(joinl(((new list<str *>(1, component)))->__add__(bits->__slice__(1, i, 0, 0))));
            }
            else {
                newpath = joinl(((new list<str *>(1, resolved)))->__add__(bits->__slice__(1, i, 0, 0)));
                return realpath(newpath);
            }
        }
    END_FOR

    return abspath(filename);
}
Ejemplo n.º 3
0
str *DynamInt::__div__(DynamInt *num) {
    /**
    Overloaded == function
    Checks if this DynamInt is equal to this one
    
    @param  num reference to an existing DynamInt
    @return added DynamInt
    */
    str *remainderString, *result, *xString;
    int __0, __1, i, j, m, n;
    DynamInt *cur, *remainder, *temp, *x;

    j = 0;
    result = const_0;
    xString = const_0;
    remainderString = const_0;
    temp = (new DynamInt(((int )(0))));
    n = 0;

    while ((n<len(this->data))) {
        result = result->__add__(const_1);
        xString = xString->__add__(const_1);
        n = (n+1);
    }
    m = 0;

    while ((m<len(num->data))) {
        remainderString = remainderString->__add__(const_1);
    }
    cur = (new DynamInt(((int )(0))));
    cur->setData((this->data)->__getitem__(0));
    remainder = (new DynamInt(((int )(0))));
    remainder->setData(remainderString);

    while ((j<len(this->data))) {
        x = (new DynamInt(((int )(0))));
        x->setData(xString);

        FAST_FOR(i,0,(len(num->data)-1),1,0,1)
            temp->setData(x->data);
            x->setData(x->__add__(num));
            if (__gt(x, cur)) {
                result = __add_strs(3, result->__slice__(2, 0, (j+1), 0), __str(i), result->__slice__(1, (j+2), 0, 0));
                break;
            }
        END_FOR

        j = (j+1);
        remainder->setData(cur->__sub__(temp));
        if ((j==len(this->data))) {
            cur->setData(__str(remainder));
        }
        cur->setData((remainder->data)->__add__((this->data)->__getitem__(j)));
    }
    return result;
}
Ejemplo n.º 4
0
void __init() {
    const_0 = new str("__main__");

    __name__ = new str("random_seq");

    orig_seq = (((new list<__ss_int>(1, 0)))->__mul__(15))->__add__(((new list<__ss_int>(1, 1)))->__mul__(15));
    seen_seq = (new list<__ss_int>());
    if (__eq(__name__, const_0)) {
        num = 5000;

        FAST_FOR(i,0,num,1,4,5)
            fastest_create_random_sequence();
        END_FOR

    }
}
Ejemplo n.º 5
0
str *DynamInt::__mul__(DynamInt *num) {
    /**
    Overloaded add function
    Adds an existing DynamInt to this one
    @param  num reference to an existing DynamInt
    @return added DynamInt
    */
    str *bottom, *product, *top;
    int __2, __3, carry, i, j, k, n, resultSize, tempProduct;

    if (__gt(this, num)) {
        top = this->data;
        bottom = num->data;
    }
    else {
        top = num->data;
        bottom = this->data;
    }
    tempProduct = 0;
    product = const_0;
    resultSize = (this->size+num->size);

    FAST_FOR(n,0,resultSize,1,2,3)
        product = (const_1)->__add__(product);
    END_FOR

    i = (len(bottom)-1);

    while ((i>=0)) {
        carry = 0;
        j = (len(top)-1);

        while ((j>=0)) {
            k = (i+j);
            tempProduct = __int((((__int(top->__getitem__(j))*__int(bottom->__getitem__(i)))+__int(product->__getitem__(k)))+carry));
            product = __add_strs(3, product->__slice__(2, 0, (k+1), 0), __str(__mods(tempProduct, 10)), product->__slice__(1, (k+2), 0, 0));
            carry = __int(__divs(tempProduct, 10));
            j = (j-1);
        }
        if ((carry!=0)) {
            product = __add_strs(3, product->__slice__(2, 0, i, 0), __str(carry), product->__slice__(1, (i+1), 0, 0));
        }
        i = (i-1);
    }
    return product;
    return 0;
}