コード例 #1
0
context_iterator access_shared_context_at_depth(a_access a1, a_access a2, int d)
    {
    assert( access_shared_depth(a1,a2) >= d );

	node *ic;
    for (ic = a1; ic != Entry && node_depth(ic) >= d; ic=ic->nodeparent)
	if (node_depth(ic) == d && it_contains(ic, a2))
	    if (if_branch_op(ic->nodeop))
		return ic;

    assert(ic->nodeop == op_dolimit || ic->nodeop == op_entry);
    assert((int)cont_i_cur_depth(ic) == d);
    return ic;
    }
コード例 #2
0
ファイル: bic_calculator.c プロジェクト: meiao/cte
/*
 * Calculates the Vw and Sw values for a node, siblings and children.
 */
void VwSw(Tree_node* bic_node, double c) {
  if (bic_node == NULL || bic_node->bic_data == NULL) {
    return;
  }
  Tree_node* prob_node = get_prob_node(bic_node);

  // if node has no child, we use the Vw1 value.
  if (node_depth(bic_node) == max_word_size || bic_node->child == NULL) {
    bic_node->bic_data->Sw = 0;
    bic_node->bic_data->Vw = Vw1(bic_node, prob_node, c);
    VwSw(bic_node->sibling, c); // calculate siblings before returning
    return;
  }

  // calculate child, because it is needed for Vw2 calculation.
  VwSw(bic_node->child, c);

  double vw1 = Vw1(bic_node, prob_node, c);
  double vw2 = Vw2(bic_node, c);

  if (vw1 >= vw2) {
    bic_node->bic_data->Sw = 0;
    bic_node->bic_data->Vw = vw1;
  } else {
    bic_node->bic_data->Sw = 1;
    bic_node->bic_data->Vw = vw2;
  }

  // calculate siblings before returning
  VwSw(bic_node->sibling, c);
}
コード例 #3
0
ファイル: bic_calculator.c プロジェクト: meiao/cte
/*
 * Recovers the sufix for the given node
 */
char* recover_sufix(Tree_node* bic_node) {
  int length = node_depth(bic_node);
  char* sufix = (char*) malloc((length+1)* sizeof(char)); // +1 for the \0 terminator

  Tree_node* current_node = bic_node;
  for (int i = 0; i < length; i++) {
    sufix[i] = current_node->symbol;
    current_node = current_node->parent;
  }
  sufix[length] = '\0';
  return sufix;
}
コード例 #4
0
ファイル: rb_tree.cpp プロジェクト: ohtorii/rb_tree
template<class _T> static void proc(){
	_T	t;

	while(! RB_IsEof()){
		char *buf = RB_GetCin();
		t.insert(std::string(buf));
		free(buf);
	}

#if 0
	{
		_T::const_iterator first = t.begin();
		_T::const_iterator last  = t.end();
		_T::const_iterator nil_node = t.end();

		for(; first!=last ; ++first){
			print_space(node_depth(first,nil_node));
			printf("[%s]%s\n", first._Ptr->_Color==set_string_type::_Black?"B":"R", first._Ptr->_Myval.c_str());
		}
	}
#else
	{
		//rb-treeの「left-mostを最下段」「right-mostを最上段」にするため reverse_iterator を使用。
		_T::const_reverse_iterator	first = t.rbegin();
		_T::const_reverse_iterator	last  = t.rend();
		_T::const_iterator			nil_node = t.end();

		for(; first!=last ; ++first){
			//const_reverse_iterator を剥いで中身(const_iterator)を取り出す。
			_T::const_reverse_iterator tmp = first;
			++tmp;
			_T::const_iterator cur = tmp.current;

			print_space(node_depth(cur,nil_node));
			printf("[%s]%s\n", cur._Ptr->_Color==set_string_type::_Black?"B":"R", cur._Ptr->_Myval.c_str());
		}
	}
#endif
	
}
コード例 #5
0
ファイル: bic_calculator.c プロジェクト: meiao/cte
/*
 * Returns the child of the given node which occurred the most.
 * If the depth of the node is max_word_size, then return the node.
 */
Tree_node* most_frequent_child(Tree_node* node) {
  if (node_depth(node) == max_word_size) {
    return node;
  }

  int max = 0;
  Tree_node* max_node;
  Tree_node* current_node = node->child;

  while (current_node != NULL) {
    Tree_node* max_child = most_frequent_child(current_node);
    if (max_child->prob_data != NULL && max_child->prob_data->occurrences > max) {
      max = max_child->prob_data->occurrences;
      max_node = max_child;
    }
    current_node = current_node->sibling;
  }
  return max_node;
}
コード例 #6
0
ファイル: itkey.c プロジェクト: svn2github/iup-iup
int treeNodeCalcPos(Ihandle* h, int *x, int *y, int *text_x)
{
  int err;
  TtreePtr tree=(TtreePtr)tree_data(h);
  Node node = (Node)tree_root(tree);
  float posy = IupGetFloat(h, IUP_POSY);     
  float dy = IupGetFloat(h, IUP_DY);
  float posx = IupGetFloat(h, IUP_POSX);
  float dx = IupGetFloat(h, IUP_DX);

  CdActivate(tree,err);

  *y = (int)((1.0 + posy/dy)*(YmaxCanvas(tree)-TREE_TOP_MARGIN));

  while(node != tree_selected(tree))
  {
    if( node_visible(node) == YES ) *y -= NODE_Y;

    node = node_next(node);
    if (node == NULL)
      return 0;
  }

  *y -= NODE_Y;
  *x = (int)(TREE_LEFT_MARGIN - (XmaxCanvas(tree)-NODE_X)*posx/dx) + NODE_X * node_depth(node);

  /* if node has a text associated to it... */
  *text_x = 0;
  if(node_name(node))
  {
    /* Calculates its dimensions */
    iupdrvStringSize(tree->self, node_name(node), text_x, NULL);
  }

  return 1;
}