Commit a2b3c3be authored by Nicolas Denoyelle's avatar Nicolas Denoyelle

add indexer to tree levels

parent 4b54d0f5
...@@ -18,17 +18,18 @@ static excit_t create_test_tleaf(const ssize_t depth, ...@@ -18,17 +18,18 @@ static excit_t create_test_tleaf(const ssize_t depth,
it = excit_alloc_test(EXCIT_TLEAF); it = excit_alloc_test(EXCIT_TLEAF);
assert(it != NULL); assert(it != NULL);
err = excit_tleaf_init(it, depth + 1, arities, indexes, policy, user_policy); err =
excit_tleaf_init(it, depth + 1, arities, indexes, policy,
user_policy);
assert(err == EXCIT_SUCCESS); assert(err == EXCIT_SUCCESS);
ssize_t i, size = 1, it_size, arity; ssize_t i, size = 1, it_size, arity;
for (i = 0; i < depth; i++){ for (i = 0; i < depth; i++) {
if(indexes && indexes[i]){ if (indexes && indexes[i])
assert(excit_size(indexes[i], &arity) == EXCIT_SUCCESS); assert(excit_size(indexes[i], &arity) == EXCIT_SUCCESS);
} else { else
arity = arities[i]; arity = arities[i];
}
size *= arity; size *= arity;
} }
assert(excit_size(it, &it_size) == EXCIT_SUCCESS); assert(excit_size(it, &it_size) == EXCIT_SUCCESS);
...@@ -50,50 +51,59 @@ static void tleaf_test_round_robin_policy(excit_t tleaf) ...@@ -50,50 +51,59 @@ static void tleaf_test_round_robin_policy(excit_t tleaf)
assert(excit_next(tleaf, &value) == EXCIT_STOPIT); assert(excit_next(tleaf, &value) == EXCIT_STOPIT);
} }
static void tleaf_test_indexed_round_robin_policy(excit_t tleaf, const ssize_t depth, static void tleaf_test_indexed_round_robin_policy(excit_t tleaf,
const ssize_t *arities, excit_t *_indexes) const ssize_t depth,
const ssize_t *arities,
excit_t *_indexes)
{ {
ssize_t i, j, value, indexed_value, indexed_mul, size, arity; ssize_t i, j, value, indexed_value, indexed_mul, size, arity;
ssize_t *values = malloc(depth * sizeof(*values)); ssize_t *values = malloc(depth * sizeof(*values));
excit_t check = excit_alloc(EXCIT_PRODUCT); excit_t check = excit_alloc(EXCIT_PRODUCT);
assert(values != NULL); assert(values != NULL);
assert(check != NULL); assert(check != NULL);
for(i = 0; i<depth; i++){ for (i = 0; i < depth; i++) {
excit_t range = excit_alloc(EXCIT_RANGE); excit_t range = excit_alloc(EXCIT_RANGE);
assert(range != NULL); assert(range != NULL);
assert(excit_range_init(range, 0, arities[i]-1, 1) == EXCIT_SUCCESS); assert(excit_range_init(range, 0, arities[i] - 1, 1) ==
EXCIT_SUCCESS);
if(_indexes[i] != NULL){
if (_indexes[i] != NULL) {
excit_t comp = excit_alloc(EXCIT_COMPOSITION); excit_t comp = excit_alloc(EXCIT_COMPOSITION);
assert(comp != NULL); assert(comp != NULL);
excit_t index = excit_dup(_indexes[i]); excit_t index = excit_dup(_indexes[i]);
assert(index != NULL); assert(index != NULL);
assert(excit_rewind(index) == EXCIT_SUCCESS); assert(excit_rewind(index) == EXCIT_SUCCESS);
assert(excit_composition_init(comp, range, index) == EXCIT_SUCCESS); assert(excit_composition_init(comp, range, index) ==
assert(excit_product_add(check,comp) == EXCIT_SUCCESS); EXCIT_SUCCESS);
assert(excit_product_add(check, comp) == EXCIT_SUCCESS);
} else { } else {
assert(excit_product_add(check,range) == EXCIT_SUCCESS); assert(excit_product_add(check, range) ==
EXCIT_SUCCESS);
} }
} }
assert(excit_size(tleaf, &size) == EXCIT_SUCCESS); assert(excit_size(tleaf, &size) == EXCIT_SUCCESS);
assert(excit_rewind(tleaf) == EXCIT_SUCCESS); assert(excit_rewind(tleaf) == EXCIT_SUCCESS);
assert(excit_rewind(check) == EXCIT_SUCCESS); assert(excit_rewind(check) == EXCIT_SUCCESS);
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
assert(excit_next(tleaf, &value) == EXCIT_SUCCESS); assert(excit_next(tleaf, &value) == EXCIT_SUCCESS);
assert(excit_next(check, values) == EXCIT_SUCCESS); assert(excit_next(check, values) == EXCIT_SUCCESS);
indexed_value = 0; indexed_value = 0;
indexed_mul = 1; indexed_mul = 1;
for(j=0; j<depth; j++){ for (j = 0; j < depth; j++) {
arity = arities[depth-j-1]; arity = arities[depth - j - 1];
indexed_value += indexed_mul * values[depth-j-1]; indexed_value += indexed_mul * values[depth - j - 1];
indexed_mul *= arity; indexed_mul *= arity;
} }
assert(value == indexed_value); assert(value == indexed_value);
} }
excit_free(check); excit_free(check);
free(values); free(values);
} }
...@@ -150,7 +160,7 @@ static void tleaf_test_round_robin_split(excit_t tleaf, ...@@ -150,7 +160,7 @@ static void tleaf_test_round_robin_split(excit_t tleaf,
} }
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
excit_t it = split[i*ncut/size]; excit_t it = split[i * ncut / size];
assert(excit_next(it, &value) == EXCIT_SUCCESS); assert(excit_next(it, &value) == EXCIT_SUCCESS);
assert(value == i); assert(value == i);
...@@ -166,42 +176,51 @@ void run_tests(const ssize_t depth, const ssize_t *arities) ...@@ -166,42 +176,51 @@ void run_tests(const ssize_t depth, const ssize_t *arities)
{ {
/* Test of round robin policy */ /* Test of round robin policy */
excit_t rrobin = excit_t rrobin =
create_test_tleaf(depth, arities, NULL, TLEAF_POLICY_ROUND_ROBIN, NULL); create_test_tleaf(depth, arities, NULL, TLEAF_POLICY_ROUND_ROBIN,
NULL);
assert(rrobin != NULL); assert(rrobin != NULL);
tleaf_test_round_robin_policy(rrobin); tleaf_test_round_robin_policy(rrobin);
assert(excit_rewind(rrobin) == EXCIT_SUCCESS);
/* Test of split operation on round robin policy */ /* Test of split operation on round robin policy */
tleaf_test_round_robin_split(rrobin, depth, arities); tleaf_test_round_robin_split(rrobin, depth, arities);
excit_free(rrobin); excit_free(rrobin);
/* Test of indexing on a round robin policy */ /* Test of indexing on a round robin policy */
ssize_t i; ssize_t i;
excit_t *indexes = malloc(depth * sizeof(*indexes)); excit_t *indexes = malloc(depth * sizeof(*indexes));
assert(indexes != NULL); assert(indexes != NULL);
for(i = 0; i<depth; i++){ for (i = 0; i < depth; i++) {
if(arities[i] > 2){ if (arities[i] > 2) {
indexes[i] = excit_alloc(EXCIT_RANGE); indexes[i] = excit_alloc(EXCIT_RANGE);
assert(indexes[i] != NULL); assert(indexes[i] != NULL);
assert(excit_range_init(indexes[i], 0, arities[i]/2 - 1, 1) == EXCIT_SUCCESS); assert(excit_range_init
(indexes[i], 0, arities[i] / 2 - 1,
1) == EXCIT_SUCCESS);
} else { } else {
indexes[i] = NULL; indexes[i] = NULL;
} }
} }
excit_t indexed_rrobin = excit_t indexed_rrobin =
create_test_tleaf(depth, arities, indexes, TLEAF_POLICY_ROUND_ROBIN, NULL); create_test_tleaf(depth, arities, indexes, TLEAF_POLICY_ROUND_ROBIN,
assert(indexed_rrobin != NULL); NULL);
tleaf_test_indexed_round_robin_policy(indexed_rrobin, depth, arities, indexes); assert(indexed_rrobin != NULL);
tleaf_test_indexed_round_robin_policy(indexed_rrobin, depth, arities,
indexes);
excit_free(indexed_rrobin); excit_free(indexed_rrobin);
for(i = 0; i<depth; i++) for (i = 0; i < depth; i++)
excit_free(indexes[i]); excit_free(indexes[i]);
free(indexes); free(indexes);
/* Test of scatter policy */ /* Test of scatter policy */
excit_t scatter = excit_t scatter =
create_test_tleaf(depth, arities, NULL, TLEAF_POLICY_SCATTER, NULL); create_test_tleaf(depth, arities, NULL, TLEAF_POLICY_SCATTER, NULL);
assert(scatter != NULL); assert(scatter != NULL);
tleaf_test_scatter_policy_no_split(scatter, depth, arities); tleaf_test_scatter_policy_no_split(scatter, depth, arities);
...@@ -211,8 +230,9 @@ void run_tests(const ssize_t depth, const ssize_t *arities) ...@@ -211,8 +230,9 @@ void run_tests(const ssize_t depth, const ssize_t *arities)
i = 0; i = 0;
while (synthetic_tests[i]) { while (synthetic_tests[i]) {
excit_t it = excit_t it =
create_test_tleaf(depth, arities, NULL, TLEAF_POLICY_ROUND_ROBIN, create_test_tleaf(depth, arities, NULL,
NULL); TLEAF_POLICY_ROUND_ROBIN,
NULL);
synthetic_tests[i] (it); synthetic_tests[i] (it);
excit_free(it); excit_free(it);
......
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