当前位置: 首页>>代码示例>>C++>>正文


C++ rb_insert函数代码示例

本文整理汇总了C++中rb_insert函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_insert函数的具体用法?C++ rb_insert怎么用?C++ rb_insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rb_insert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rb

void rb() {
    printf(">> RB\n");
    rb_tree_t tree;
    rb_init(&tree, NULL);

    test_rb_t a = { 1 };
    test_rb_t b = { 2 };
    test_rb_t c = { 3 };

    rb_insert(&tree, &a.node, &test_rb_compare);
    rb_insert(&tree, &b.node, &test_rb_compare);
    rb_insert(&tree, &c.node, &test_rb_compare);

    // Display them
    rb_node_t *node = rb_head(&tree);
    while (node) {
        rb_node_t *next = rb_next(node);
        rb_node_t *prev = rb_prev(node);
        test_rb_t *c = rb_ref(node, test_rb_t, node);
        test_rb_t *n = next ? rb_ref(next, test_rb_t, node) : NULL;
        test_rb_t *p = prev ? rb_ref(prev, test_rb_t, node) : NULL;
        printf("current: %d, next: %d, prev: %d\n",
                c->number,
                n ? n->number : -1,
                p ? p->number : -1);
        node = next;
    }
}
开发者ID:pikhq,项目名称:libintrusive,代码行数:28,代码来源:example.c

示例2: color_flip

struct rbtree *rb_insert(struct rbtree *tree, struct rbtree *node)
{
    node->left = node->right = NULL;
    node->red = false;

    if (!tree) {
        node->red = true;
        return node;
    }

    if (is_red(tree->left) && is_red(tree->right))
        color_flip(tree);

    if (node->key < tree->key)
        tree->left = rb_insert(tree->left, node);
    else
        tree->right = rb_insert(tree->right, node);

    if (is_red(tree->right))
        tree = rotate_left(tree);

    if (is_red(tree->left) && is_red(tree->left->left))
        tree = rotate_right(tree);

    return tree;
}
开发者ID:coskifu,项目名称:syslinux,代码行数:26,代码来源:rbtree.c

示例3: insert_CLRS

void insert_CLRS(NODE * t, int v)
{
	if (dbg_level == 0) {
		fprintf(stderr, "%s%d%s, ", GREEN, v, NOCOLOR);
		rb_insert(t, alloc_node(v, R));
		verify_rbtree(t->L, 0);
	} else {
		printf("%sinsert %d%s\n", GREEN, v, NOCOLOR);
		rb_insert(t, alloc_node(v, R));
		______________________________("./fig/", t, t, "inserted %d", v);
	}
}
开发者ID:morining,项目名称:forrest,代码行数:12,代码来源:red.black.tree.c

示例4: free

/* If hk==NULL to register, new is attempted to be created. */
WHook *mainloop_register_hook(const char *name, WHook *hk)
{
    char *nnm;
    
    if(hk==NULL)
        return NULL;
    
    if(named_hooks==NULL){
        named_hooks=make_rb();
        if(named_hooks==NULL)
            return NULL;
    }
    
    nnm=scopy(name);
    
    if(nnm==NULL)
        return NULL;
    
    if(!rb_insert(named_hooks, nnm, hk)){
        free(nnm);
        destroy_obj((Obj*)hk);
    }
    
    return hk;
}
开发者ID:JoeNotCharles,项目名称:notion,代码行数:26,代码来源:hooks.c

示例5: m_insert_right

static void m_insert_right(MTrace * m, void * pdata){
    rb_insert(m->rb2, pdata);
    m->cnt2 += 1;
    if ((m->right_min && m->cmp_fn(pdata, m->right_min) < 0) || (!m->right_min)){
        m->right_min = pdata;
    }
}
开发者ID:elvinxiao,项目名称:dml,代码行数:7,代码来源:median.c

示例6: m_insert_left

static void m_insert_left(MTrace * m, void *pdata){
    rb_insert(m->rb1, pdata);
    m->cnt1 += 1;
    if ((m->left_max && m->cmp_fn(pdata, m->left_max) > 0) || (!m->left_max)){
        m->left_max = pdata;
    }
}
开发者ID:elvinxiao,项目名称:dml,代码行数:7,代码来源:median.c

示例7: stringstore_alloc_n

StringId stringstore_alloc_n(const char *str, uint l)
{
    Rb_node node=(Rb_node)stringstore_find_n(str, l);
    char *s;
    
    if(node!=NULL){
        node->v.ival++;
        return node;
    }
    
    if(stringstore==NULL){
        stringstore=make_rb();
        if(stringstore==NULL)
            return STRINGID_NONE;
    }
    
    s=scopyn(str, l);
    
    if(s==NULL)
        return STRINGID_NONE;
    
    node=rb_insert(stringstore, s, NULL);
    
    if(node==NULL)
        return STRINGID_NONE;
    
    node->v.ival=1;
        
    return (StringId)node;
}
开发者ID:jsbackus,项目名称:notion,代码行数:30,代码来源:stringstore.c

示例8: vmm_ld_mapped

BOOL vmm_ld_mapped(struct pm_task *task, UINT32 vlow, UINT32 vhigh)
{
    struct vmm_memory_region *mreg = NULL;

    // I'll only create a memory region for LD on the task..
    // I won't check collitions because this is always the first lib loaded.
    mreg = kmalloc(sizeof(struct vmm_memory_region));

    if(!mreg) return FALSE;

    if(!rb_free_value(&task->vmm_info.regions_id, &mreg->tsk_id_node.value))
	{
		kfree(mreg);
		return FALSE;
	}

    mreg->owner_task = task->id;
    mreg->next = mreg->prev = NULL;
	mreg->tsk_node.high = TRANSLATE_ADDR(vhigh, UINT32);
	mreg->tsk_node.low = TRANSLATE_ADDR(vlow, UINT32);
	mreg->flags = VMM_MEM_REGION_FLAG_NONE;
	mreg->type = VMM_MEMREGION_LIB;
    mreg->descriptor = NULL;

    ma_insert(&task->vmm_info.regions, &mreg->tsk_node);
    rb_insert(&task->vmm_info.regions_id, &mreg->tsk_id_node, FALSE);

    return TRUE;
}
开发者ID:ahamid,项目名称:sartoris,代码行数:29,代码来源:vmm_shared_libs.c

示例9: main

int
main(void)
{
	rbt root;
	int i;
	int key[] = { 1, 2, 4, 5, 7, 8, 11, 14, 15, 39, 29, 73, 24, 18, 18, 18, 18};
	int key2[] = {15, 14, 11, 8, 7, 5, 4, 2, 1, 18, 73, 24, 39, 29, 18, 18, 18};
	/*int key[] = {41, 38, 31, 12, 19, 8};
	int key2[] = { 8, 12, 19, 31, 38, 41};*/
	rbn nil = { BLACK, 0, NULL, NULL, NULL};
	root.nil = &nil;
	root.root = &nil;
	rbn *tmp;
	for (i = 0; i < sizeof(key2) / sizeof(int); i++) {
		tmp = malloc(sizeof(rbn));
		tmp->key = key2[i];
		rb_insert(&root, tmp);
		printf("insert:%d\n", tmp->key);
	}
	for (i = 0; i < sizeof(key) / sizeof(int); i++) {
		tmp = rb_search(root.root, key[i]);
		rb_delete(&root, tmp);
		printf("deleted:%d\n", tmp->key);
	}
	printf("\n");
	return 0;
}
开发者ID:LinuxKernelDevelopment,项目名称:ITA,代码行数:27,代码来源:main.c

示例10: plist_add

/* Add a file to the list. Return the index of the item. */
int plist_add (struct plist *plist, const char *file_name)
{
	assert (plist != NULL);
	assert (plist->items != NULL);

	if (plist->allocated == plist->num) {
		plist->allocated *= 2;
		plist->items = (struct plist_item *)xrealloc (plist->items,
				sizeof(struct plist_item) * plist->allocated);
	}

	plist->items[plist->num].file = xstrdup (file_name);
	plist->items[plist->num].type = file_name ? file_type (file_name)
		: F_OTHER;
	plist->items[plist->num].deleted = 0;
	plist->items[plist->num].title_file = NULL;
	plist->items[plist->num].title_tags = NULL;
	plist->items[plist->num].tags = NULL;
	plist->items[plist->num].mtime = (file_name ? get_mtime(file_name)
			: (time_t)-1);
	plist->items[plist->num].queue_pos = 0;

	if (file_name) {
		rb_delete (plist->search_tree, file_name);
		rb_insert (plist->search_tree, (void *)(intptr_t)plist->num);
	}

	plist->num++;
	plist->not_deleted++;

	return plist->num - 1;
}
开发者ID:jonsafari,项目名称:mocp,代码行数:33,代码来源:playlist.c

示例11: main

int main(int argc, char *argv[])
{
	struct rb_node sentinel;
	struct rb_tree rbtree;
	struct rb_node node[1000];
	int i, j;

	rb_init(&rbtree, &sentinel);
	srand(time(0));

	for (i = 0; i < 10; i++) {
		for (;;) {
			node[i].key = rand()%10000;
			for (j = 0; j < i; j++) {
				if (node[i].key == node[j].key)
					break;
			}
			if (j < i)
				continue;
			else
				break;
		}
		rb_insert(&rbtree, &node[i]);
	}
	for (i = 0; i < 10; i++)
		rb_delete(&rbtree, &node[i]);

	exit(0);
}
开发者ID:bablon,项目名称:algorithms,代码行数:29,代码来源:t_rbtree.c

示例12: node_insert_at

static bool
node_insert_at(struct rbtree_elem **root, struct rbtree_elem *node,
    struct rbtree_elem *new_node, rbtree_less_func *less)
{
  bool inserted;

  inserted = false;

  while (!inserted) {
    ASSERT(node!=nil);
    if (less(node, new_node)) /*(node->high < lowIP)*/ {
      if (node->right == nil) {
        node->right = new_node;
        new_node->parent = node;
        inserted = true;
      } else {
        node = node->right;
      }
    } else {
      ASSERT(is_less(new_node, node));
      if (node->left == nil) {
        node->left = new_node;
        new_node->parent = node;
        inserted = true;
      } else {
        node = node->left;
      }
    }
  }

  rb_insert(root, new_node) ;
  return true;
}
开发者ID:EgoIncarnate,项目名称:btkernel,代码行数:33,代码来源:rbtree.c

示例13: Write

int Write(unsigned long *random_seed, param_t *params)
{
    long int_value;
    void *value;

    int_value = (get_random(random_seed) % params->size) + 1;

    // make sure we have an odd value
    int_value |= 0x0001;

    value = rb_remove(My_Tree, int_value);
    if (value == NULL)
    {
        printf("Failure to remove %ld\n", int_value);
        exit(-2);
    }

    if (!rb_insert(My_Tree, int_value, (void *)int_value) )
    {
        printf("Failure to insert %ld\n", int_value);
        exit(-3);
    }

    return 0;
}
开发者ID:philip-w-howard,项目名称:RP-Red-Black-Tree,代码行数:25,代码来源:rbtest.c

示例14: main

int main() {
    RB_TREE root = NULL;
    RB_TYPE rbt;
    int v,i;

    rb_type_create( &rbt, sizeof(VNODE), 0, cmp, NULL, NULL );

    srand(2);
    for( i=0; i<1000; i++ ) {
	v = rand();
	//v = 1000000-i;
	rb_insert( &rbt, &root, &v );
	}
    rb_assert(&rbt,root);

    printf( "Tree has %d elements\n", rb_size(&root) );

    srand(2);
    for( i=0; i<1000; i++ ) {
	v = rand();
	//v = 1000000-i;
	rb_remove( &rbt, &root, &v );
	}
    rb_assert(&rbt,root);
    printf( "Tree has %d elements\n", rb_size(&root) );

    rb_free(&rbt,&root);

    return 0;
    }
开发者ID:jpcoles,项目名称:ZM,代码行数:30,代码来源:rbtree.c

示例15: register_event_prio

int register_event_prio(int fd, event_handler_t h, void *data, int prio)
{
	int ret;
	struct epoll_event ev;
	struct event_info *ei;

	ei = xzalloc(sizeof(*ei));
	ei->fd = fd;
	ei->handler = h;
	ei->data = data;
	ei->prio = prio;

	memset(&ev, 0, sizeof(ev));
	ev.events = EPOLLIN;
	ev.data.ptr = ei;

	ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
	if (ret) {
		sd_err("failed to add epoll event for fd %d: %m", fd);
		free(ei);
	} else
		rb_insert(&events_tree, ei, rb, event_cmp);

	return ret;
}
开发者ID:gHcAgree,项目名称:sheepdog-ng,代码行数:25,代码来源:event.c


注:本文中的rb_insert函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。