コード例 #1
0
ファイル: set.c プロジェクト: Affirm/statsite
/**
 * Returns the size of the set. May be approximate.
 * @arg s The set to query
 * @return The size of the set.
 */
uint64_t set_size(set_t *s) {
    switch (s->type) {
        case EXACT:
            return s->store.s.count;

        case APPROX:
            return ceil(hll_size(&s->store.h));

        default:
            abort();
    }
}
コード例 #2
0
ファイル: test_hll.c プロジェクト: Affirm/statsite
END_TEST

START_TEST(test_hll_size)
{
    hll_t h;
    fail_unless(hll_init(10, &h) == 0);

    double s = hll_size(&h);
    fail_unless(s == 0);

    fail_unless(hll_destroy(&h) == 0);
}
コード例 #3
0
ファイル: main.c プロジェクト: pombredanne/funzone
int main() {
    hll_t *hll = malloc(sizeof(hll_t));
    int res = hll_init(18, hll);
    char line[MAXLINELEN];
    double after;
    while (fgets(line, MAXLINELEN, stdin))  {
        hll_add(hll, line);
    }

    after = hll_size(hll);
    printf("%.1f\n", after);
    hll_destroy(hll);
    return 0;
}
コード例 #4
0
ファイル: test_hll.c プロジェクト: Affirm/statsite
END_TEST

START_TEST(test_hll_add_size)
{
    hll_t h;
    fail_unless(hll_init(10, &h) == 0);

    char buf[100];
    for (int i=0; i < 100; i++) {
        fail_unless(sprintf((char*)&buf, "test%d", i));
        hll_add(&h, (char*)&buf);
    }

    double s = hll_size(&h);
    fail_unless(s > 95 && s < 105);

    fail_unless(hll_destroy(&h) == 0);
}
コード例 #5
0
ファイル: test_hll.c プロジェクト: Affirm/statsite
END_TEST

START_TEST(test_hll_error_bound)
{
    // Precision 14 -> variance of 1%
    hll_t h;
    fail_unless(hll_init(14, &h) == 0);

    char buf[100];
    for (int i=0; i < 10000; i++) {
        fail_unless(sprintf((char*)&buf, "test%d", i));
        hll_add(&h, (char*)&buf);
    }

    // Should be within 1%
    double s = hll_size(&h);
    fail_unless(s > 9900 && s < 10100);

    fail_unless(hll_destroy(&h) == 0);
}
コード例 #6
0
ファイル: stubs.c プロジェクト: pombredanne/ocaml-hll
CAMLprim value
caml_hll_size(value hll) {
    hll_t *_hll = (hll_t*)hll;
    double size = hll_size(_hll);
    return caml_copy_double(size);
}