Commit 3d6589dc authored by Yoni Fogel's avatar Yoni Fogel

Addresses #284

Coded toku_rt_decrease capacity to reclaim memory if size of range tree becomes
too small for local array.

git-svn-id: file:///svn/tokudb@1779 c7de825b-a66e-492c-adef-691d508d4ae1
parent 4f767ef4
......@@ -16,8 +16,6 @@
#include <stdlib.h>
#include <string.h>
#define AA __attribute__((__unused__))
const unsigned minlen = 64;
/*
......@@ -33,10 +31,21 @@ static int __toku_rt_p_cmp(toku_range_tree* tree,
return 0;
}
static int __toku_rt_decrease_capacity(toku_range_tree* tree, unsigned num AA) {
static int __toku_rt_decrease_capacity(toku_range_tree* tree, unsigned _num) {
assert(tree);
//TODO: reclaim capacity.
return 1;
unsigned num = _num < minlen ? minlen : _num;
if (tree->ranges_len >= num * 2) {
unsigned temp_len = tree->ranges_len;
while (temp_len >= num * 2) temp_len /= 2;
assert(temp_len >= _num); //Sanity check.
toku_range* temp_ranges =
realloc(tree->ranges, temp_len * sizeof(toku_range));
if (!temp_ranges) return errno;
tree->ranges = temp_ranges;
tree->ranges_len = temp_len;
}
return 0;
}
static int __toku_rt_increase_capacity(toku_range_tree* tree, unsigned num) {
......
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