Skip to content

Commit

Permalink
Changed key generation in test cases.
Browse files Browse the repository at this point in the history
Changed purely random key generation to sequential with random steps.
This will not change anything for the distribution of hashed values
because this is ensured by the hash function.
  • Loading branch information
goossaert committed Apr 27, 2014
1 parent 32ca39a commit 1bdbaaf
Showing 1 changed file with 30 additions and 92 deletions.
122 changes: 30 additions & 92 deletions testcase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,26 @@ std::string concatenate(std::string const& str, int i)

void TestCase::InsertEntries(uint32_t num_items, std::set<std::string>& keys) {
std::string key;
int key_size = 16;
char buffer[key_size + 1];
buffer[key_size] = '\0';
char alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
std::set<std::string>::iterator it_find;

std::string value_dummy;
static uint64_t key_id_current = 0;
// NOTE: If ever using this method, remember to reset key_id_current between
// instances.

for (uint32_t j = 0; j < num_items; j++) {
bool is_valid = false;
while (!is_valid) {
for (int k = 0; k < key_size; k++) {
buffer[k] = alpha[rand() % 62];
}
key = buffer;
it_find = keys.find(key);
if (it_find == keys.end()) {
is_valid = true;
} else {
//fprintf(stdout, "%s\n", key.c_str());
//fprintf(stdout, "%d\n", keys.size());
}
key_id_current += 1 + rand() % 32;
key = concatenate( "key", key_id_current );
it_find = keys.find(key);
if (it_find != keys.end()) {
fprintf(stderr, "Error: key already in the hash table, this should not happen\n");
}
keys.insert(key);

keys.insert(key);
int ret_get = hm_->Get(key, &value_dummy);
if (ret_get != 1) {
fprintf(stderr, "Get() error\n");
}
int ret_put = hm_->Put(key, key);
//fprintf(stderr, "Put() [%s]\n", key.c_str());
if (ret_put != 0) {
fprintf(stderr, "Put() error\n");
}
Expand Down Expand Up @@ -89,11 +78,7 @@ void TestCase::RemoveEntries(uint32_t num_items, std::set<std::string>& keys) {
void BatchTestCase::run() {
std::set<std::string> keys;
std::string key;
int key_size = 16;
char buffer[key_size + 1];
buffer[key_size] = '\0';
char filename[1024];
char alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
uint32_t num_items;
uint32_t num_items_big = (uint32_t)((double)num_buckets_ * load_factor_max_);
uint32_t num_items_small = (uint32_t)((double)num_buckets_ * load_factor_remove_);
Expand Down Expand Up @@ -133,27 +118,20 @@ void BatchTestCase::run() {
exit(1);
}


std::string value_dummy;
uint64_t key_id_current = 0;

for (int cycle = 0; cycle < 50; cycle++) {
fprintf(stderr, "instance %d cycle %d\n", i, cycle);
bool has_error_on_put = false;
for (uint32_t j = 0; j < num_items; j++) {
bool is_valid = false;
while (!is_valid) {
for (int k = 0; k < key_size; k++) {
buffer[k] = alpha[rand() % 62];
}
key = buffer;
it_find = keys.find(key);
if (it_find == keys.end()) {
is_valid = true;
} else {
//fprintf(stdout, "%s\n", key.c_str());
//fprintf(stdout, "%d\n", keys.size());
}
key_id_current += 1 + rand() % 32;
key = concatenate( "key", key_id_current );
it_find = keys.find(key);
if (it_find != keys.end()) {
fprintf(stderr, "Error: key already in the hash table, this should not happen\n");
}

keys.insert(key);
int ret_get = hm_->Get(key, &value_dummy);
if (ret_get != 1) {
Expand Down Expand Up @@ -306,11 +284,7 @@ void BatchTestCase::run() {
void RippleTestCase::run() {
std::set<std::string> keys;
std::string key;
int key_size = 16;
char buffer[key_size + 1];
buffer[key_size] = '\0';
char filename[1024];
char alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
uint32_t num_items;
uint32_t num_items_big = (uint32_t)((double)num_buckets_ * load_factor_max_);
uint32_t num_items_small = (uint32_t)((double)num_buckets_ * load_factor_remove_);
Expand All @@ -329,6 +303,7 @@ void RippleTestCase::run() {
char pt_json[1024];
sprintf(pt_json, "{\"load_factor_max\": %.2f, \"load_factor_remove\": %.2f}", load_factor_max_, load_factor_remove_);


std::set<std::string>::iterator it_find;
for (int i = 0; i < 1; i++) {
num_items = num_items_big;
Expand All @@ -348,37 +323,28 @@ void RippleTestCase::run() {
}

std::string value_dummy;
uint64_t key_id_current = 0;

for (int cycle = 0; cycle < 50; cycle++) {
fprintf(stderr, "instance %d cycle %d\n", i, cycle);
bool has_error_on_put = false;
for (uint32_t j = 0; j < num_items; j++) {
bool is_valid = false;
while (!is_valid) {
for (int k = 0; k < key_size; k++) {
buffer[k] = alpha[rand() % 62];
}
key = buffer;
it_find = keys.find(key);
if (it_find == keys.end()) {
is_valid = true;
} else {
//fprintf(stdout, "%s\n", key.c_str());
//fprintf(stdout, "%d\n", keys.size());
}
key_id_current += 1 + rand() % 32;
key = concatenate( "key", key_id_current );
it_find = keys.find(key);
if (it_find != keys.end()) {
fprintf(stderr, "Error: key already in the hash table, this should not happen\n");
}

keys.insert(key);
int ret_get = hm_->Get(key, &value_dummy);
if (ret_get != 1) {
fprintf(stderr, "Get() error\n");
}
int ret_put = hm_->Put(key, key);
//fprintf(stderr, "Put() [%s]\n", key.c_str());
if (ret_put != 0) {
fprintf(stderr, "Put() error\n");
// break on error
has_error_on_put = true;
//break;
}

if (cycle > 0) {
Expand Down Expand Up @@ -526,11 +492,7 @@ void RippleTestCase::run() {
void LoadingTestCase::run() {
std::set<std::string> keys;
std::string key;
int key_size = 16;
char buffer[key_size + 1];
buffer[key_size] = '\0';
char filename[1024];
//char alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
uint32_t num_items;
uint32_t num_items_big = num_buckets_;

Expand All @@ -547,8 +509,6 @@ void LoadingTestCase::run() {
char pt_json[1024];
sprintf(pt_json, "{}");

uint64_t key_id_current = 0;

num_items = num_items_big / 50;
std::set<std::string>::iterator it_find;
for (int i = 0; i < 1; i++) {
Expand All @@ -568,39 +528,17 @@ void LoadingTestCase::run() {
}

std::string value_dummy;
uint64_t key_id_current = 0;

for (int cycle = 0; cycle < 50; cycle++) {
fprintf(stderr, "instance %d cycle %d\n", i, cycle);
bool has_error_on_put = false;
for (uint32_t j = 0; j < num_items; j++) {
bool is_valid = false;

/*
while (!is_valid) {
for (int k = 0; k < key_size; k++) {
buffer[k] = alpha[rand() % 62];
}
key = buffer;
it_find = keys.find(key);
if (it_find == keys.end()) {
is_valid = true;
} else {
//fprintf(stdout, "%s\n", key.c_str());
//fprintf(stdout, "%d\n", keys.size());
}
}
*/

while (!is_valid) {
key_id_current += 1 + rand() % 62;
key = concatenate( "key", key_id_current );
//fprintf(stderr, "generated key %s\n", key.c_str());
it_find = keys.find(key);
if (it_find == keys.end()) {
is_valid = true;
} else {
fprintf(stderr, "Error: key already in the hash table, this should not happen\n");
}
key_id_current += 1 + rand() % 32;
key = concatenate( "key", key_id_current );
it_find = keys.find(key);
if (it_find != keys.end()) {
fprintf(stderr, "Error: key already in the hash table, this should not happen\n");
}

keys.insert(key);
Expand Down

0 comments on commit 1bdbaaf

Please sign in to comment.