Commit eb9b6d85 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Add support to the gpma to delete an item at a particular index. Addresses #690.

git-svn-id: file:///svn/tokudb@3441 c7de825b-a66e-492c-adef-691d508d4ae1
parent 671074d4
......@@ -512,6 +512,14 @@ int toku_smooth_deleted_region (GPMA pma, u_int32_t minidx, u_int32_t maxidx, gp
}
}
int toku_gpma_delete_at_index (GPMA pma, u_int32_t index,
gpma_renumber_callback_t renumberf,
void *extra_for_renumberf) {
toku_gpma_clear_at_index(pma, index);
return toku_smooth_deleted_region(pma, index, index, renumberf, extra_for_renumberf);
}
int toku_gpma_delete_bessel (GPMA pma,
gpma_besselfun_t besself, void*extra_for_besself,
gpma_delete_callback_t deletef, void*extra_for_deletef, // for each deleted item, let the caller know
......
......@@ -52,6 +52,12 @@ int toku_gpma_insert_bessel (GPMA pma,
u_int32_t *indexp // Where did the item get stored?
);
// Delete a particular index, and rebalance the tree.
int toku_gpma_delete_at_index (GPMA pma, u_int32_t index,
gpma_renumber_callback_t renumberf,
void *extra_for_renumberf);
// Delete anything for which the besselfun is zero. The besselfun must be monotonically increasing compared to the comparison function.
// That is, if two othings compare to be < then their besselfun's must yield <=, and if the compare to be = their besselfuns must be =, and if they are > then their besselfuns must be >=
// Note the delete_callback would be responsible for calling free on the object.
......@@ -97,6 +103,7 @@ int toku_gpma_get_from_index (GPMA, u_int32_t idx, u_int32_t *len, void **data);
// Whatever is in the slot gets overwritten. Watch out that you free the thing before overwriting it.
void toku_gpma_set_at_index (GPMA, u_int32_t idx, u_int32_t len, void*data);
// Clears the item at a particular index without rebalancing the PMA.
void toku_gpma_clear_at_index (GPMA, u_int32_t idx);
int toku_gpma_move_inside_pma_by_renumbering (GPMA,
......
......@@ -340,6 +340,53 @@ void test_delete (void) {
test_delete_n(300);
}
void test_delete_at (void) {
GPMA pma;
int r = toku_gpma_create(&pma, 0);
assert(r==0);
int i, j;
int N=20;
char *strings[N];
for (i=0; i<N; i++) {
char str[6];
snprintf(str, 6, "%05d", i);
strings[i]=strdup(str);
r = toku_gpma_insert(pma, 6, strings[i], compare_strings, 0, rcall_ok, strings[i], 0);
assert(r==0);
//printf("insert, N=%d\n", toku_gpma_index_limit(pma));
}
u_int32_t max_limit = toku_gpma_index_limit(pma);
u_int32_t min_limit = max_limit;
u_int32_t prev_limit = max_limit;
u_int32_t resultlen, idx;
void *resultdata;
for (j=0; j<N; j++) {
r = toku_gpma_lookup_item(pma, 6, strings[j], compare_strings, 0, &resultlen, &resultdata, &idx);
assert(r==0);
assert(resultlen==6);
assert(0==strcmp(resultdata, strings[j]));
r = toku_gpma_delete_at_index(pma, idx, 0, 0);
assert(r==0);
u_int32_t this_limit = toku_gpma_index_limit(pma);
if (this_limit<min_limit) min_limit=this_limit;
assert(this_limit<=prev_limit);
prev_limit=this_limit;
//printf("delete, N=%d\n", this_limit);
for (i=0; i<=j; i++) {
r = toku_gpma_lookup_item(pma, 6, strings[i], compare_strings, 0, &resultlen, &resultdata, &idx);
assert(r==DB_NOTFOUND);
}
for (i=j+1; i<N; i++) {
r = toku_gpma_lookup_item(pma, 6, strings[i], compare_strings, 0, &resultlen, &resultdata, &idx);
assert(r==0);
assert(resultlen==6);
assert(0==strcmp(resultdata, strings[i]));
}
}
assert(min_limit<max_limit);
}
static int compare_this_string (u_int32_t dlen, void *dval, void *extra) {
assert(dlen==1+strlen(dval));
return strcmp(dval, extra);
......@@ -393,6 +440,7 @@ int main (int argc, const char *argv[]) {
test_insert_A();
test_split();
test_delete();
test_delete_at();
test_bes();
toku_malloc_cleanup();
return 0;
......
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