Beispiel #1
0
int max_height( tree * t )
{
  if( t == NULL )
    return 0;
  else
    return 1 + MAX( max_height( (*t).left ), max_height( (*t).right ) );
}
Beispiel #2
0
uint32_t		min_height(t_set_h const *node)
{
	uint32_t const	left = node->left ? max_height(node->left) : 0;
	uint32_t const	right = node->right ? max_height(node->right) : 0;

	return (MIN(left, right) + 1);
}
int max_height(struct btree *root)
{
	if(root == NULL)
		return 0;
	else
		return 1 + max(max_height(root->left),max_height(root->right));

}
Beispiel #4
0
ExprNAryOp::ExprNAryOp(const Array<const ExprNode>& _args, const Dim& dim) :
		ExprNode(max_height(_args)+1, nary_size(_args), dim),
		args(_args), nb_args(_args.size()) {

	for (int i=0; i<nb_args; i++) {
		((ExprNode&) args[i]).fathers.add(*this);
	}
}
Beispiel #5
0
ExprNAryOp::ExprNAryOp(const ExprNode** _args, int n, const Dim& dim) :
		ExprNode(max_height(_args,n)+1, nary_size(_args,n), dim), nb_args(n) {

	args = new const ExprNode*[n];
	for (int i=0; i<n; i++) {
		args[i]=_args[i];
		((ExprNode&) *args[i]).fathers.add(*this);
	}
}
Beispiel #6
0
ExprBinaryOp::ExprBinaryOp(const ExprNode& left, const ExprNode& right, const Dim& dim) :
		ExprNode(	max_height(left,right)+1,
					bin_size(left,right),
					dim ),
		left(left), right(right) {

	((ExprNode&) left).fathers.add(*this);
	((ExprNode&) right).fathers.add(*this);
}
Beispiel #7
0
ExprNAryOp::ExprNAryOp(const ExprNode** _args, int n, const Dim& dim) :
		ExprNode(max_height(_args,n)+1, nary_size(_args,n), dim), nb_args(n) {

	args = new const ExprNode*[n];
	for (int i=0; i<n; i++) {
		args[i]=_args[i];
		((ExprNode*&) args[i]->father)=this;
	}
}
Beispiel #8
0
ExprBinaryOp::ExprBinaryOp(const ExprNode& left, const ExprNode& right, const Dim& dim) :
		ExprNode(	max_height(left,right)+1,
					bin_size(left,right),
					dim ),
		left(left), right(right) {

	((ExprNode*&) left.father)=this;
	((ExprNode*&) right.father)=this;
}
void print_level_order(struct btree *root)
{
	int height = max_height(root);
	int i;
	for(i=1;i<=height;i++)
	{
		print_level(root,i);
		printf("\n");
	}
}
Beispiel #10
0
void is_balanced( tree * t )
{
  int m, mm;
  m = max_height( t );
  mm = min_height( t );
  printf("m = %d, mm = %d\n", m, mm);
  if( m - mm <= 1 )
    printf("balanced\n");
  else
    printf("unbalanced\n");
}
Beispiel #11
0
/* This function is used to find the height of a tree or sub-tree */
int max_height(text_t *txt) 
{
	int ldepth, rdepth;
	if (txt->right == NULL) 
	{
		return 0;
	}
   	else
   	{
   		ldepth = max_height(txt->left);
       		rdepth = max_height(txt->right);
       		if (ldepth < rdepth) 
		{
           		return (rdepth+1);
       		}
		else
		{ 
			return (ldepth+1);
   		}
	}
} 
Beispiel #12
0
void UIContext::set_debugger_size(const Size2i& dims)
{
  if( this->valid() ) {

    Rocket::Core::ElementDocument* target =
      this->context()->GetDocument("rkt-debug-hook");

    NOM_ASSERT( target != nullptr );
    if( target ) {
      // NOM_DUMP( target->GetSourceURL().CString() );

      Rocket::Core::Element* body_tag =
        target->GetParentNode();

      NOM_ASSERT( body_tag != nullptr );
      if( body_tag ) {

        // Sets width of visual debugger's Element Info window
        Rocket::Core::Element* info =
          body_tag->GetElementById("rkt-debug-info");

        NOM_ASSERT( info != nullptr );
        if( info ) {

          Rocket::Core::Property width(dims.w, Rocket::Core::Property::PX);
          info->SetProperty("min-width", width);
          info->SetProperty("width", width);
        } // end if info

        // Sets height of visual debugger's Element Info window
        Rocket::Core::Element* content =
          body_tag->GetElementById("content");

        NOM_ASSERT( content != nullptr );
        if( content ) {

          // As per Rocket/Debugger/MenuSource.h
          // int menu_height = 32;

          // Maximum height shall be no more than half the size of the context,
          // add menu height
          Rocket::Core::Property max_height(  dims.h,
                                              Rocket::Core::Property::PX);
          content->SetProperty("max-height", max_height);
        } // end if debug_content

      } // end if body_tag
    } // end if target
  } // end if valid context
}
Beispiel #13
0
int				main(void)
{
	t_set			set;
	t_test *const	nodes = NEW_N(t_test, TEST_SIZE);

	set = SET(&test_cmp, 0);

	{
		uint32_t		i;
		uint32_t		occur;

		i = 0;
		while (i < TEST_SIZE)
		{
			nodes[i] = TEST(ft_rand(-TEST_SIZE/2, TEST_SIZE/2));
			occur = count_occur(&set, nodes[i].key);
			ft_set_insert(&set, &nodes[i], &nodes[i].key);
			ASSERT(occur == count_occur(&set, nodes[i].key) - 1, "INSERT ERROR");
			i++;
		}
	}

	ASSERT(test_order_count(&set) == TEST_SIZE, "COUNT ERROR");
	test_get(&set);
	test_begin(&set);
	ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR");
	TRACE("INSERT OK");

	t_vec2u			range;

	range.x = ft_rand(0, TEST_SIZE / 2);
	range.y = ft_rand(TEST_SIZE / 2, TEST_SIZE);

	{
		uint32_t		i;
		uint32_t		occur;

		i = range.x;
		while (i < range.y)
		{
			occur = count_occur(&set, nodes[i].key);
			ft_set_remove(&set, &nodes[i]);
			ASSERT(occur == count_occur(&set, nodes[i].key) + 1, "REMOVE ERROR");
			i++;
		}
	}

	test_order_count(&set);
	test_get(&set);
	test_begin(&set);
	ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR");
	TRACE("REMOVE OK");

	{
		uint32_t		i;

		i = range.y;
		while (--i >= range.x)
		{
			nodes[i].key = range.x;
			ft_set_insert(&set, &nodes[i], &nodes[i].key);
		}
	}

	test_order_count(&set);
	test_get(&set);
	test_begin(&set);
	ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR");
	TRACE("INSERT REV SORTED OK");

	{
		uint32_t		i;

		i = 0;
		while (i < TEST_SIZE)
		{
			ft_set_remove(&set, &nodes[0]);
			nodes[0].key = i;
			ft_set_insert(&set, &nodes[0], &nodes[0].key);
			i++;
		}
	}

	test_order_count(&set);
	test_get(&set);
	test_begin(&set);
	ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR");
	TRACE("INSERT SORTED OK");

	{

#define DUP_COUNT		100000

		uint32_t		i;
		t_test			*before;
		t_test			*tmp;
		t_test *const	insert = NEW_N(t_test, DUP_COUNT);

		before = ft_set_get(&set, &nodes[ft_rand(0, TEST_SIZE - 1)].key);

		i = 0;
		while (i < DUP_COUNT)
		{
			while ((tmp = ft_set_prev(before)) != NULL && tmp->key == before->key)
				before = tmp;
			insert[i] = TEST(before->key - 1);
			ft_set_insert_before(&set, &insert[i], before);
			tmp = ft_set_prev(before);
			ASSERT(tmp == &insert[i], "INSERT_BEFORE (prev) ERROR");
			tmp = ft_set_next(&insert[i]);
			ASSERT(tmp == before, "INSERT_BEFORE (next) ERROR");
			before = &insert[i];
			i++;
		}

	}

	test_order_count(&set);
	test_get(&set);
	test_begin(&set);
	ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR");
	TRACE("INSERT_BEFORE OK");

	// print_tree(set.root);
	// print_iter(&set);

	return (0);
}