int main(int argc, char **argv) { int *v; int i; char buf[256]; int c; int ofx = 0; rbtree_t *rbt = rbtree_create(rbtree_cmp_keys_int32, free); printf("\e[1;1H\e[2J"); printf("Enter an integer number: "); while((c = getchar())) { if (c == EOF) break; if (c == '\n') { buf[ofx] = 0; int *num = malloc(sizeof(int)); *num = strtol(buf, NULL, 10); printf("Added node: %d\n\n", *num); rbtree_add(rbt, num, sizeof(int), num, sizeof(int)); printf("\e[1;1H\e[2J"); rbtree_print(rbt); ofx = 0; printf("Enter an integer number: "); } else {
void main() { struct rbtree *tree = NULL; tree = rbtree_add(tree, 10, "10"); tree = rbtree_add(tree, 5, "5"); tree = rbtree_add(tree, 3, "3"); tree = rbtree_add(tree, 11, "11"); tree = rbtree_add(tree, 12, "12"); tree = rbtree_add(tree, 6, "6"); tree = rbtree_add(tree, 8, "8"); tree = rbtree_add(tree, 9, "9"); }
static adlb_code xlb_workq_add_parallel(xlb_work_unit* wu) { // Untargeted parallel task TRACE("xlb_workq_add_parallel(): %p", wu); struct rbtree* T = ¶llel_work[wu->type]; TRACE("rbtree_add: wu: %p key: %i\n", wu, -wu->opts.priority); rbtree_add(T, -wu->opts.priority, wu); xlb_workq_parallel_task_count++; if (xlb_s.perfc_enabled) { xlb_task_counters[wu->type].parallel_enqueued++; } return ADLB_SUCCESS; }
/* * Return a fresh x not in the set then add x to set * - the set must not be full */ uint32_t rb_bvset_get_fresh(rb_bvset_t *set) { uint32_t x; assert(! rb_bvset_full(set)); /* * Naive technique: scan from 0 to .. max_val * (todo: use a random search first, then revert * to the naive method)?? */ x = set->ptr; while (rbtree_is_present(&set->tree, x)) { x ++; } assert(x <= set->max_val); rbtree_add(&set->tree, x); set->ptr = x+1; return x; }
int main() { /* * default flags */ rbtree_t rbt; rbtree_create(&rbt, sizeof(int)); int n = 1; rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); print_rbt(rbt.root, 0); rbtree_destroy( &rbt ); /* * right leaning flag */ rbtree_create(&rbt, sizeof(int)); rbtree_set_flags(&rbt, rbt.flags & ~G_RB_LEFT_LEANING); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); print_rbt(rbt.root, 0); rbtree_destroy( &rbt ); /* * override flag */ rbtree_create(&rbt, sizeof(int)); rbtree_set_flags(&rbt, G_RB_EQUAL_OVERRIDE); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); rbtree_add(&rbt, &n); print_rbt(rbt.root, 0); rbtree_destroy( &rbt ); return 0; }