/* take a _node_t, value, and depth (zero means root) */ _node_t *_find(_node_t *o, uint32_t v, size_t d) { if (_is_leaf(o)) { return VALUE(o) == v ? o : NULL; } if (!_has_children(o)) { return NULL; } return _find(_children(o) + _idx8(v, d), v, d + 1); }
void _delete_recursive(_node_t *o) { if (_has_children(o)) { _node_t *children = _children(o); for (size_t i = 0; i < 8; ++i) { _delete_recursive(children + i); } free(children); } }
/* take a _node_t, value, and depth (zero means root) */ _node_t *_insert(_node_t *o, uint32_t v, size_t d) { /* at level 0, shift 21 bits */ /* at level 7, shift 0 bits */ if (_has_children(o)) { SPIT(std::cout); return _insert(CHILDREN(o) + _idx8(v, d), v, d + 1); } if (!_is_leaf(o)) { /* unused _node_t */ _leaf_set(o); _value_set(o, v); return o; } /* else occupied leaf */ if (UINT24(v) == VALUE(o)) { /* same value */ return o; } /* else different value */ _leaf_clear(o); uint32_t w = VALUE(o); // save old value VALUE(o) = 0; // clear value CHILDREN(o) = _children_new(); for (size_t i = 0; i < 8; ++i) { (CHILDREN(o) + i)->parent_ = o; } /* insert old value */ _insert(_children(o) + _idx8(w, d), w, d + 1); /* recurse with given value */ return _insert(_children(o) + _idx8(v, d), v, d + 1); }
static int _weight_recursive(_node_t *o) { if (_is_leaf(o)) { return 1; } if (!_has_children(o)) { return 0; } int acc = 0; for (size_t i = 0; i != 8; ++i) { acc += _weight_recursive(_children(o) + i); } return acc; }
static int _depth_recursive(_node_t *o) { SPIT(std::cout << std::endl); if (_is_leaf(o)) return 0; if (!_has_children(o)) return 0; int acc = 0; for (size_t i = 0; i != 8; ++i) { acc = _imax(acc, _depth_recursive(_children(o) + i)); } return 1 + acc; }
void type_node::activate( fact_handle & fh) { if ( instance_of( fh) ) _children( fh); }
void alpha_memory::activate( tuple_handle & th) { store( th); _children( th); }
static bool _has_children(_node_t *o) { return _validate(_children(o)); }