Commit c28b01aa authored by Yoni Fogel's avatar Yoni Fogel

refs #5308 Remove unused omt/omt-tmpl functions (and tests for them)

git-svn-id: file:///svn/toku/tokudb@46193 c7de825b-a66e-492c-adef-691d508d4ae1
parent f10ac37b
...@@ -899,39 +899,4 @@ int omt<omtdata_t, omtdataout_t>::find_internal_minus(const node_idx n_idx, cons ...@@ -899,39 +899,4 @@ int omt<omtdata_t, omtdataout_t>::find_internal_minus(const node_idx n_idx, cons
return this->find_internal_minus<omtcmp_t, h>(n->left, extra, value, idxp); return this->find_internal_minus<omtcmp_t, h>(n->left, extra, value, idxp);
} }
} }
template<typename omtdata_t, typename omtdataout_t>
int omt<omtdata_t, omtdataout_t>::deep_clone_iter(const omtdata_t &value, const uint32_t idx, omt *const dest) {
#ifndef __ICC
static_assert(std::is_pointer<omtdata_t>::value, "omtdata_t isn't a pointer, can't do deep clone");
#endif
invariant_notnull(dest);
invariant(idx == dest->d.a.num_values);
invariant(idx < dest->capacity);
omtdata_t &destp = dest->d.a.values[dest->d.a.num_values++];
XMEMDUP(destp, value);
return 0;
}
template<typename omtdata_t, typename omtdataout_t>
int omt<omtdata_t, omtdataout_t>::free_items_iter(omtdata_t *value, const uint32_t UU(idx), void *const UU(unused)) {
#ifndef __ICC
static_assert(std::is_pointer<omtdata_t>::value, "omtdata_t isn't a pointer, can't do free items");
#endif
invariant_notnull(*value);
toku_free(*value);
return 0;
}
template<typename omtdata_t, typename omtdataout_t>
void omt<omtdata_t, omtdataout_t>::free_items(void) {
this->iterate_ptr<void, free_items_iter>(nullptr);
}
template<typename omtdata_t, typename omtdataout_t>
void omt<omtdata_t, omtdataout_t>::deep_clone(const omt &src) {
this->create_internal(src.size());
int r = src.iterate<omt, deep_clone_iter>(this);
lazy_assert_zero(r);
this->d.a.num_values = src.size();
}
} // namespace toku } // namespace toku
...@@ -524,29 +524,6 @@ private: ...@@ -524,29 +524,6 @@ private:
template<typename omtcmp_t, template<typename omtcmp_t,
int (*h)(const omtdata_t &, const omtcmp_t &)> int (*h)(const omtdata_t &, const omtcmp_t &)>
int find_internal_minus(const node_idx n_idx, const omtcmp_t &extra, omtdataout_t *value, uint32_t *const idxp) const; int find_internal_minus(const node_idx n_idx, const omtcmp_t &extra, omtdataout_t *value, uint32_t *const idxp) const;
__attribute__((nonnull))
static int deep_clone_iter(const omtdata_t &value, const uint32_t idx, omt *const dest);
static int free_items_iter(omtdata_t *value, const uint32_t UU(idx), void *const UU(unused));
public:
/**
* Effect: Iterate over the values of the omt, from left to right, freeing each value with toku_free
* Requires: all items in OMT to have been malloced with toku_malloc
* Rational: This function was added due to a problem encountered in ft-ops.c. We needed to free the elements and then
* destroy the OMT. However, destroying the OMT requires invalidating cursors. This cannot be done if the values of the OMT
* have been already freed. So, this function is written to invalidate cursors and free items.
*/
void free_items(void);
/**
* Effect: Creates a copy of an omt.
* Creates this as the clone.
* Each element is assumed to be a pointer, and the underlying data is duplicated for the clone using toku_malloc.
* Performance: the running time of iterate()
*/
void deep_clone(const omt &src);
}; };
} // namespace toku } // namespace toku
......
...@@ -650,19 +650,6 @@ int toku_omt_fetch(OMT V, uint32_t i, OMTVALUE *v) { ...@@ -650,19 +650,6 @@ int toku_omt_fetch(OMT V, uint32_t i, OMTVALUE *v) {
return 0; return 0;
} }
static int
free_item (OMTVALUE lev, uint32_t UU(idx), void *vsi) {
assert(vsi == NULL);
toku_free(lev);
return 0;
}
void toku_omt_free_items(OMT omt) {
int r = toku_omt_iterate(omt, free_item, NULL);
lazy_assert_zero(r);
}
int toku_omt_iterate(OMT omt, int (*f)(OMTVALUE, uint32_t, void*), void*v) { int toku_omt_iterate(OMT omt, int (*f)(OMTVALUE, uint32_t, void*), void*v) {
if (omt->is_array) { if (omt->is_array) {
return iterate_internal_array(omt, 0, omt_size(omt), f, v); return iterate_internal_array(omt, 0, omt_size(omt), f, v);
...@@ -782,78 +769,6 @@ int toku_omt_merge(OMT leftomt, OMT rightomt, OMT *newomtp) { ...@@ -782,78 +769,6 @@ int toku_omt_merge(OMT leftomt, OMT rightomt, OMT *newomtp) {
return 0; return 0;
} }
struct copy_data_extra {
OMTVALUE *a;
uint32_t eltsize;
};
static int copy_data_iter(OMTVALUE v, uint32_t idx, void *ve) {
struct copy_data_extra *CAST_FROM_VOIDP(e, ve);
memcpy(e->a[idx], v, e->eltsize);
return 0;
}
static int omt_copy_data(OMTVALUE *a, OMT omt, uint32_t eltsize) {
struct copy_data_extra extra = { .a = a, .eltsize = eltsize };
if (omt->is_array) {
return iterate_internal_array(omt, 0, omt_size(omt), copy_data_iter, &extra);
}
return iterate_internal(omt, 0, nweight(omt, omt->i.t.root), omt->i.t.root, 0, copy_data_iter, &extra);
}
int toku_omt_clone(OMT *dest, OMT src, uint32_t eltsize) {
uint32_t size = omt_size(src);
if (size == 0) {
toku_omt_create(dest);
return 0;
}
OMTVALUE *XMALLOC_N(size, a);
for (uint32_t i = 0; i < size; ++i) {
CAST_FROM_VOIDP(a[i], toku_xmalloc(eltsize));
}
int r = omt_copy_data(a, src, eltsize);
if (r != 0) { goto err; }
r = toku_omt_create_steal_sorted_array(dest, &a, size, size);
if (r != 0) { goto err; }
return 0;
err:
toku_free(a);
return r;
}
int toku_omt_clone_pool(OMT *dest, OMT src, uint32_t eltsize) {
uint32_t size = omt_size(src);
if (size == 0) {
toku_omt_create(dest);
return 0;
}
OMTVALUE *XMALLOC_N(size, a);
unsigned char *XMALLOC_N(eltsize * size, data);
for (uint32_t i = 0; i < size; ++i) {
a[i] = &data[eltsize * i];
}
int r = omt_copy_data(a, src, eltsize);
if (r != 0) { goto err; }
r = toku_omt_create_steal_sorted_array(dest, &a, size, size);
if (r != 0) { goto err; }
return 0;
err:
toku_free(data);
toku_free(a);
return r;
}
void toku_omt_free_items_pool(OMT omt) {
if (toku_omt_size(omt) == 0) {
return;
}
OMTVALUE v;
int r = toku_omt_fetch(omt, 0, &v);
lazy_assert_zero(r);
invariant(v != NULL);
toku_free(v);
}
int toku_omt_clone_noptr(OMT *dest, OMT src) { int toku_omt_clone_noptr(OMT *dest, OMT src) {
uint32_t size = omt_size(src); uint32_t size = omt_size(src);
if (size == 0) { if (size == 0) {
......
...@@ -137,13 +137,6 @@ int toku_omt_iterate_on_range(OMT omt, uint32_t left, uint32_t right, int (*f)(O ...@@ -137,13 +137,6 @@ int toku_omt_iterate_on_range(OMT omt, uint32_t left, uint32_t right, int (*f)(O
// Performance: time=O(i+\log N) where i is the number of times f is called, and N is the number of elements in omt. // Performance: time=O(i+\log N) where i is the number of times f is called, and N is the number of elements in omt.
// Rational: Although the functional iterator requires defining another function (as opposed to C++ style iterator), it is much easier to read. // Rational: Although the functional iterator requires defining another function (as opposed to C++ style iterator), it is much easier to read.
void toku_omt_free_items(OMT omt);
// Effect: Iterate over the values of the omt, from left to right, freeing each value with toku_free
// Requires: all items in OMT to have been malloced with toku_malloc
// Rational: This function was added due to a problem encountered in ft-ops.c. We needed to free the elements and then
// destroy the OMT. However, destroying the OMT requires invalidating cursors. This cannot be done if the values of the OMT
// have been already freed. So, this function is written to invalidate cursors and free items.
int toku_omt_iterate(OMT omt, int (*f)(OMTVALUE, uint32_t, void*), void*v); int toku_omt_iterate(OMT omt, int (*f)(OMTVALUE, uint32_t, void*), void*v);
// Effect: Iterate over the values of the omt, from left to right, calling f on each value. // Effect: Iterate over the values of the omt, from left to right, calling f on each value.
// The second argument passed to f is the index of the value. // The second argument passed to f is the index of the value.
...@@ -313,32 +306,6 @@ int toku_omt_merge(OMT leftomt, OMT rightomt, OMT *newomt); ...@@ -313,32 +306,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_clone(OMT *dest, OMT src, uint32_t eltsize);
// Effect: Creates a copy of an omt.
// Sets *dest to the clone
// Each element is allocated separately with toku_xmalloc and is assumed to be eltsize big.
// Returns 0 on success
// ENOMEM on out of memory.
// On error, nothing is modified.
// Performance: time between O(n) and O(n log n), depending how long it
// takes to traverse src.
int toku_omt_clone_pool(OMT *dest, OMT src, uint32_t eltsize);
// Effect: Creates a copy of an omt.
// Sets *dest to the clone
// Each element is copied to a contiguous buffer allocated with toku_xmalloc and each element is assumed to be eltsize big.
// Returns 0 on success
// ENOMEM on out of memory.
// On error, nothing is modified.
// Performance: time between O(n) and O(n log n), depending how long it
// takes to traverse src.
void toku_omt_free_items_pool(OMT omt);
// Effect: Frees the memory containing the items in an omt created with toku_omt_clone_pool.
// Since toku_omt_clone_pool allocates a contiguous chunk of memory and
// the first item is at the first position, this just gets the first
// value out of the omt and frees it for you.
int toku_omt_clone_noptr(OMT *dest, OMT src); int toku_omt_clone_noptr(OMT *dest, OMT src);
// Effect: Creates a copy of an omt. // Effect: Creates a copy of an omt.
// Sets *dest to the clone // Sets *dest to the clone
......
...@@ -808,45 +808,6 @@ test_clone(uint32_t nelts) ...@@ -808,45 +808,6 @@ test_clone(uint32_t nelts)
} }
toku_omt_destroy(&dest); toku_omt_destroy(&dest);
toku_omt_destroy(&src); toku_omt_destroy(&src);
r = toku_omt_create(&src);
assert_zero(r);
long array[nelts];
for (long i = 0; i < nelts; ++i) {
array[i] = i;
r = toku_omt_insert_at(src, &array[i], i);
assert_zero(r);
}
r = toku_omt_clone_pool(&dest, src, (sizeof array[0]));
assert_zero(r);
assert(dest != NULL);
assert(toku_omt_size(dest) == nelts);
for (long i = 0; i < nelts; ++i) {
OMTVALUE v;
long *l;
r = toku_omt_fetch(dest, i, &v);
assert_zero(r);
CAST_FROM_VOIDP(l, v);
assert(*l == i);
}
toku_omt_free_items_pool(dest);
toku_omt_destroy(&dest);
r = toku_omt_clone(&dest, src, (sizeof array[0]));
assert_zero(r);
assert(dest != NULL);
assert(toku_omt_size(dest) == nelts);
for (long i = 0; i < nelts; ++i) {
OMTVALUE v;
long *l;
r = toku_omt_fetch(dest, i, &v);
assert_zero(r);
CAST_FROM_VOIDP(l, v);
assert(*l == i);
}
toku_omt_free_items(dest);
toku_omt_destroy(&dest);
toku_omt_destroy(&src);
} }
int int
......
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