コード例 #1
0
ファイル: tower.c プロジェクト: student-t/PSPP
/* Returns the height of the bottom of the given tower NODE.

   The performance of this function is O(lg n) in the number of
   nodes in the tower.  It is often possible to avoid calling
   this function, either by taking advantage of the NODE_START
   parameter to tower_lookup or by incrementally keeping track of
   height while iterating through a tower.  In the former case
   the asymptotic performance is no different, since tower_lookup
   is also O(lg n), but in the latter case performance improves
   from O(lg n) to O(1). */
unsigned long int
tower_node_get_level (const struct tower_node *node)
{
  const struct abt_node *p = &node->abt_node;
  unsigned long level = get_subtree_size (p->down[0]);
  while (p->up != NULL) 
    {
      if (p == p->up->down[1])
        level += (get_subtree_size (p->up->down[0]) 
                  + abt_to_tower_node (p->up)->size);
      p = p->up;
    }
  return level;
}
コード例 #2
0
ファイル: KMCentersNodeSplit.cpp プロジェクト: salilab/imp
KMPoint KMCentersNodeSplit::sample_center() {
  int r = internal::random_int(get_subtree_size());
  if (r == 0) {                                // sample from this node
    KMRectangle exp_box = bnd_box_.expand(3);  // compute 3x expanded box
    return exp_box.sample();
  } else if (r <= children_[0]->get_subtree_size()) {  // sample from left
    return children_[0]->sample_center();
  } else {  // sample from right subtree
    return children_[1]->sample_center();
  }
}
コード例 #3
0
ファイル: tower.c プロジェクト: student-t/PSPP
/* Returns the total height of tower T. */
unsigned long
tower_height (const struct tower *t)
{
  return get_subtree_size (t->abt.root);
}