示例#1
0
AVL*  check_and_rorate(AVL * rnode, AVL* parent) {
	AVL * rret = rnode;
	if (rnode == NULL)
		return;
	if (rnode->height >= 2) { 
		//left tree height than right
		if(rnode->lchild != NULL 
			&& rnode->lchild->lchild != NULL) {
			rret = LL_Rotate(rnode);
		} else if(rnode->lchild != NULL 
			&& rnode->lchild->rchild != NULL) {
			rret = LR_Rotate(rnode);
		}

		if (parent != NULL) {
			set_parent(rret, rnode, parent);
		}
		
	} else if (rnode->height <= -2) {
		//right tree height than left
		if (rnode->rchild != NULL 
			&& rnode->rchild->rchild != NULL) {
			rret = RR_Rotate(rnode);
		} else if (rnode->rchild != NULL
			&& rnode->rchild->lchild != NULL) {
			rret = RL_Rotate(rnode);
		}
		if (parent != NULL) {
			set_parent(rret, rnode, parent);
		}
	}
	return rret;
}
示例#2
0
void
rbtree_rotate(rbtree_t      *tree,
              rbtree_node_t *node,
              int           left)
{
  rbtree_node_t *tmp    = node->child[left];
  rbtree_node_t *parent = get_parent(node);

  node->child[left] = tmp->child[!left];
  if(tmp->child[!left] != NULL)
    set_parent(tmp->child[!left], node);

  tmp->child[!left] = node;
  set_parent(tmp, parent);
  if(parent != NULL)
  {
    if(node == parent->child[!left])
      parent->child[!left] = tmp;
    else
      parent->child[left] = tmp;
  }
  else
    tree->root = tmp;
  set_parent(node, tmp);
}
示例#3
0
static void rotate_left(struct rbtree_node* node,struct rbtree* tree)
{
    struct rbtree_node* p = node;
    struct rbtree_node* q = node->right;
    struct rbtree_node* parent = node->parent;
    if(parent == NULL)
    {
        tree->root = q;
    }
    else
    {
        if(parent->left == p)
            parent->left = q;
        else
            parent->right = q;
    }
    set_parent(parent,q);
    set_parent(q,p);

    p->right = q->left;
    if(q->left)
        set_parent(p,q->left);
    q->left = p;

}
示例#4
0
static void rotate_right(struct FwAvlNode* node, struct FwAvlTree* tree)
{
    struct FwAvlNode* p = node;
    struct FwAvlNode* q = node->left;
    struct FwAvlNode* parent = get_parent(node);

    if(!is_root(p))
    {
        if(parent->left == p)
            parent->left = q;
        else
            parent->right = q;
    }
    else
    {
        tree->root = q;
    }

    set_parent(parent, q);
    set_parent(q, p);

    p->left = q->right;
    if(p->left != NULL)
    {
        set_parent(p, p->left);
    }
    q->right = p;
}
示例#5
0
	Board(Board *b) 
	{
	
		//  Allocate board memory
		board.resize(BOARD_SIZE);
		for (int i = 0; i < BOARD_SIZE; ++i) {
			for (int j = 0; j < BOARD_SIZE; ++j) {
				board[i].push_back(NULL);
			}
		}
		
		//  Initialize board to match argument board.
		for (int i = 0; i < BOARD_SIZE; ++i) {
			for (int j = 0; j < BOARD_SIZE; ++j) {
				set_piece(i, j, b->get_piece(i, j));
			}
		}
		
		//  Set parent board.
		set_parent(b);
		
		//  Set player move of current board.
		turn = !b->get_player();
			
	}
/** Recursively cycles through all the left and right children setting their node_parent as the TreeNode before
 @param child is a pointer to the TreeNode object being cycled through and having each parent TreeNode set
 */
void BinarySearchTree::set_parent(TreeNode* child) {
    //if TreeNode pointer is nullptr, then cannot continue to set node_parent in that direction
    if(child == nullptr) {
        return;
    }
    //if left child is not nullptr, continue in the left direction
    if(child->left != nullptr) {
        child->left->node_parent = child;
        set_parent(child->left);
    }
    //if right child is not nullptr, continue in the right direction
    if(child->right != nullptr) {
        child->right->node_parent = child;
        set_parent(child->right);
    }
}
示例#7
0
MuContainer*
mu_container_append_siblings (MuContainer *c, MuContainer *sibling)
{
	g_assert (c);

	g_return_val_if_fail (c, NULL);
	g_return_val_if_fail (sibling, NULL);
	g_return_val_if_fail (c != sibling, NULL);

	/* assert_no_duplicates (c); */

	set_parent (sibling, c->parent);

	/* find the last sibling and append; first we try our cache
	 * 'last', otherwise we need to walk the chain. We use a
	 * cached last as to avoid walking the chain (which is
	 * O(n*n)) */
	if (c->last)
		c->last->next = sibling;
	else {
		/* no 'last' cached, so walk the chain */
		MuContainer *c2;
		for (c2 = c; c2 && c2->next; c2 = c2->next);
		c2->next = sibling;
	}
	/* update the cached last */
	c->last = sibling->last ? sibling->last : sibling;

	/* assert_no_duplicates (c); */

	return c;
}
示例#8
0
void
SgAsmPERVASizePair::ctor(SgAsmPERVASizePairList *parent, rose_addr_t rva, rose_addr_t size)
{
    p_e_rva = rva;
    p_e_size = size;
    set_parent(parent);
}
示例#9
0
void MultiGrid::element_created(TElem* elem, TParent* pParent,
								TElem* pReplaceMe)
{
	UG_ASSERT(pReplaceMe, "Only call this method with a valid element which shall be replaced.");
	int level = get_level(pReplaceMe);

//	register parent and child
	set_parent(elem, pParent);

	if(pParent)
	{
	//	add the element to the parents children list
	//	pParent should have an info object at this time!
		typename mginfo_traits<TParent>::info_type& parentInfo = get_info(pParent);
		parentInfo.replace_child(elem, pReplaceMe);
	}

//	put the element into the hierarchy
	level_required(level);
	m_hierarchy.assign_subset(elem, level);

//	explicitly copy the parent-type from pReplaceMe to the new vrt.
//	This has to be done explicitly since a parent may not exist locally in
//	a parallel environment.
	set_parent_type(elem, parent_type(pReplaceMe));
}
示例#10
0
void MultiGrid::element_created(TElem* elem, TParent* pParent)
{
//	if hierarchical_insertion is enabled, the element will be put
//	into the next higher level of pParents level.

	int level = 0;
	if(pParent)
	{
	//	the element is inserted into a new layer.
		level = get_level(pParent) + 1;
		set_parent_type(elem, pParent->base_object_id());
	}
	else
		set_parent_type(elem, -1);

//	register parent and child
	//typename mginfo_traits<TElem>::info_type& info = get_info(elem);
	//info.m_pParent = pParent;
	set_parent(elem, pParent);
	if(pParent)
	{
	//	make sure that the parent has an info object
		create_child_info(pParent);

	//	add the element to the parents children list
		typename mginfo_traits<TParent>::info_type& parentInfo = get_info(pParent);
		parentInfo.add_child(elem);
	}

//	put the element into the hierarchy
	level_required(level);
	m_hierarchy.assign_subset(elem, level);
}
示例#11
0
文件: config.cpp 项目: gobby/sobby
Sobby::Config::ParentEntry& Sobby::Config::ParentEntry::
	operator[](const Glib::ustring& name)
{
	ParentEntry* entry = get_parent_child(name);
	if(entry != NULL) return *entry;
	return set_parent(name);
}
示例#12
0
// Set up the gadget and registers it with the UI window
//
void UI_GADGET::base_create(UI_WINDOW *wnd, int _kind, int _x, int _y, int _w, int _h)
{
	int i;

	// initialize data with passed values
	kind = _kind;
	x = _x;
	y = _y;
	w = _w;
	h = _h;

	// set up reference to UI window and initialize as having no family
	my_wnd = wnd;
	parent = NULL;
	children = NULL;
	next = prev = this;

	// this actually links the gadget into the UI window's top level family (as the youngest gadget)
	set_parent(NULL);

	// initialize variables
	hotkey = -1;
	user_function = NULL;
	disabled_flag = 0;
	base_dragging = 0;
	base_drag_x = base_drag_y = 0;
	hotspot_num = -1;
	hidden = 0;
	linked_to_hotspot = 0;
	uses_bmaps = 0;
	m_num_frames = 0;
	for ( i=0; i<MAX_BMAPS_PER_GADGET; i++ ) {
		bmap_ids[i] = -1;
	}
}
示例#13
0
/** Non-parsing constructor */
void
SgAsmElfEHFrameEntryFD::ctor(SgAsmElfEHFrameEntryCI *cie)
{
    ROSE_ASSERT(cie->get_fd_entries()!=NULL);
    cie->get_fd_entries()->get_entries().push_back(this);
    ROSE_ASSERT(cie->get_fd_entries()->get_entries().size()>0);
    set_parent(cie->get_fd_entries());
}
示例#14
0
LocalContext::LocalContext(Table *parent, Function *f) 
  : Table(parent,SREL,0),m_function(f), m_no_auto_dtor(false)
{
    m_type = FUNCTION;
    set_mem_unit(4);     // we work in DWORDS
    set_dword_align(4);  // *fix 1.2.3 Local contexts have 32-bit alignment _explicitly_
    set_parent(parent);
}
J_PXC_Color_Stream_Processor::J_PXC_Color_Stream_Processor(J_PXC_Stream_Shared_t i_stream){
#ifndef VS_2013
	default_initialization();
#endif //!VS_2013
	M_width = i_stream->width();
	M_height = i_stream->height();
	set_parent(i_stream);
}
示例#16
0
/*
  Duplicates the currently running process
  The two copies are identical except for the child having a new pid
*/
int
sys_fork(struct trapframe *tf, int32_t *retval) {

  // Prevent interrupts so address space doesn't change before getting
  // copied
  int spl = splhigh();

  // Store trapframe on the heap for copying to child
  // thread later
  struct trapframe *child_tf;
  child_tf = kmalloc(sizeof(tf));
  if (child_tf == NULL) {
    splx(spl);
    return ENOMEM;
  }

  //memcpy(child_tf, tf, sizeof(tf));
  child_tf = tf;

  // Copy parent address space
  struct addrspace *original_as;
  struct addrspace *new_as;
  original_as = curproc_getas();
  int result = as_copy(original_as, &new_as);
  if (result) {
    splx(spl);
    return ENOMEM;
  }

  // Create new process
  struct proc *new_proc = proc_create(curproc->p_name);

  // Copy process fdlist
  for (int i = 0; i < __OPEN_MAX; i++) {
    if (curproc->p_fdlist[i] != NULL) {
      new_proc->p_fdlist[i] = curproc->p_fdlist[i];
      // Increment reference count
      new_proc->p_fdlist[i]->fd_vfile->vn_refcount++;
    }
  }

  //Child process needs to have parent pid attached to it
  set_parent(curproc->pid, new_proc->pid);

  // Fork new thread, attach to new proc
  result = thread_fork("Child process", new_proc, enter_forked_process, (void *)child_tf, (unsigned long)new_as);
  if (result) {
    kfree(child_tf);
    splx(spl);
    return result;  // Error code will be returned from thread_fork
  }

  // Set retval to child process pid
  *retval = new_proc->pid;
  splx(spl);
  return 0;
}
示例#17
0
文件: stage.cpp 项目: aonorin/KGLT
ParticleSystemID Stage::new_particle_system_with_parent_from_file(ActorID parent, const unicode& filename, bool destroy_on_completion) {
    ParticleSystemID new_id = new_particle_system();

    auto ps = particle_system(new_id);
    ps->set_parent(parent);
    ps->set_destroy_on_completion(destroy_on_completion);

    window->loader_for(filename)->into(ps);

    return new_id;
}
示例#18
0
inline StringIndex::StringIndex(ref_type ref, ArrayParent* parent, size_t ndx_in_parent,
                                ColumnBase* target_column,
                                bool deny_duplicate_values, Allocator& alloc):
    m_array(new Array(alloc)),
    m_target_column(target_column),
    m_deny_duplicate_values(deny_duplicate_values)
{
    REALM_ASSERT_EX(Array::get_context_flag_from_header(alloc.translate(ref)), ref, size_t(alloc.translate(ref)));
    m_array->init_from_ref(ref);
    set_parent(parent, ndx_in_parent);
}
示例#19
0
/** Non-parsing constructor */
void
SgAsmElfEHFrameEntryCI::ctor(SgAsmElfEHFrameSection *ehframe)
{
    ROSE_ASSERT(ehframe->get_ci_entries()!=NULL);
    ehframe->get_ci_entries()->get_entries().push_back(this);
    ROSE_ASSERT(ehframe->get_ci_entries()->get_entries().size()>0);
    set_parent(ehframe->get_ci_entries());

    p_fd_entries = new SgAsmElfEHFrameEntryFDList;
    p_fd_entries->set_parent(this);
}
示例#20
0
文件: ElfNote.C 项目: KurSh/rose
/** Constructor adds the new note to the list of notes for the note section. */
void
SgAsmElfNoteEntry::ctor(SgAsmElfNoteSection *section)
{
    ROSE_ASSERT(section->get_entries()!=NULL);
    section->get_entries()->get_entries().push_back(this);
    ROSE_ASSERT(section->get_entries()->get_entries().size()>0);
    set_parent(section->get_entries());

    p_name = new SgAsmBasicString("");
    p_name->set_parent(this);
}
示例#21
0
bin_tree_node<Item>& bin_tree_node<Item>::operator=(bin_tree_node<Item>& rhs)
{
	if(&rhs == this)
		return *this;

	set_data(rhs.get_data());
	set_lchild(DsNULL);
	set_rchild(DsNULL);
	set_parent(DsNULL);
	
	return *this;
};
示例#22
0
static void rotate_right(struct rbtree_node *node, struct rbtree *tree)
{
    struct rbtree_node *p = node;
    struct rbtree_node *q = node->left; /* can't be NULL */
    struct rbtree_node *parent = get_parent(p);

    if (!is_root(p)) {
        if (parent->left == p)
            parent->left = q;
        else
            parent->right = q;
    } else
        tree->root = q;
    set_parent(parent, q);
    set_parent(q, p);

    p->left = q->right;
    if (p->left)
        set_parent(p, p->left);
    q->right = p;
}
示例#23
0
文件: avl.c 项目: kuzmas/anytree
void avltree_replace(struct avltree_node *old, struct avltree_node *node, struct avltree *tree)
{
    struct avltree_node *parent = get_parent(old);

    if (parent)
        set_child(node, parent, parent->left == old);
    else
        tree->root = node;

    if (old->left)
        set_parent(node, old->left);
    if (old->right)
        set_parent(node, old->right);

    if (tree->first == old)
        tree->first = node;
    if (tree->last == old)
        tree->last = node;

    *node = *old;
}
 /** parent_ remains left child.  Newly constructed object is right child. */
 start_for( start_for& parent_, const Range& r, depth_t d ) :
     my_range(r),
     my_body(parent_.my_body),
     my_partition(parent_.my_partition, tbb::split()),
     m_executedBegin(0), m_executedEnd(0), m_firstTimeRun(true),
     m_joinedBegin(/* grows left */ r.end()), m_joinedEnd(r.end()),
     m_tree(parent_.m_tree)
 {
     set_parent(parent_.parent());
     my_partition.set_affinity(*this);
     my_partition.align_depth( d );
 }
示例#25
0
文件: SID_plots.cpp 项目: MikoG/SID
sid::plots::plots(object* objParent) :
m_blHasWater(false) {
    
    set_parent(objParent);
    for (int i=0; i< CHUNK_SIZE; i++) {
        __m_plots[i] = new plot();
        std::string str = "Plot";
        //__m_plots[i]->set_name(str);
        __m_plots[i]->set_parent(this);
    }
    this->set_select_delegate(new select_3Drect());
}
示例#26
0
static void rotate_right(h_rbtree_st *tree, rbtree_node_st *node)
{
    rbtree_node_st *p = node;
    rbtree_node_st *q = node->left; /* can't be NULL */
    rbtree_node_st *parent = get_parent(p);

    if (!is_root(p)) {
        if (parent->left == p)
            parent->left = q;
        else
            parent->right = q;
    } else
        tree->root = q;
    set_parent(parent, q);
    set_parent(q, p);

    p->left = q->right;
    if (p->left)
        set_parent(p, p->left);
    q->right = p;
}
示例#27
0
	void on_set_parent(viewport::control& Viewport, const GdkEventButton& Event)
	{
		const k3d::selection::record selection = Viewport.pick_node(k3d::point2(Event.x, Event.y));
		if(selection.empty())
			return;

		k3d::inode* const node = k3d::selection::get_node(selection);
		if(!node)
			return;

		set_parent(Viewport, *node);

	}
示例#28
0
void
Lpatch::get_parent_patch(TAGformat &d) 
{

	int parent_index;
	*d >> parent_index;
	
	if (parent_index == -1)
		_parent = nullptr;
	else if(set_parent(lmesh()->parent_mesh()->patch(parent_index)) != true)
		_parent = nullptr;
	
}
示例#29
0
void rblist::right_rotate(void *item)
{
   void *x, *y;

   y = item;
   x = left(y);
   set_left(y, right(x));
   if (right(x)) {
      set_parent(right(x), y);
   }
   set_parent(x, parent(y));
   /* if no parent then we have a new head */
   if (!parent(y)) {
      head = x;
   } else if (y == left(parent(y))) {
      set_left(parent(y), x);
   } else {
      set_right(parent(y), x);
   }
   set_right(x, y);
   set_parent(y, x);
}
示例#30
0
文件: stage.cpp 项目: aonorin/KGLT
LightID Stage::new_light(Object &parent, LightType type) {
    LightID lid = LightManager::manager_new();

    {
        auto l = light(lid);
        l->set_type(type);
        l->set_parent(&parent);
    }

    signal_light_created_(lid);

    return lid;
}