Commit 5be95032 authored by NICOLAS DENOYELLE's avatar NICOLAS DENOYELLE

working tleaf

parent b8a35329
......@@ -2,6 +2,6 @@ AM_CFLAGS = -Wall -Werror -pedantic
lib_LTLIBRARIES = libexcit.la
libexcit_la_SOURCES = excit.c slice.c prod.c cons.c repeat.c hilbert2d.c range.c
libexcit_la_SOURCES = excit.c slice.c prod.c cons.c repeat.c hilbert2d.c range.c tleaf.c
include_HEADERS = excit.h
......@@ -300,3 +300,4 @@ struct excit_func_table_s excit_cons_func_table = {
cons_it_rank,
cons_it_pos
};
......@@ -7,6 +7,7 @@
#include "repeat.h"
#include "hilbert2d.h"
#include "range.h"
#include "tleaf.h"
#define CASE(val) case val: return #val; break
......@@ -47,8 +48,8 @@ int excit_set_dimension(excit_t it, ssize_t dimension)
{
if (!it)
return -EXCIT_EINVAL;
/* if (it->type != EXCIT_USER) */
/* return -EXCIT_ENOTSUP; */
if (it->type != EXCIT_USER)
return -EXCIT_ENOTSUP;
it->dimension = dimension;
return EXCIT_SUCCESS;
}
......
......@@ -15,6 +15,7 @@ enum excit_type_e {
EXCIT_HILBERT2D, /*!< Hilbert space filing curve */
EXCIT_PRODUCT, /*!< Iterator over the catesian product of iterators */
EXCIT_SLICE, /*!< Iterator using another iterator to index a third */
EXCIT_TLEAF, /*!< Iterator on tree leaves with all leaves at same depth */
EXCIT_USER, /*!< User-defined iterator */
EXCIT_TYPE_MAX /*!< Guard */
};
......@@ -396,8 +397,9 @@ int excit_slice_init(excit_t it, excit_t src, excit_t indexer);
enum tleaf_it_policy_e {
ROUND_ROBIN, /* Iterate on tree leaves in a round-robin fashion */
SCATTER /* Iterate on tree leaves such spreading as much as possible */
TLEAF_POLICY_ROUND_ROBIN, /* Iterate on tree leaves in a round-robin fashion */
TLEAF_POLICY_SCATTER, /* Iterate on tree leaves such spreading as much as possible */
TLEAF_POLICY_USER /* Policy is a user defined policy */
};
......@@ -405,11 +407,19 @@ enum tleaf_it_policy_e {
* Initialize a tleaf iterator by giving its depth, levels arity and iteration policy.
* "it": a tleaf iterator
* "depth": the total number of levels of the tree, including leaves
* "arity": For each level, the number of children attached to a node. Leaves have no children, hence last level arity must be 0.
* "iter_policy": A policy for iteration on leaves.
* "offset": Offset on output. Usually 0.
* "stride": Stride applied at eache level for indexing. Usually 1. If NULLm it is set to one at each level..
*/
int excit_tleaf_init(excit_t it, const ssize_t depth, const ssize_t* arity, const enum tleaf_it_policy_e iter_policy, const ssize_t offset, const_ssize_t* strides);
* "arity": An array of size (depth-1). For each level, the number of children attached to a node. Leaves have no children, hence last level arity is ignored.
* "policy": A policy for iteration on leaves.
* "user_policy": If policy is TLEAF_POLICY_USER, then this argument must be an array of size (depth-1) providing the order (from 0 to (depth-2)) in wich levels are walked
* when resolving indexes. Underneath, a product iterator of range iterator returns indexes on last levels upon iterator queries. This set of indexes is then
* computed to a single leaf index. For instance TLEAF_POLICY_ROUND_ROBIN is obtained from walking from leaves to root whereas TLEAF_POLICY_SCATTER is
* obtained from walking from root to leaves.
*/
int excit_tleaf_init(excit_t it,
const ssize_t depth,
const ssize_t *arities,
const enum tleaf_it_policy_e policy,
const ssize_t *user_policy);
int tleaf_it_split_at_level(const excit_t it, const ssize_t level, const ssize_t n, excit_t *out);
#endif
......@@ -11,3 +11,4 @@ struct hilbert2d_it_s {
extern struct excit_func_table_s excit_hilbert2d_func_table;
#endif //EXCIT_HILBERT2D_H
......@@ -12,3 +12,4 @@ struct prod_it_s {
extern struct excit_func_table_s excit_prod_func_table;
#endif //EXCIT_PROD_H
......@@ -171,7 +171,6 @@ error:
for (; i < n; i++)
excit_free(results[i]);
return err;
>>>>>>> master
}
int excit_range_init(excit_t it, ssize_t first, ssize_t last, ssize_t step)
......@@ -182,7 +181,6 @@ int excit_range_init(excit_t it, ssize_t first, ssize_t last, ssize_t step)
return -EXCIT_EINVAL;
it->dimension = 1;
range_it = (struct range_it_s *)it->data;
>>>>>>> master
range_it->first = first;
range_it->v = first;
range_it->last = last;
......@@ -203,3 +201,4 @@ struct excit_func_table_s excit_range_func_table = {
range_it_rank,
range_it_pos
};
......@@ -13,3 +13,4 @@ struct range_it_s {
extern struct excit_func_table_s excit_range_func_table;
#endif //EXCIT_RANGE_H
This diff is collapsed.
......@@ -3,30 +3,15 @@
#include "excit.h"
struct tleaf_it_s{
ssize_t cur; // cursor of iterator position
ssize_t depth; // The tree depth
ssize_t* arity; // Number of children per node on each level
ssize_t* nleaves; // Number of leaves below each level
ssize_t offset; // When split occures, a resulting chunk can be offset as a subtree of the original one.
ssize_t* strides; // When split occures, indexing might not be contiguous anymore, the stride is applied by level. It shall be increased by 1 on level where split occures.
enum tleaf_it_policy_e policy; // iteration policy
struct tleaf_it_s {
ssize_t depth;
ssize_t *arities;
ssize_t *order;
ssize_t *order_inverse;
excit_t levels;
ssize_t *buf;
};
/* See excit.h for functions meaning */
int tleaf_it_alloc(excit_t);
void tleaf_it_free(excit_t);
int tleaf_it_copy(excit_t, const excit_t);
int tleaf_it_next(excit_t, ssize_t*);
int tleaf_it_peek(const excit_t, ssize_t*);
int tleaf_it_size(const excit_t, ssize_t*);
int tleaf_it_rewind(excit_t);
int tleaf_it_split(const excit_t, ssize_t, excit_t*);
int tleaf_it_nth(const excit_t, ssize_t, ssize_t*);
int tleaf_it_rank(const excit_t, const ssize_t*, ssize_t*);
int tleaf_it_pos(const excit_t, ssize_t*);
extern struct excit_func_table_s excit_tleaf_func_table;
#endif //TLEAF_H
......@@ -5,6 +5,81 @@
#define ES EXCIT_SUCCESS
#define TLEAF_DEPTH 3
#define TLEAF_NSPLIT 2
void test_tleaf_iterator(void)
{
excit_t it;
ssize_t depth = TLEAF_DEPTH+1;
ssize_t arities[(TLEAF_DEPTH)] = {3, 2, 4};
ssize_t i = 0, value;
ssize_t size = 1, it_size = 0;
int err = EXCIT_SUCCESS;
for (i = 0; i < depth-1; i++)
size *= arities[i];
it = excit_alloc(EXCIT_TLEAF);
err = excit_tleaf_init(it, depth, arities,
TLEAF_POLICY_ROUND_ROBIN, NULL);
assert(err == EXCIT_SUCCESS);
err = excit_size(it, &it_size);
assert(err == EXCIT_SUCCESS);
assert(it_size == size);
for (i = 0; i < size; i++) {
err = excit_next(it, &value);
assert(err == EXCIT_SUCCESS);
assert(value == i);
}
err = excit_next(it, &value);
assert(err == EXCIT_STOPIT);
excit_t split[TLEAF_NSPLIT];
for (i = 0; i < TLEAF_NSPLIT; i++)
split[i] = excit_alloc(EXCIT_TLEAF);
err = tleaf_it_split_at_level(it, 2, TLEAF_NSPLIT, split);
assert(err == EXCIT_SUCCESS);
err = excit_rewind(split[1]);
assert(err == EXCIT_SUCCESS);
err = excit_size(split[1], &it_size);
assert(err == EXCIT_SUCCESS);
assert(it_size == size/TLEAF_NSPLIT);
err = excit_next(split[1], &value);
assert(err == EXCIT_SUCCESS);
assert(value == 2);
err = excit_next(split[1], &value);
assert(err == EXCIT_SUCCESS);
assert(value == 3);
err = excit_next(split[1], &value);
assert(err == EXCIT_SUCCESS);
assert(value == 6);
err = excit_next(split[1], &value);
assert(err == EXCIT_SUCCESS);
assert(value == 7);
err = excit_next(split[1], &value);
assert(err == EXCIT_SUCCESS);
assert(value == 10);
err = excit_next(split[1], &value);
assert(err == EXCIT_SUCCESS);
assert(value == 11);
for (i = 0; i < TLEAF_NSPLIT; i++)
excit_free(split[i]);
excit_free(it);
}
void test_range_iterator(void)
{
excit_t it;
......@@ -664,5 +739,6 @@ int main(int argc, char *argv[])
test_cons_iterator();
test_repeat_iterator();
test_hilbert2d_iterator();
test_tleaf_iterator();
return 0;
}
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