Example #1
0
ssize_t
unpack_array(mnbytestream_t *bs, int fd, mnarray_t *v)
{
    uint32_t elnum, i;
    ssize_t nread;

    if ((nread = unpack_long(bs, fd, &elnum)) < 0) {
        TRRET(UNPACK_ECONSUME);
    }

    array_init(v, 0, sizeof(amqp_value_t *),
               NULL,
               (array_finalizer_t)array_item_fini);

    for (i = 0; i < elnum; ++i) {
        ssize_t n;
        amqp_value_t **value;

        if ((value = array_incr(v)) == NULL) {
            FAIL("array_incr");
        }

        *value = NULL;
        if ((n = unpack_field_value(bs, fd, value)) < 0) {
            amqp_value_destroy(value);
            TRRET(UNPACK_ECONSUME);
        }
        nread += n;
    }
    return nread;
}
Example #2
0
Array * page_rank(Table * inbound, unsigned int order, float alpha, float convergence, unsigned int max_times)
{
        register int t = 0, k, i;
        register float norm2 = 1.0, prod_scalar, x;
        unsigned int total_size = order;
        Array * vector = initial(total_size);
        Array * new_vector = initial(total_size);
        Array * tmp;



        x = 1.0 - alpha;

        while (t < max_times && norm2 >= convergence) {
                t++;
                norm2 = 0.0;
                prod_scalar = 0.0;

                for (k = 0; k < total_size; k++) {
                        if (is_sink(inbound, k))
                                prod_scalar += array_get(vector, k) * alpha;
                }
                prod_scalar += x;

                for (k = 0; k < total_size; k++) {
                        array_set(new_vector, k, prod_scalar);
                        if (!is_sink(inbound, k)) {
                                tmp = table_get(inbound, k);
                                for (i = 0; i < array_len(tmp); i++) {
                                        array_incr(new_vector, k,
                                                   array_get(vector,
                                                             (int)array_get(tmp, i)) *
                                                   alpha);
                                }
                        }
                        norm2 += (array_get(new_vector, k) - array_get(vector, k)) *
                                (array_get(new_vector, k) - array_get(vector, k));
                }

                t++;

                norm2 = sqrt((double)norm2) / total_size;

                array_copy(vector, new_vector);
        }

        array_delete(new_vector);
        return normalize(vector);
}
Example #3
0
int
main(int argc, char *argv[])
{
    int opt, i;

    if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
        errx(1, "signal");
    }

    while ((opt = getopt(argc, argv, "hc:p:s:")) != -1) {
        switch (opt) {
            case 'c':
                mode = TSF_MODE_CLIENT;
                host = optarg;
                break;

            case 's':
                mode = TSF_MODE_SERVER;
                host = optarg;
                break;

            case 'p':
                port = strtol(optarg, NULL, 10);
                break;

            case 'h':
                usage(argv[0]);
                exit(0);
                break;

            default:
                usage(argv[0]);
                exit(0);
                break;
        }

    }

    host = strdup((host == NULL) ? "localhost" : host);

    if (port <= 0) {
        errx(1, "Invalid port: %d", port);
    }

    argc -= optind;
    argv += optind;

    array_init(&files,
               sizeof(mnbytes_t *),
               0,
               NULL,
               (array_finalizer_t)file_item_fini);
    for (i = 0; i < argc; ++i) {
        mnbytes_t **s;
        if ((s = array_incr(&files)) == NULL) {
            errx(1, "array_incr()");
        }
        *s = bytes_new_from_str(argv[i]);
        BYTES_INCREF(*s);
    }

    //TRACE("selected %s:%d", host, port);
    mrkthr_init();
    MRKTHR_SPAWN("run00", run00);
    mrkthr_loop();
    mrkthr_fini();
    array_fini(&files);
    free(host);
    host = NULL;

    return 0;
}