/** * 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(); } }
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); }
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; }
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); }
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); }
CAMLprim value caml_hll_size(value hll) { hll_t *_hll = (hll_t*)hll; double size = hll_size(_hll); return caml_copy_double(size); }