예제 #1
0
파일: soctree.c 프로젝트: rubicks/soctree
/* 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);
}
예제 #2
0
파일: soctree.c 프로젝트: rubicks/soctree
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);
  }
}
예제 #3
0
파일: soctree.c 프로젝트: rubicks/soctree
/* 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);
}
예제 #4
0
파일: soctree.c 프로젝트: rubicks/soctree
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;
}
예제 #5
0
파일: soctree.c 프로젝트: rubicks/soctree
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;
}
예제 #6
0
void
type_node::activate( fact_handle & fh) {
    if ( instance_of( fh) ) _children( fh);
}
예제 #7
0
void 
alpha_memory::activate( tuple_handle & th) { 
	store( th); 
	_children( th);
}
예제 #8
0
파일: soctree.c 프로젝트: rubicks/soctree
static bool _has_children(_node_t *o) { return _validate(_children(o)); }