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) { 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); } fail_unless(hll_destroy(&h) == 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); }
int main(int argc, char *argv[]) { long i; struct HLL hll; if(hll_init(&hll, 16) == -1) { perror("hll_init"); exit(1); } for(i = 0; i < 100000000; i++) { long r = random() % 1000000; hll_add(&hll, &r, sizeof(r)); } printf("Estimate: %f\n", hll_count(&hll)); hll_destroy(&hll); return 0; }
CAMLprim value caml_hll_add(value hll, value key) { hll_t *_hll = (hll_t*)hll; hll_add(_hll, String_val(key)); return Val_unit; }