From f805ee746eec8bf99ffd38e63cd659cf76879e40 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Tue, 3 Dec 2013 14:32:31 -0500 Subject: [PATCH] regressions: Coverage for ck_hs_put_unique. --- regressions/ck_hs/benchmark/serial.c | 46 +++++++++++++++++++++++++--- regressions/ck_hs/validate/serial.c | 18 +++++++++-- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/regressions/ck_hs/benchmark/serial.c b/regressions/ck_hs/benchmark/serial.c index a121471..462bfff 100644 --- a/regressions/ck_hs/benchmark/serial.c +++ b/regressions/ck_hs/benchmark/serial.c @@ -103,8 +103,7 @@ set_remove(const char *value) unsigned long h; h = CK_HS_HASH(&hs, hs_hash, value); - ck_hs_remove(&hs, h, value); - return true; + return ck_hs_remove(&hs, h, value) != NULL; } static bool @@ -148,6 +147,15 @@ set_insert(const char *value) return ck_hs_put(&hs, h, value); } +static bool +set_insert_unique(const char *value) +{ + unsigned long h; + + h = CK_HS_HASH(&hs, hs_hash, value); + return ck_hs_put_unique(&hs, h, value); +} + static size_t set_count(void) { @@ -188,7 +196,7 @@ main(int argc, char *argv[]) char buffer[512]; size_t i, j, r; unsigned int d = 0; - uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng, ss, sts; + uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng, ss, sts, su; struct ck_hs_stat st; char **t; @@ -237,7 +245,8 @@ main(int argc, char *argv[]) set_count(), d, st.probe_maximum); fprintf(stderr, "# reverse_insertion serial_insertion random_insertion serial_swap " - "serial_replace reverse_get serial_get random_get serial_remove negative_get tombstone\n\n"); + "serial_replace reverse_get serial_get random_get serial_remove negative_get tombstone " + "set_unique\n\n"); a = 0; for (j = 0; j < r; j++) { @@ -391,6 +400,32 @@ main(int argc, char *argv[]) } sts = a / (r * keys_length); + set_reset(); + + /* Prune duplicates. */ + for (i = 0; i < keys_length; i++) { + if (set_insert(keys[i]) == true) + continue; + + keys[i] = keys[--keys_length]; + } + + for (i = 0; i < keys_length; i++) + set_remove(keys[i]); + + a = 0; + for (j = 0; j < r; j++) { + s = rdtsc(); + for (i = 0; i < keys_length; i++) + set_insert_unique(keys[i]); + e = rdtsc(); + a += e - s; + + for (i = 0; i < keys_length; i++) + set_remove(keys[i]); + } + su = a / (r * keys_length); + printf("%zu " "%" PRIu64 " " "%" PRIu64 " " @@ -402,8 +437,9 @@ main(int argc, char *argv[]) "%" PRIu64 " " "%" PRIu64 " " "%" PRIu64 " " + "%" PRIu64 " " "%" PRIu64 "\n", - keys_length, ri, si, ai, ss, sr, rg, sg, ag, sd, ng, sts); + keys_length, ri, si, ai, ss, sr, rg, sg, ag, sd, ng, sts, su); return 0; } diff --git a/regressions/ck_hs/validate/serial.c b/regressions/ck_hs/validate/serial.c index 27d6bdc..32ce619 100644 --- a/regressions/ck_hs/validate/serial.c +++ b/regressions/ck_hs/validate/serial.c @@ -57,15 +57,16 @@ static struct ck_malloc my_allocator = { .free = hs_free }; -const char *test[] = {"Samy", "Al", "Bahra", "dances", "in", "the", "wind.", "Once", +const char *test[] = { "Samy", "Al", "Bahra", "dances", "in", "the", "wind.", "Once", "upon", "a", "time", "his", "gypsy", "ate", "one", "itsy", "bitsy", "spider.", "What", "goes", "up", "must", "come", "down.", "What", "is", "down", "stays", "down.", "A", "B", "C", "D", "E", "F", "G", "H", - "I", "J", "K", "L", "M", "N", "O"}; + "I", "J", "K", "L", "M", "N", "O", "P", "Q" }; const char *negative = "negative"; +/* Purposefully crappy hash function. */ static unsigned long hs_hash(const void *object, unsigned long seed) { @@ -99,6 +100,19 @@ run_test(unsigned int is) } for (j = 0; j < size; j++) { + for (i = 0; i < sizeof(test) / sizeof(*test); i++) { + h = test[i][0]; + if (ck_hs_get(&hs[j], h, test[i]) != NULL) { + continue; + } + + if (ck_hs_put_unique(&hs[j], h, test[i]) == false) + ck_error("ERROR [%zu]: Failed to insert unique (%s)\n", j, test[i]); + + if (ck_hs_remove(&hs[j], h, test[i]) == false) + ck_error("ERROR [%zu]: Failed to remove unique (%s)\n", j, test[i]); + } + for (i = 0; i < sizeof(test) / sizeof(*test); i++) { h = test[i][0]; ck_hs_put(&hs[j], h, test[i]);