Commit 64d5e7a2 authored by Nicolas Denoyelle's avatar Nicolas Denoyelle

checkpatch

parent 8ea0f2a2
...@@ -8,8 +8,7 @@ static int tleaf_init_with_it(excit_t it, ...@@ -8,8 +8,7 @@ static int tleaf_init_with_it(excit_t it,
const ssize_t *arities, const ssize_t *arities,
const enum tleaf_it_policy_e policy, const enum tleaf_it_policy_e policy,
const ssize_t *user_policy, const ssize_t *user_policy,
excit_t levels, excit_t levels, excit_t levels_inverse);
excit_t levels_inverse);
static int tleaf_it_alloc(excit_t it) static int tleaf_it_alloc(excit_t it)
{ {
...@@ -40,12 +39,12 @@ static void tleaf_it_free(excit_t it) ...@@ -40,12 +39,12 @@ static void tleaf_it_free(excit_t it)
excit_free(data_it->levels_inverse); excit_free(data_it->levels_inverse);
} }
static int tleaf_it_size(const excit_t it, ssize_t *size) static int tleaf_it_size(const excit_t it, ssize_t *size)
{ {
struct tleaf_it_s *data_it = it->data; struct tleaf_it_s *data_it = it->data;
ssize_t i, s=1; ssize_t i, s = 1;
for(i = 0; i < data_it->depth; i++)
for (i = 0; i < data_it->depth; i++)
s *= data_it->arities[i]; s *= data_it->arities[i];
*size = data_it->depth ? s : 0; *size = data_it->depth ? s : 0;
return EXCIT_SUCCESS; return EXCIT_SUCCESS;
...@@ -54,6 +53,7 @@ static int tleaf_it_size(const excit_t it, ssize_t *size) ...@@ -54,6 +53,7 @@ static int tleaf_it_size(const excit_t it, ssize_t *size)
static int tleaf_it_rewind(excit_t it) static int tleaf_it_rewind(excit_t it)
{ {
struct tleaf_it_s *data_it = it->data; struct tleaf_it_s *data_it = it->data;
return excit_rewind(data_it->levels); return excit_rewind(data_it->levels);
} }
...@@ -74,8 +74,8 @@ static int tleaf_it_copy(excit_t dst_it, const excit_t src_it) ...@@ -74,8 +74,8 @@ static int tleaf_it_copy(excit_t dst_it, const excit_t src_it)
} }
/* dst is not initialized (anymore) */ /* dst is not initialized (anymore) */
excit_t levels = excit_dup(src->levels); excit_t levels = excit_dup(src->levels);
if (levels == NULL) { if (levels == NULL) {
err = -EXCIT_ENOMEM; err = -EXCIT_ENOMEM;
goto error; goto error;
...@@ -88,9 +88,9 @@ static int tleaf_it_copy(excit_t dst_it, const excit_t src_it) ...@@ -88,9 +88,9 @@ static int tleaf_it_copy(excit_t dst_it, const excit_t src_it)
goto error_with_levels; goto error_with_levels;
} }
err = tleaf_init_with_it(dst_it, src->depth + 1, src->arities, err = tleaf_init_with_it(dst_it, src->depth + 1, src->arities,
TLEAF_POLICY_USER, src->order, levels, levels_inverse); TLEAF_POLICY_USER, src->order, levels,
levels_inverse);
if (err != EXCIT_SUCCESS) if (err != EXCIT_SUCCESS)
goto error_with_levels_inverse; goto error_with_levels_inverse;
...@@ -107,12 +107,14 @@ error: ...@@ -107,12 +107,14 @@ error:
static int tleaf_it_pos(const excit_t it, ssize_t *value) static int tleaf_it_pos(const excit_t it, ssize_t *value)
{ {
struct tleaf_it_s *data_it = it->data; struct tleaf_it_s *data_it = it->data;
return excit_pos(data_it->levels, value); return excit_pos(data_it->levels, value);
} }
static ssize_t tleaf_it_value(struct tleaf_it_s *it) static ssize_t tleaf_it_value(struct tleaf_it_s *it)
{ {
ssize_t i, acc = 1, val = 0; ssize_t i, acc = 1, val = 0;
for (i = 0; i < it->depth; i++) { for (i = 0; i < it->depth; i++) {
val += acc * it->buf[i]; val += acc * it->buf[i];
acc *= it->arities[it->order[i]]; acc *= it->arities[it->order[i]];
...@@ -161,8 +163,9 @@ int tleaf_it_rank(const excit_t it, const ssize_t *indexes, ssize_t *n) ...@@ -161,8 +163,9 @@ int tleaf_it_rank(const excit_t it, const ssize_t *indexes, ssize_t *n)
if (err != EXCIT_SUCCESS) if (err != EXCIT_SUCCESS)
return err; return err;
ssize_t i, acc = 1, val = 0; ssize_t i, acc = 1, val = 0;
for (i = 0; i < data_it->depth; i++) { for (i = 0; i < data_it->depth; i++) {
val += acc * data_it->buf[i]; val += acc * data_it->buf[i];
acc *= data_it->arities[data_it->order_inverse[i]]; acc *= data_it->arities[data_it->order_inverse[i]];
...@@ -172,16 +175,18 @@ int tleaf_it_rank(const excit_t it, const ssize_t *indexes, ssize_t *n) ...@@ -172,16 +175,18 @@ int tleaf_it_rank(const excit_t it, const ssize_t *indexes, ssize_t *n)
return EXCIT_SUCCESS; return EXCIT_SUCCESS;
} }
static int tleaf_add_level(excit_t levels, const ssize_t arity){ static int tleaf_add_level(excit_t levels, const ssize_t arity)
excit_t level = excit_alloc(EXCIT_RANGE); {
if (level == NULL) excit_t level = excit_alloc(EXCIT_RANGE);
return -EXCIT_ENOMEM;
if (level == NULL)
return -EXCIT_ENOMEM;
int err = excit_range_init(level, 0, arity - 1, 1);
int err;
err = excit_range_init(level, 0, arity - 1, 1);
if (err != EXCIT_SUCCESS) if (err != EXCIT_SUCCESS)
goto error; goto error;
err = excit_product_add(levels, level); err = excit_product_add(levels, level);
if (err != EXCIT_SUCCESS) if (err != EXCIT_SUCCESS)
goto error; goto error;
...@@ -196,8 +201,7 @@ static int tleaf_init_with_it(excit_t it, ...@@ -196,8 +201,7 @@ static int tleaf_init_with_it(excit_t it,
const ssize_t *arities, const ssize_t *arities,
const enum tleaf_it_policy_e policy, const enum tleaf_it_policy_e policy,
const ssize_t *user_policy, const ssize_t *user_policy,
excit_t levels, excit_t levels, excit_t levels_inverse)
excit_t levels_inverse)
{ {
if (it == NULL || it->data == NULL) if (it == NULL || it->data == NULL)
return -EXCIT_EINVAL; return -EXCIT_EINVAL;
...@@ -233,7 +237,7 @@ static int tleaf_init_with_it(excit_t it, ...@@ -233,7 +237,7 @@ static int tleaf_init_with_it(excit_t it,
/* Set order inverse */ /* Set order inverse */
data_it->order_inverse = data_it->order_inverse =
malloc(sizeof(*data_it->order_inverse) * data_it->depth); malloc(sizeof(*data_it->order_inverse) * data_it->depth);
if (data_it->order_inverse == NULL) { if (data_it->order_inverse == NULL) {
err = -EXCIT_ENOMEM; err = -EXCIT_ENOMEM;
goto error_with_order; goto error_with_order;
...@@ -264,25 +268,31 @@ static int tleaf_init_with_it(excit_t it, ...@@ -264,25 +268,31 @@ static int tleaf_init_with_it(excit_t it,
err = -EXCIT_ENOMEM; err = -EXCIT_ENOMEM;
goto error_with_buf; goto error_with_buf;
} }
for (i = 0; i < data_it->depth; i++){ for (i = 0; i < data_it->depth; i++) {
err = tleaf_add_level(levels, data_it->arities[data_it->order[i]]); ssize_t l = data_it->order[i];
if(err != EXCIT_SUCCESS)
err = tleaf_add_level(levels,
data_it->arities[l]);
if (err != EXCIT_SUCCESS)
goto error_with_levels; goto error_with_levels;
} }
} else { } else {
data_it->levels = levels; data_it->levels = levels;
} }
if (levels_inverse == NULL) { if (levels_inverse == NULL) {
data_it->levels_inverse = excit_alloc(EXCIT_PRODUCT); data_it->levels_inverse = excit_alloc(EXCIT_PRODUCT);
if (data_it->levels_inverse == NULL) { if (data_it->levels_inverse == NULL) {
err = -EXCIT_ENOMEM; err = -EXCIT_ENOMEM;
goto error_with_levels; goto error_with_levels;
} }
for (i = 0; i < data_it->depth; i++){ for (i = 0; i < data_it->depth; i++) {
err = tleaf_add_level(levels_inverse, data_it->arities[data_it->order_inverse[i]]); ssize_t l = data_it->order_inverse[i];
if(err != EXCIT_SUCCESS)
err = tleaf_add_level(levels_inverse,
data_it->arities[l]);
if (err != EXCIT_SUCCESS)
goto error_with_levels_inverse; goto error_with_levels_inverse;
} }
} else { } else {
...@@ -293,7 +303,7 @@ static int tleaf_init_with_it(excit_t it, ...@@ -293,7 +303,7 @@ static int tleaf_init_with_it(excit_t it,
error_with_levels_inverse: error_with_levels_inverse:
excit_free(data_it->levels_inverse); excit_free(data_it->levels_inverse);
data_it->levels_inverse = NULL; data_it->levels_inverse = NULL;
error_with_levels: error_with_levels:
excit_free(data_it->levels); excit_free(data_it->levels);
data_it->levels = NULL; data_it->levels = NULL;
...@@ -323,13 +333,16 @@ int excit_tleaf_init(excit_t it, ...@@ -323,13 +333,16 @@ int excit_tleaf_init(excit_t it,
NULL, NULL); NULL, NULL);
} }
int tleaf_split_levels(excit_t levels, const ssize_t depth, const ssize_t n, excit_t** out){ int tleaf_split_levels(excit_t levels, const ssize_t depth, const ssize_t n,
*out = malloc(sizeof(**out) * n); excit_t **out)
{
*out = malloc(sizeof(**out) * n);
if (*out == NULL) if (*out == NULL)
return -EXCIT_ENOMEM; return -EXCIT_ENOMEM;
int err = excit_product_split_dim(levels, depth, n, *out); int err = excit_product_split_dim(levels, depth, n, *out);
if (err != EXCIT_SUCCESS){
if (err != EXCIT_SUCCESS) {
free(*out); free(*out);
*out = NULL; *out = NULL;
return err; return err;
...@@ -348,17 +361,22 @@ int tleaf_it_split(const excit_t it, const ssize_t depth, ...@@ -348,17 +361,22 @@ int tleaf_it_split(const excit_t it, const ssize_t depth,
return -EXCIT_EINVAL; return -EXCIT_EINVAL;
struct tleaf_it_s *data_it = it->data; struct tleaf_it_s *data_it = it->data;
if (data_it->arities[data_it->order[depth]] % n != 0) if (data_it->arities[data_it->order[depth]] % n != 0)
return -EXCIT_EINVAL; return -EXCIT_EINVAL;
int err; int err;
excit_t *levels, *levels_inverse; excit_t *levels, *levels_inverse;
err = tleaf_split_levels(data_it->levels, data_it->order[depth], n, &levels); err =
if(err != EXCIT_SUCCESS) tleaf_split_levels(data_it->levels, data_it->order[depth], n,
&levels);
if (err != EXCIT_SUCCESS)
return err; return err;
err = tleaf_split_levels(data_it->levels_inverse, data_it->order_inverse[depth], n, &levels_inverse); err =
tleaf_split_levels(data_it->levels_inverse,
data_it->order_inverse[depth], n,
&levels_inverse);
if (err != EXCIT_SUCCESS) if (err != EXCIT_SUCCESS)
goto error_with_levels; goto error_with_levels;
...@@ -367,7 +385,8 @@ int tleaf_it_split(const excit_t it, const ssize_t depth, ...@@ -367,7 +385,8 @@ int tleaf_it_split(const excit_t it, const ssize_t depth,
data_it->depth + 1, data_it->depth + 1,
data_it->arities, data_it->arities,
TLEAF_POLICY_USER, TLEAF_POLICY_USER,
data_it->order, levels[i], levels_inverse[i]); data_it->order, levels[i],
levels_inverse[i]);
if (err != EXCIT_SUCCESS) if (err != EXCIT_SUCCESS)
goto error_with_levels_inverse; goto error_with_levels_inverse;
} }
......
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