regressions: Testing of ck_hs_fas functionality.

ck_pring
Samy Al Bahra 12 years ago
parent 7da381bb1a
commit 03efd38742

@ -171,6 +171,16 @@ set_replace(const char *value)
return ck_hs_set(&hs, h, value, &previous); return ck_hs_set(&hs, h, value, &previous);
} }
static bool
set_swap(const char *value)
{
unsigned long h;
void *previous;
h = CK_HS_HASH(&hs, hs_hash, value);
return ck_hs_fas(&hs, h, value, &previous);
}
static void * static void *
set_get(const char *value) set_get(const char *value)
{ {
@ -205,7 +215,6 @@ set_reset(void)
return ck_hs_reset(&hs); return ck_hs_reset(&hs);
} }
static void * static void *
reader(void *unused) reader(void *unused)
{ {
@ -469,8 +478,13 @@ main(int argc, char *argv[])
for (;;) { for (;;) {
repeated++; repeated++;
s = rdtsc(); s = rdtsc();
for (i = 0; i < keys_length; i++) for (i = 0; i < keys_length; i++) {
set_replace(keys[i]); if (i & 1) {
set_replace(keys[i]);
} else {
set_swap(keys[i]);
}
}
e = rdtsc(); e = rdtsc();
a += e - s; a += e - s;
@ -542,8 +556,13 @@ main(int argc, char *argv[])
} }
if (p_r != 0.0) { if (p_r != 0.0) {
replace = common_drand48(); replace = common_drand48();
if (replace <= p_r) if (replace <= p_r) {
set_replace(keys[i]); if ((i & 1) || (delete <= p_d)) {
set_replace(keys[i]);
} else {
set_swap(keys[i]);
}
}
} }
} }
e = rdtsc(); e = rdtsc();

@ -107,6 +107,16 @@ set_remove(const char *value)
return true; return true;
} }
static bool
set_swap(const char *value)
{
unsigned long h;
void *previous;
h = CK_HS_HASH(&hs, hs_hash, value);
return ck_hs_fas(&hs, h, value, &previous);
}
static bool static bool
set_replace(const char *value) set_replace(const char *value)
{ {
@ -178,7 +188,7 @@ main(int argc, char *argv[])
char buffer[512]; char buffer[512];
size_t i, j, r; size_t i, j, r;
unsigned int d = 0; unsigned int d = 0;
uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng; uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng, ss;
struct ck_hs_stat st; struct ck_hs_stat st;
char **t; char **t;
@ -226,7 +236,7 @@ main(int argc, char *argv[])
fprintf(stderr, "# %zu entries stored, %u duplicates, %u probe.\n", fprintf(stderr, "# %zu entries stored, %u duplicates, %u probe.\n",
set_count(), d, st.probe_maximum); set_count(), d, st.probe_maximum);
fprintf(stderr, "# reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n"); fprintf(stderr, "# reverse_insertion serial_insertion random_insertion serial_swap serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n");
a = 0; a = 0;
for (j = 0; j < r; j++) { for (j = 0; j < r; j++) {
@ -272,6 +282,16 @@ main(int argc, char *argv[])
} }
ai = a / (r * keys_length); ai = a / (r * keys_length);
a = 0;
for (j = 0; j < r; j++) {
s = rdtsc();
for (i = 0; i < keys_length; i++)
set_swap(keys[i]);
e = rdtsc();
a += e - s;
}
ss = a / (r * keys_length);
a = 0; a = 0;
for (j = 0; j < r; j++) { for (j = 0; j < r; j++) {
s = rdtsc(); s = rdtsc();
@ -360,8 +380,9 @@ main(int argc, char *argv[])
"%" PRIu64 " " "%" PRIu64 " "
"%" PRIu64 " " "%" PRIu64 " "
"%" PRIu64 " " "%" PRIu64 " "
"%" PRIu64 " "
"%" PRIu64 "\n", "%" PRIu64 "\n",
keys_length, ri, si, ai, sr, rg, sg, ag, sd, ng); keys_length, ri, si, ai, ss, sr, rg, sg, ag, sd, ng);
return 0; return 0;
} }

@ -171,6 +171,18 @@ main(void)
test[i], (char *)r); test[i], (char *)r);
} }
/* Replacement should succeed. */
if (ck_hs_fas(&hs, h, test[i], &r) == false)
ck_error("ERROR: ck_hs_fas must succeed.\n");
if (strcmp(r, test[i]) != 0) {
ck_error("ERROR: Incorrect replaced value: %s != %s\n",
test[i], (char *)r);
}
if (ck_hs_fas(&hs, h, negative, &r) == true)
ck_error("ERROR: Replacement of negative should fail.\n");
if (ck_hs_set(&hs, h, test[i], &r) == false) { if (ck_hs_set(&hs, h, test[i], &r) == false) {
ck_error("ERROR: Failed to set [1]\n"); ck_error("ERROR: Failed to set [1]\n");
} }

Loading…
Cancel
Save