#ifndef dg_tree_pack_H #define dg_tree_pack_H /* Pack of tree nodes in a dyadic grid. */ /* Last edited on 2014-05-15 20:34:56 by stolfilocal */ #include #include #include #include #include /* TREE PACKS A /tree pack/ is a vector of subtrees of a dyadic tree that correspond to the cells in a cell pack of a multidimensional dyadic grid. The pointers may be repeated (due to fold-over of the pack in the toroidal topology) or may be NULL. The elements of a tree pack are serialized in the same order as a the cells of the corresponding cell pack. */ vec_typedef(dg_tree_vec_t,dg_tree_vec,dg_tree_t); /* A general-purpose vector of tree node pointers, which may representa tree pack. */ bool_t dg_tree_pack_is_leaf (dg_tree_vec_t *N); /* Returns TRUE if all the trees in the pack {N} are non-{NULL}, and at least one is a leaf. */ bool_t dg_tree_pack_is_even(dg_tree_vec_t *N); /* Returns TRUE if all the trees in the pack {N} are non-{NULL}, and the lowest cell of {N} has even identifier. */ void dg_tree_pack_child ( dg_dim_t d, dg_grid_size_t psz[], dg_tree_vec_t *N, dg_axis_t i, int which, dg_tree_vec_t *NCH ); /* Assumes that {N} is a tree pack at some level {r} of the tree, with size vector {psz[0..d-1]}. Returns in {NCH} the tree pack of level {r+1} which has the same size vector, and whose lower cell is child {which} of the lower cell of {N}. */ void dg_tree_pack_split ( dg_dim_t d, dg_grid_size_t psz[], dg_tree_vec_t *N, dg_axis_t i, dg_tree_vec_t *NS ); /* Assumes that {N} is a tree pack at some level {r} of the tree, with size vector {psz[0..d-1]}. Returns in {NS} the tree pack of level {r+1} obtained by splitting every cell of {N} in half. That is, the lower cell of {NS} is the low child of the lower cell of {N}, and the size vector of {NS} size is {psz}, except along axis {i} where it is {2*psz[i]}. */ void dg_tree_pack_check (dg_tree_vec_t *N, dg_dim_t d, dg_grid_size_t psz[], int r); /* Runs some consistency checks on a tree pack {N}. If {psz} is not NULL, checks whether the number of elements agrees with {psz}. Assumes that the pack has dimension {d}, size vector {psz}, and rank {r}. All non-null trees should have the same rank; if {r} is not -1, that common rank must be {r}. */ void dg_tree_pack_print(FILE *wr, dg_dim_t d, dg_grid_size_t psz[], dg_tree_vec_t *N); /* Prints the cells of the nodes in the tree pack {N} to {wr}. NULL nodes are printed as "Ø". */ /* TEMPLATES A /template/ is simply a vector {psz[0..d-1]} of positive integers. An /instance/ of a template in a finite dyadic grid {G} is a cell pack {P} with size {psz[i]} along each axis {i}, whose cells are cells of {G}. The lower cell of the pack is said to /fit/ the template. */ typedef void dg_tree_pack_op_t(dg_tree_vec_t *N, bool_t leaf); /* A procedure called to process a tree pack. The parameter {is_leaf} is TRUE iff one or more of the cells in {N} is a leaf. */ void dg_tree_pack_enum ( dg_dim_t d, dg_tree_t G, dg_grid_size_t psz[], dg_tree_pack_op_t op ); /* Calls {op} on every valid tree pack of {G} that fits the template {psz[0..d-1]}, in top-down fashion. */ #endif