Commit 030a7ab8 authored by Zardosht Kasheff's avatar Zardosht Kasheff

addresses #724

add test for set_at

git-svn-id: file:///svn/tokudb@3591 c7de825b-a66e-492c-adef-691d508d4ae1
parent e830c316
...@@ -233,8 +233,7 @@ void test_create_from_sorted_array_size(enum create_type create_choice, enum clo ...@@ -233,8 +233,7 @@ void test_create_from_sorted_array_size(enum create_type create_choice, enum clo
test_close(close); test_close(close);
} }
void test_create_fetch_verify(enum create_type create_choice, enum close_when_done close) { void test_fetch_verify (void) {
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
u_int32_t i; u_int32_t i;
int r; int r;
OMTVALUE v = (OMTVALUE)&i; OMTVALUE v = (OMTVALUE)&i;
...@@ -270,6 +269,11 @@ void test_create_fetch_verify(enum create_type create_choice, enum close_when_do ...@@ -270,6 +269,11 @@ void test_create_fetch_verify(enum create_type create_choice, enum close_when_do
CKERR2(r, ERANGE); CKERR2(r, ERANGE);
assert(v == NULL); assert(v == NULL);
} }
}
void test_create_fetch_verify(enum create_type create_choice, enum close_when_done close) {
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
test_fetch_verify();
test_close(close); test_close(close);
} }
...@@ -283,20 +287,86 @@ int iterate_helper(OMTVALUE v, u_int32_t idx, void* extra) { ...@@ -283,20 +287,86 @@ int iterate_helper(OMTVALUE v, u_int32_t idx, void* extra) {
return 0; return 0;
} }
void test_create_iterate_verify(enum create_type create_choice, enum close_when_done close) { void test_iterate_verify(void) {
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
int r; int r;
iterate_helper_error_return = 0; iterate_helper_error_return = 0;
r = toku_omt_iterate(omt, iterate_helper, (void*)omt); r = toku_omt_iterate(omt, iterate_helper, (void*)omt);
CKERR(r); CKERR(r);
iterate_helper_error_return = 0xFEEDABBA; iterate_helper_error_return = 0xFEEDABBA;
r = toku_omt_iterate(omt, iterate_helper, NULL); r = toku_omt_iterate(omt, iterate_helper, NULL);
CKERR2(r, iterate_helper_error_return); CKERR2(r, iterate_helper_error_return);
}
void test_create_iterate_verify(enum create_type create_choice, enum close_when_done close) {
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
test_iterate_verify();
test_close(close);
}
void test_create_set_at(enum create_type create_choice, enum close_when_done close) {
u_int32_t i = 0;
struct value* old_nums = NULL;
MALLOC_N(length, old_nums);
assert(nums);
u_int32_t* perm = NULL;
MALLOC_N(length, perm);
assert(perm);
OMTVALUE* old_values = NULL;
MALLOC_N(length, old_values);
assert(old_values);
//
// permute an array that holds elements 0...length-1
//
for (i = 0; i < length; i++) {
perm[i] = i;
}
for (i = 0; i < length - 1; i++) {
u_int32_t choices = length - i;
u_int32_t choice = random() % choices;
if (choice != i) {
u_int32_t temp = perm[i];
perm[i] = perm[choice];
perm[choice] = temp;
}
}
//
// These are going to be the new values
//
for (i = 0; i < length; i++) {
old_nums[i] = nums[i];
old_values[i] = &old_nums[i];
values[i] = &old_nums[i];
}
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
//
//
//
int r;
r = toku_omt_set_at (omt, values[0], length);
CKERR2(r,ERANGE);
for (i = 0; i < length; i++) {
u_int32_t choice = perm[i];
values[choice] = &nums[choice];
nums[choice].number = (u_int32_t)random();
r = toku_omt_set_at (omt, values[choice], choice);
CKERR(r);
test_iterate_verify();
test_fetch_verify();
}
r = toku_omt_set_at (omt, values[0], length);
CKERR2(r,ERANGE);
test_close(close); test_close(close);
} }
void test_create_array(enum create_type create_choice, enum rand_type rand_choice) { void test_create_array(enum create_type create_choice, enum rand_type rand_choice) {
if (rand_choice == TEST_RANDOM) { if (rand_choice == TEST_RANDOM) {
init_distinct_random_values(random_seed, 100); init_distinct_random_values(random_seed, 100);
...@@ -316,6 +386,8 @@ void test_create_array(enum create_type create_choice, enum rand_type rand_choic ...@@ -316,6 +386,8 @@ void test_create_array(enum create_type create_choice, enum rand_type rand_choic
/* ********************************************************************** */ /* ********************************************************************** */
test_create_iterate_verify( create_choice, CLOSE_WHEN_DONE); test_create_iterate_verify( create_choice, CLOSE_WHEN_DONE);
/* ********************************************************************** */ /* ********************************************************************** */
test_create_set_at( create_choice, CLOSE_WHEN_DONE);
/* ********************************************************************** */
} }
typedef struct { typedef struct {
...@@ -526,9 +598,6 @@ int toku_omt_merge(OMT leftomt, OMT rightomt, OMT *newomt); ...@@ -526,9 +598,6 @@ int toku_omt_merge(OMT leftomt, OMT rightomt, OMT *newomt);
// On error, nothing is modified. // On error, nothing is modified.
// Performance: time=O(n) is acceptable, but one can imagine implementations that are O(\log n) worst-case. // Performance: time=O(n) is acceptable, but one can imagine implementations that are O(\log n) worst-case.
int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index);
// Effect: Replaces the item at index with value.
int toku_omt_insert(OMT omt, OMTVALUE value, int(*h)(OMTVALUE, void*v), void *v, u_int32_t *index); int toku_omt_insert(OMT omt, OMTVALUE value, int(*h)(OMTVALUE, void*v), void *v, u_int32_t *index);
// Effect: Insert value into the OMT. // Effect: Insert value into the OMT.
// If there is some i such that $h(V_i, v)=0$ then returns DB_KEYEXIST. // If there is some i such that $h(V_i, v)=0$ then returns DB_KEYEXIST.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment