mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 03:51:50 +01:00
git-svn-id: file:///svn/tokudb@4333 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
9185a8549b
commit
77639084ce
3 changed files with 39 additions and 38 deletions
12
newbrt/omt.c
12
newbrt/omt.c
|
@ -331,7 +331,7 @@ static inline void insert_internal(OMT omt, node_idx *n_idxp, OMTVALUE value, u_
|
|||
int toku_omt_insert_at(OMT omt, OMTVALUE value, u_int32_t index) {
|
||||
int r;
|
||||
invalidate_cursors(omt);
|
||||
if (index>nweight(omt, omt->root)) return ERANGE;
|
||||
if (index>nweight(omt, omt->root)) return EINVAL;
|
||||
if ((r=maybe_resize_and_rebuild(omt, 1+nweight(omt, omt->root), MAYBE_REBUILD))) return r;
|
||||
node_idx* rebalance_idx = NULL;
|
||||
insert_internal(omt, &omt->root, value, index, &rebalance_idx);
|
||||
|
@ -352,7 +352,7 @@ static inline void set_at_internal(OMT omt, node_idx n_idx, OMTVALUE v, u_int32_
|
|||
}
|
||||
|
||||
int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index) {
|
||||
if (index>=nweight(omt, omt->root)) return ERANGE;
|
||||
if (index>=nweight(omt, omt->root)) return EINVAL;
|
||||
set_at_internal(omt, omt->root, value, index);
|
||||
return 0;
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ int toku_omt_delete_at(OMT omt, u_int32_t index) {
|
|||
OMTVALUE v;
|
||||
int r;
|
||||
invalidate_cursors(omt);
|
||||
if (index>=nweight(omt, omt->root)) return ERANGE;
|
||||
if (index>=nweight(omt, omt->root)) return EINVAL;
|
||||
if ((r=maybe_resize_and_rebuild(omt, -1+nweight(omt, omt->root), MAYBE_REBUILD))) return r;
|
||||
node_idx* rebalance_idx = NULL;
|
||||
delete_internal(omt, &omt->root, index, &v, &rebalance_idx);
|
||||
|
@ -420,7 +420,7 @@ static inline void fetch_internal(OMT V, node_idx idx, u_int32_t i, OMTVALUE *v)
|
|||
}
|
||||
|
||||
int toku_omt_fetch(OMT V, u_int32_t i, OMTVALUE *v, OMTCURSOR c) {
|
||||
if (i>=nweight(V, V->root)) return ERANGE;
|
||||
if (i>=nweight(V, V->root)) return EINVAL;
|
||||
fetch_internal(V, V->root, i, v);
|
||||
if (c) {
|
||||
associate(V,c);
|
||||
|
@ -562,7 +562,7 @@ int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int directi
|
|||
} else {
|
||||
r = find_internal_plus( V, V->root, h, extra, value, index);
|
||||
}
|
||||
if (c) {
|
||||
if (c && r==0) {
|
||||
associate(V,c);
|
||||
c->index=*index;
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ int toku_omt_split_at(OMT omt, OMT *newomtp, u_int32_t index) {
|
|||
OMT newomt = NULL;
|
||||
OMTVALUE *tmp_values = NULL;
|
||||
invalidate_cursors(omt);
|
||||
if (index>nweight(omt, omt->root)) { r = ERANGE; goto cleanup; }
|
||||
if (index>nweight(omt, omt->root)) { r = EINVAL; goto cleanup; }
|
||||
u_int32_t newsize = nweight(omt, omt->root)-index;
|
||||
if ((r = omt_create_internal(&newomt, newsize))) goto cleanup;
|
||||
MALLOC_N(nweight(omt, omt->root), tmp_values);
|
||||
|
|
13
newbrt/omt.h
13
newbrt/omt.h
|
@ -227,7 +227,7 @@ int toku_omt_insert_at(OMT omt, OMTVALUE value, u_int32_t index);
|
|||
//
|
||||
// Returns:
|
||||
// 0 success
|
||||
// ERANGE if index>toku_omt_size(omt)
|
||||
// EINVAL if index>toku_omt_size(omt)
|
||||
// ENOMEM
|
||||
// On error, omt is unchanged.
|
||||
// Performance: time=O(\log N) amortized time.
|
||||
|
@ -237,7 +237,7 @@ int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index);
|
|||
// Effect: Replaces the item at index with value.
|
||||
// Returns:
|
||||
// 0 success
|
||||
// ERANGE if index>=toku_omt_size(omt)
|
||||
// EINVAL if index>=toku_omt_size(omt)
|
||||
// On error, omt i sunchanged.
|
||||
// Performance: time=O(\log N)
|
||||
// Rationale: The BRT needs to be able to replace a value with another copy of the same value (allocated in a different location)
|
||||
|
@ -265,7 +265,7 @@ int toku_omt_delete_at(OMT omt, u_int32_t index);
|
|||
// Decreases indexes of all items at slot >= index by 1.
|
||||
// Returns
|
||||
// 0 success
|
||||
// ERANGE if index>=toku_omt_size(omt)
|
||||
// EINVAL if index>=toku_omt_size(omt)
|
||||
// On error, omt is unchanged.
|
||||
// Rationale: To delete an item, first find its index using toku_omt_find, then delete it.
|
||||
// Performance: time=O(\log N) amortized.
|
||||
|
@ -277,7 +277,7 @@ int toku_omt_fetch (OMT V, u_int32_t i, OMTVALUE *v, OMTCURSOR c);
|
|||
// Requires: v != NULL
|
||||
// Returns
|
||||
// 0 success
|
||||
// ERANGE if index>=toku_omt_size(omt)
|
||||
// EINVAL if index>=toku_omt_size(omt)
|
||||
// On nonzero return, *v is unchanged, and c (if nonnull) is either
|
||||
// invalidated or unchanged.
|
||||
// Performance: time=O(\log N)
|
||||
|
@ -304,7 +304,8 @@ int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int directi
|
|||
// Returns
|
||||
// 0 success
|
||||
// DB_NOTFOUND no such value is found.
|
||||
// On nonzero return, *value and *index are unchanged.
|
||||
// On nonzero return, *value and *index are unchanged, and c (if nonnull) is either invalidated
|
||||
// or unchanged.
|
||||
// Performance: time=O(\log N)
|
||||
// Rationale:
|
||||
// Here's how to use the find function to find various things
|
||||
|
@ -360,7 +361,7 @@ int toku_omt_split_at(OMT omt, OMT *newomt, u_int32_t index);
|
|||
// Requires: newomt != NULL
|
||||
// Returns
|
||||
// 0 success,
|
||||
// ERANGE if index > toku_omt_size(omt)
|
||||
// EINVAL if index > toku_omt_size(omt)
|
||||
// ENOMEM
|
||||
// On nonzero return, omt and *newomt are unmodified.
|
||||
// Performance: time=O(n)
|
||||
|
|
|
@ -172,9 +172,9 @@ void test_create_insert_at_almost_random(enum close_when_done close) {
|
|||
|
||||
test_create(KEEP_WHEN_DONE);
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
for (i = 0; i < length/2; i++) {
|
||||
assert(size==toku_omt_size(omt));
|
||||
r = toku_omt_insert_at(omt, values[i], i);
|
||||
|
@ -185,9 +185,9 @@ void test_create_insert_at_almost_random(enum close_when_done close) {
|
|||
assert(++size==toku_omt_size(omt));
|
||||
}
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
assert(size==toku_omt_size(omt));
|
||||
test_close(close);
|
||||
}
|
||||
|
@ -199,9 +199,9 @@ void test_create_insert_at_sequential(enum close_when_done close) {
|
|||
|
||||
test_create(KEEP_WHEN_DONE);
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
for (i = 0; i < length; i++) {
|
||||
assert(size==toku_omt_size(omt));
|
||||
r = toku_omt_insert_at(omt, values[i], i);
|
||||
|
@ -209,9 +209,9 @@ void test_create_insert_at_sequential(enum close_when_done close) {
|
|||
assert(++size==toku_omt_size(omt));
|
||||
}
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
assert(size==toku_omt_size(omt));
|
||||
test_close(close);
|
||||
}
|
||||
|
@ -324,11 +324,11 @@ void test_fetch_verify (OMT omtree, TESTVALUE* val, u_int32_t len ) {
|
|||
for (i = len; i < len*2; i++) {
|
||||
v = oldv;
|
||||
r = toku_omt_fetch(omtree, i, &v, NULL);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
assert(v == oldv);
|
||||
v = NULL;
|
||||
r = toku_omt_fetch(omtree, i, &v, c);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
assert(v == NULL);
|
||||
}
|
||||
|
||||
|
@ -421,9 +421,9 @@ void test_create_set_at(enum create_type create_choice, enum close_when_done clo
|
|||
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
|
||||
int r;
|
||||
r = toku_omt_set_at (omt, values[0], length);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
r = toku_omt_set_at (omt, values[0], length+1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
for (i = 0; i < length; i++) {
|
||||
u_int32_t choice = perm[i];
|
||||
values[choice] = &nums[choice];
|
||||
|
@ -434,9 +434,9 @@ void test_create_set_at(enum create_type create_choice, enum close_when_done clo
|
|||
test_fetch_verify(omt, values, length);
|
||||
}
|
||||
r = toku_omt_set_at (omt, values[0], length);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
r = toku_omt_set_at (omt, values[0], length+1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
|
||||
toku_free(perm);
|
||||
toku_free(old_values);
|
||||
|
@ -515,10 +515,10 @@ void test_create_delete_at(enum create_type create_choice, enum close_when_done
|
|||
|
||||
assert(length == toku_omt_size(omt));
|
||||
r = toku_omt_delete_at(omt, length);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
assert(length == toku_omt_size(omt));
|
||||
r = toku_omt_delete_at(omt, length+1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
while (length > 0) {
|
||||
assert(length == toku_omt_size(omt));
|
||||
u_int32_t index_to_delete = random()%length;
|
||||
|
@ -534,10 +534,10 @@ void test_create_delete_at(enum create_type create_choice, enum close_when_done
|
|||
assert(length == 0);
|
||||
assert(length == toku_omt_size(omt));
|
||||
r = toku_omt_delete_at(omt, length);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
assert(length == toku_omt_size(omt));
|
||||
r = toku_omt_delete_at(omt, length+1);
|
||||
CKERR2(r, ERANGE);
|
||||
CKERR2(r, EINVAL);
|
||||
test_close(close);
|
||||
}
|
||||
|
||||
|
@ -550,9 +550,9 @@ void test_split_merge(enum create_type create_choice, enum close_when_done close
|
|||
|
||||
for (i = 0; i <= length; i++) {
|
||||
r = toku_omt_split_at(omt, &right_split, length+1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
r = toku_omt_split_at(omt, &right_split, length+2);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
|
||||
//
|
||||
// test successful split
|
||||
|
@ -571,19 +571,19 @@ void test_split_merge(enum create_type create_choice, enum close_when_done close
|
|||
// verify that new OMT's cannot do bad splits
|
||||
//
|
||||
r = toku_omt_split_at(left_split, &omt, i+1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
assert(toku_omt_size(left_split) == i);
|
||||
assert(toku_omt_size(right_split) == length - i);
|
||||
r = toku_omt_split_at(left_split, &omt, i+2);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
assert(toku_omt_size(left_split) == i);
|
||||
assert(toku_omt_size(right_split) == length - i);
|
||||
r = toku_omt_split_at(right_split, &omt, length - i + 1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
assert(toku_omt_size(left_split) == i);
|
||||
assert(toku_omt_size(right_split) == length - i);
|
||||
r = toku_omt_split_at(right_split, &omt, length - i + 1);
|
||||
CKERR2(r,ERANGE);
|
||||
CKERR2(r,EINVAL);
|
||||
assert(toku_omt_size(left_split) == i);
|
||||
assert(toku_omt_size(right_split) == length - i);
|
||||
|
||||
|
@ -792,7 +792,7 @@ void test_find(enum create_type create_choice, enum close_when_done close) {
|
|||
heavy_extra(&extra, 0, 0);
|
||||
test_find_dir(-1, &extra, test_heaviside, DB_NOTFOUND, FALSE, 0, 0, FALSE);
|
||||
test_find_dir(+1, &extra, test_heaviside, 0, TRUE, 0, 0, TRUE);
|
||||
test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, 0, 0, TRUE);
|
||||
test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, 0, 0, FALSE);
|
||||
|
||||
/*
|
||||
0...0
|
||||
|
@ -828,7 +828,7 @@ void test_find(enum create_type create_choice, enum close_when_done close) {
|
|||
heavy_extra(&extra, length/2, length/2);
|
||||
test_find_dir(-1, &extra, test_heaviside, 0, TRUE, length/2-1, length/2-1, TRUE);
|
||||
test_find_dir(+1, &extra, test_heaviside, 0, TRUE, length/2, length/2, TRUE);
|
||||
test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, length/2, length/2, TRUE);
|
||||
test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, length/2, length/2, FALSE);
|
||||
|
||||
/*
|
||||
-...-0...0+...+
|
||||
|
|
Loading…
Add table
Reference in a new issue