#include #include "rkdnode.h" /** * Update element count ("elem_count" field) of a node */ static void rkdnode_update_elem_count(rkdnode_t *node) { node->elem_count = 1; if ( node->L ) node->elem_count += node->L->elem_count; if ( node->R ) node->elem_count += node->R->elem_count; } /** * Set left child of a node */ void rkdnode_set_l_child(rkdnode_t *N, rkdnode_t *L) { N->L = L; rkdnode_update_elem_count(N); } /** * Set right child of a node */ void rkdnode_set_r_child(rkdnode_t *N, rkdnode_t *R) { N->R = R; rkdnode_update_elem_count(N); } /** * Set L and R children of a node */ void rkdnode_set_children(rkdnode_t *N, rkdnode_t *L, rkdnode_t *R) { N->L = L; N->R = R; rkdnode_update_elem_count(N); } /** * Create a new node */ rkdnode_t *rkdnode_new(unsigned int dim, int *key, void *data) { int i; rkdnode_t *node = malloc(sizeof(rkdnode_t)); /* Set key */ node->key = malloc(sizeof(int)*dim); for(i=0;ikey[i] = key[i]; node->elem_count = 1; node->dim = dim; node->data = data; node->disc = random() % dim; node->L = NULL; node->R = NULL; return node; } /** * Free a node * FIXME: What to do with data field ? */ void rkdnode_free(rkdnode_t *N) { if ( N == NULL ) return; free(N->key); free(N); }