de-duplicated some cut and paste code
git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@526 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
parent
2fcfafb589
commit
38f2cb3897
9 changed files with 172 additions and 505 deletions
|
@ -12,76 +12,13 @@
|
|||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "check_util.h"
|
||||
|
||||
#undef begin
|
||||
#undef end
|
||||
|
||||
template class DataPage<datatuple>;
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> &arr)
|
||||
{
|
||||
|
||||
for(int i=arr.size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp(arr[i], arr[i-1]) || mycmp(arr[i-1], arr[i])))
|
||||
arr.erase(arr.begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> &arr, int avg_len=50, bool duplicates_allowed=false)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
//make sure there is no duplicate key
|
||||
if(!duplicates_allowed)
|
||||
{
|
||||
bool dup = false;
|
||||
for(int i=0; i<j; i++)
|
||||
if(! (mycmp(arr[i], str) || mycmp(str, arr[i])))
|
||||
{
|
||||
dup=true;
|
||||
break;
|
||||
}
|
||||
if(dup)
|
||||
{
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("keylen-%d\t%d\t%s\n", str_len, str.length(),rc);
|
||||
free(rc);
|
||||
|
||||
arr.push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* REGION ALLOCATION
|
||||
**/
|
||||
|
|
|
@ -16,76 +16,11 @@
|
|||
#undef begin
|
||||
#undef end
|
||||
|
||||
|
||||
#include "check_util.h"
|
||||
|
||||
//template class DataPage<datatuple>;
|
||||
template class treeIterator<datatuple>;
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> &arr)
|
||||
{
|
||||
|
||||
for(int i=arr.size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp(arr[i], arr[i-1]) || mycmp(arr[i-1], arr[i])))
|
||||
arr.erase(arr.begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> &arr, int avg_len=50, bool duplicates_allowed=false)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
//make sure there is no duplicate key
|
||||
if(!duplicates_allowed)
|
||||
{
|
||||
bool dup = false;
|
||||
for(int i=0; i<j; i++)
|
||||
if(! (mycmp(arr[i], str) || mycmp(str, arr[i])))
|
||||
{
|
||||
dup=true;
|
||||
break;
|
||||
}
|
||||
if(dup)
|
||||
{
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("keylen-%d\t%d\t%s\n", str_len, str.length(),rc);
|
||||
free(rc);
|
||||
|
||||
arr.push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
{
|
||||
srand(1000);
|
||||
|
|
|
@ -22,55 +22,7 @@
|
|||
#undef begin
|
||||
#undef end
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> &arr)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = rand()%100 + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
//make sure there is no duplicate key
|
||||
bool dup = false;
|
||||
for(int i=0; i<j; i++)
|
||||
if(! (mycmp(arr[i], str) || mycmp(str, arr[i])))
|
||||
{
|
||||
dup=true;
|
||||
break;
|
||||
}
|
||||
if(dup)
|
||||
{
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//printf("keylen-%d\t%d\t%s\n", str_len, str.length(),rc);
|
||||
free(rc);
|
||||
|
||||
arr.push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "check_util.h"
|
||||
|
||||
void insertProbeIter_str(int NUM_ENTRIES)
|
||||
{
|
||||
|
@ -100,7 +52,7 @@ void insertProbeIter_str(int NUM_ENTRIES)
|
|||
long oldpagenum = -1;
|
||||
|
||||
std::vector<std::string> arr;
|
||||
preprandstr(NUM_ENTRIES, arr);
|
||||
preprandstr(NUM_ENTRIES, arr, 50, false);
|
||||
std::sort(arr.begin(), arr.end(), &mycmp);
|
||||
|
||||
//for(int i = 0; i < NUM_ENTRIES; i++)
|
||||
|
|
|
@ -16,54 +16,7 @@
|
|||
#undef begin
|
||||
#undef end
|
||||
|
||||
|
||||
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> *arr)
|
||||
{
|
||||
|
||||
for(int i=arr->size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp((*arr)[i], (*arr)[i-1]) || mycmp((*arr)[i-1], (*arr)[i])))
|
||||
arr->erase(arr->begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> *arr, int avg_len=50)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
free(rc);
|
||||
|
||||
arr->push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#include "check_util.h"
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
{
|
||||
|
@ -77,8 +30,8 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
std::vector<std::string> * data_arr = new std::vector<std::string>;
|
||||
std::vector<std::string> * key_arr = new std::vector<std::string>;
|
||||
|
||||
preprandstr(NUM_ENTRIES, data_arr, 10*8192);
|
||||
preprandstr(NUM_ENTRIES+200, key_arr, 100);
|
||||
preprandstr(NUM_ENTRIES, data_arr, 10*8192, true);
|
||||
preprandstr(NUM_ENTRIES+200, key_arr, 100, true);
|
||||
|
||||
std::sort(key_arr->begin(), key_arr->end(), &mycmp);
|
||||
|
||||
|
|
|
@ -16,73 +16,7 @@
|
|||
#undef begin
|
||||
#undef end
|
||||
|
||||
|
||||
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> *arr)
|
||||
{
|
||||
|
||||
for(int i=arr->size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp((*arr)[i], (*arr)[i-1]) || mycmp((*arr)[i-1], (*arr)[i])))
|
||||
arr->erase(arr->begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void getnextdata(std::string &data, int avg_len)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
data = std::string(str_len, rand()%10+48);
|
||||
/*
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
data = std::string(rc);
|
||||
|
||||
free(rc);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> *arr, int avg_len=50)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
free(rc);
|
||||
|
||||
arr->push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#include "check_util.h"
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
{
|
||||
|
@ -97,7 +31,7 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
std::vector<std::string> * key_arr = new std::vector<std::string>;
|
||||
|
||||
// preprandstr(NUM_ENTRIES, data_arr, 10*8192);
|
||||
preprandstr(NUM_ENTRIES+200, key_arr, 100);
|
||||
preprandstr(NUM_ENTRIES+200, key_arr, 100, true);
|
||||
|
||||
std::sort(key_arr->begin(), key_arr->end(), &mycmp);
|
||||
|
||||
|
|
|
@ -16,73 +16,7 @@
|
|||
#undef begin
|
||||
#undef end
|
||||
|
||||
|
||||
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> *arr)
|
||||
{
|
||||
|
||||
for(int i=arr->size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp((*arr)[i], (*arr)[i-1]) || mycmp((*arr)[i-1], (*arr)[i])))
|
||||
arr->erase(arr->begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void getnextdata(std::string &data, int avg_len)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
data = std::string(str_len, rand()%10+48);
|
||||
/*
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
data = std::string(rc);
|
||||
|
||||
free(rc);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> *arr, int avg_len=50)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
free(rc);
|
||||
|
||||
arr->push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#include "check_util.h"
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
{
|
||||
|
@ -104,9 +38,9 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
{
|
||||
key_v_t * key_arr = new key_v_t;
|
||||
if(NUM_ENTRIES < max_partition_size*(i+1))
|
||||
preprandstr(NUM_ENTRIES-max_partition_size*i, key_arr, KEY_LEN);
|
||||
preprandstr(NUM_ENTRIES-max_partition_size*i, key_arr, KEY_LEN, true);
|
||||
else
|
||||
preprandstr(max_partition_size, key_arr, KEY_LEN);
|
||||
preprandstr(max_partition_size, key_arr, KEY_LEN, true);
|
||||
|
||||
std::sort(key_arr->begin(), key_arr->end(), &mycmp);
|
||||
key_v_list->push_back(key_arr);
|
||||
|
|
|
@ -16,73 +16,7 @@
|
|||
#undef begin
|
||||
#undef end
|
||||
|
||||
|
||||
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> &arr)
|
||||
{
|
||||
|
||||
for(int i=arr.size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp(arr[i], arr[i-1]) || mycmp(arr[i-1], arr[i])))
|
||||
arr.erase(arr.begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> &arr, int avg_len=50, bool duplicates_allowed=false)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
//make sure there is no duplicate key
|
||||
if(!duplicates_allowed)
|
||||
{
|
||||
bool dup = false;
|
||||
for(int i=0; i<j; i++)
|
||||
if(! (mycmp(arr[i], str) || mycmp(str, arr[i])))
|
||||
{
|
||||
dup=true;
|
||||
break;
|
||||
}
|
||||
if(dup)
|
||||
{
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("keylen-%d\t%d\t%s\n", str_len, str.length(),rc);
|
||||
free(rc);
|
||||
|
||||
arr.push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#include "check_util.h"
|
||||
|
||||
void insertProbeIter(int NUM_ENTRIES)
|
||||
{
|
||||
|
|
|
@ -14,78 +14,11 @@
|
|||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "check_util.h"
|
||||
|
||||
#undef begin
|
||||
#undef end
|
||||
|
||||
|
||||
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> *arr)
|
||||
{
|
||||
|
||||
for(int i=arr->size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp((*arr)[i], (*arr)[i-1]) || mycmp((*arr)[i-1], (*arr)[i])))
|
||||
arr->erase(arr->begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void getnextdata(std::string &data, int avg_len)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
data = std::string(str_len, rand()%10+48);
|
||||
/*
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
data = std::string(rc);
|
||||
|
||||
free(rc);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> *arr, int avg_len=50)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
free(rc);
|
||||
|
||||
arr->push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void readfromsocket(int sockd, byte *buf, int count)
|
||||
{
|
||||
|
||||
|
@ -210,9 +143,9 @@ void insertProbeIter(int NUM_ENTRIES)
|
|||
{
|
||||
key_v_t * key_arr = new key_v_t;
|
||||
if(NUM_ENTRIES < max_partition_size*(i+1))
|
||||
preprandstr(NUM_ENTRIES-max_partition_size*i, key_arr, KEY_LEN);
|
||||
preprandstr(NUM_ENTRIES-max_partition_size*i, key_arr, KEY_LEN, true);
|
||||
else
|
||||
preprandstr(max_partition_size, key_arr, KEY_LEN);
|
||||
preprandstr(max_partition_size, key_arr, KEY_LEN, true);
|
||||
|
||||
std::sort(key_arr->begin(), key_arr->end(), &mycmp);
|
||||
key_v_list->push_back(key_arr);
|
||||
|
|
155
test/check_util.h
Normal file
155
test/check_util.h
Normal file
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* check_util.h
|
||||
*
|
||||
* Created on: Jan 25, 2010
|
||||
* Author: sears
|
||||
*/
|
||||
|
||||
#ifndef CHECK_UTIL_H_
|
||||
#define CHECK_UTIL_H_
|
||||
|
||||
bool mycmp(const std::string & k1,const std::string & k2)
|
||||
{
|
||||
//for char* ending with \0
|
||||
return strcmp(k1.c_str(),k2.c_str()) < 0;
|
||||
|
||||
//for int32_t
|
||||
//printf("%d\t%d\n",(*((int32_t*)k1)) ,(*((int32_t*)k2)));
|
||||
//return (*((int32_t*)k1)) <= (*((int32_t*)k2));
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
void removeduplicates(std::vector<std::string> *arr)
|
||||
{
|
||||
|
||||
for(int i=arr->size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp((*arr)[i], (*arr)[i-1]) || mycmp((*arr)[i-1], (*arr)[i])))
|
||||
arr->erase(arr->begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//must be given a sorted array
|
||||
// XXX probably don't need two copies of this function.
|
||||
void removeduplicates(std::vector<std::string> &arr)
|
||||
{
|
||||
|
||||
for(int i=arr.size()-1; i>0; i--)
|
||||
{
|
||||
if(! (mycmp(arr[i], arr[i-1]) || mycmp(arr[i-1], arr[i])))
|
||||
arr.erase(arr.begin()+i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void getnextdata(std::string &data, int avg_len)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
data = std::string(str_len, rand()%10+48);
|
||||
/*
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
data = std::string(rc);
|
||||
|
||||
free(rc);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> *arr, int avg_len=50, bool duplicates_allowed=false)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
//make sure there is no duplicate key
|
||||
if(!duplicates_allowed)
|
||||
{
|
||||
bool dup = false;
|
||||
for(int i=0; i<j; i++)
|
||||
if(! (mycmp((*arr)[i], str) || mycmp(str, (*arr)[i])))
|
||||
{
|
||||
dup=true;
|
||||
break;
|
||||
}
|
||||
if(dup)
|
||||
{
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("keylen-%d\t%d\t%s\n", str_len, str.length(),rc);
|
||||
free(rc);
|
||||
|
||||
arr->push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void preprandstr(int count, std::vector<std::string> &arr, int avg_len=50, bool duplicates_allowed=false)
|
||||
{
|
||||
|
||||
for ( int j=0; j<count; j++)
|
||||
{
|
||||
int str_len = (rand()%(avg_len*2)) + 3;
|
||||
|
||||
char *rc = (char*)malloc(str_len);
|
||||
|
||||
for(int i=0; i<str_len-1; i++)
|
||||
rc[i] = rand()%10+48;
|
||||
|
||||
rc[str_len-1]='\0';
|
||||
std::string str(rc);
|
||||
|
||||
//make sure there is no duplicate key
|
||||
if(!duplicates_allowed)
|
||||
{
|
||||
bool dup = false;
|
||||
for(int i=0; i<j; i++)
|
||||
if(! (mycmp(arr[i], str) || mycmp(str, arr[i])))
|
||||
{
|
||||
dup=true;
|
||||
break;
|
||||
}
|
||||
if(dup)
|
||||
{
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("keylen-%d\t%d\t%s\n", str_len, str.length(),rc);
|
||||
free(rc);
|
||||
|
||||
arr.push_back(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* CHECK_UTIL_H_ */
|
Loading…
Reference in a new issue