Exemple #1
0
int
bc_add_blk(page_idx_t start_page, int order) {
    if (!blk_cache_init || !enable_blk_cache)
        return INVALID_LRU_IDX;

    if (unlikely(lru_is_full())) {
        bc_evict_oldest();
        ASSERT(!lru_is_full());
    }

    int idx = lru_append(start_page, order);
    ASSERT(idx != INVALID_LRU_IDX);

    int rv = rbt_insert(blk_cache->blks, start_page, idx);
    if (likely(rv)) {
        blk_cache->total_page_num += 1 << order;
        if (blk_cache->total_page_num > MAX_CACHE_PAGE_NUM &&
            blk_cache->lru_hdr != blk_cache->lru_tail) {
            bc_evict_oldest();
        }
        return 1;
    }

    ASSERT(0);
    lru_popback();
    return 0;
}
static void
aoff_link_free_block(Allctr_t *allctr, Block_t *block)
{
    AOFFAllctr_t* alc = (AOFFAllctr_t*) allctr;
    AOFF_RBTree_t *blk = (AOFF_RBTree_t *) block;
    AOFF_RBTree_t *crr_node;
    AOFF_Carrier_t *blk_crr = (AOFF_Carrier_t*) FBLK_TO_MBC(block);
    Uint blk_sz = AOFF_BLK_SZ(blk);

    ASSERT(allctr == ERTS_ALC_CARRIER_TO_ALLCTR(&blk_crr->crr));
    ASSERT(blk_crr->rbt_node.hdr.bhdr == (blk_crr->root ? blk_crr->root->max_sz : 0));
    HARD_CHECK_TREE(&blk_crr->crr, alc->blk_order, blk_crr->root, 0);

    rbt_insert(alc->blk_order, &blk_crr->root, blk);

    /*
     * Update carrier tree with a potentially new (larger) max_sz
     */
    crr_node = &blk_crr->rbt_node;
    if (blk_sz > crr_node->hdr.bhdr) {
        ASSERT(blk_sz == blk_crr->root->max_sz);
        crr_node->hdr.bhdr = blk_sz;
        while (blk_sz > crr_node->max_sz) {
            crr_node->max_sz = blk_sz;
            crr_node = crr_node->parent;
            if (!crr_node) break;
        }
    }
    HARD_CHECK_TREE(NULL, alc->crr_order, alc->mbc_root, 0);
}
Exemple #3
0
rbt rbt_insert(rbt r,char *s)
{
  if(r == NULL){/*empty tree*/
    r = emalloc(sizeof *r);
    r->key = emalloc(strlen(s) * sizeof s[0] + 1);
    r->colour = RED;
    strcpy(r->key,s);
  }else if(strcmp(r->key,s)==0){/*do nothing*/
  }else if(strcmp(r->key,s) < 0){/*s > b-key */
    r->right = rbt_insert(r->right,s);
  }
  else if(strcmp(r->key,s) > 0){/*s < b-key*/
    r->left = rbt_insert(r->left,s);
  }
  r = rbt_fix(r);
  return r;
}
Exemple #4
0
rbt rbt_insert(rbt r, char *s) {
   if (NULL == r) {
      r = emalloc(sizeof *r);
      r->key = emalloc(strlen(s) + 1);
      r->colour = RED;
      r->left = NULL;
      r->right = NULL;
      strcpy(r->key, s);
   } else if (strcmp(s, r->key) == 0) {
      /* do nothing */
   } else if (strcmp(s, r->key) < 0) {
      r->left = rbt_insert(r->left, s);
   } else {
      r->right = rbt_insert(r->right, s);
   }
   return rbt_fix(r);
}
//red_black_tree oerride method
void user_insert_node(char* id, char* register_date, char* name) {
	User_Node node = user_node_alloc(id, register_date, name);
	if (user_database == NULL) {
		user_database = node->rbtnode;
		user_database->left = user_database->right = Nil;
	}
	else
		rbt_insert(&user_database, node->rbtnode, user_compare_node);
}
static void aoff_add_mbc(Allctr_t *allctr, Carrier_t *carrier)
{
    AOFFAllctr_t *alc = (AOFFAllctr_t *) allctr;
    AOFF_Carrier_t *crr = (AOFF_Carrier_t*) carrier;
    AOFF_RBTree_t **root = &alc->mbc_root;

    ASSERT(!IS_CRR_IN_TREE(crr, *root));
    HARD_CHECK_TREE(NULL, alc->crr_order, *root, 0);   

    rbt_insert(alc->crr_order, root, &crr->rbt_node);

    HARD_CHECK_TREE(NULL, alc->crr_order, *root, 0);
}
void aoff_add_pooled_mbc(Allctr_t *allctr, Carrier_t *crr)
{
    AOFFAllctr_t *alc = (AOFFAllctr_t *) allctr;
    AOFF_RBTree_t **root = &allctr->cpool.pooled_tree;

    ASSERT(allctr == crr->cpool.orig_allctr);
    HARD_CHECK_TREE(NULL, 0, *root, 0);

    /* Link carrier in address order tree
     */
    rbt_insert(alc->crr_order, root, &crr->cpool.pooled);

    HARD_CHECK_TREE(NULL, 0, *root, 0);
}
Exemple #8
0
Bool rbtsimple_create_node( /*@in@*/ RBT_ROOT *root , uintptr_t key )
{
  RBT_NODE *node = rbt_search( root , key ) ;

  if ( node == NULL ) {
    node = rbt_allocate_node( root , key , NULL ) ;

    if ( node == NULL ) {
      return FALSE ;
    }

    rbt_insert( root , node ) ;
  }

  return TRUE ;
}
Exemple #9
0
int PushCache(INT h, int hash, int width, int height, int format, unsigned char * data)
{
	LPCACHE_NODE pNode;
	LPCACHE_HANDLE handle = (LPCACHE_HANDLE)h;
	int ret = 0;
	if (handle == GNull) {
		return -1;
	}

	// search in rb-tree
	pNode = rbt_search(&handle->mRBRoot, hash);

	if (handle->mCurCount >= handle->mMaxCount && pNode == GNull) {
		// replace
		container_of(pNode, dl_last(&(handle->mDLRoot)), CACHE_NODE, mDLNode);
#if defined( _DEBUG )
		LOGI("replace get last 0x%X\n", pNode);
#endif
	}

	if (pNode != GNull) {
		//remove out in linked queue.
		dl_remove_node(&(pNode->mDLNode), &(handle->mDLRoot));

		//remove from rb-tree.
		rb_erase(&pNode->mRBNode, &handle->mRBRoot);

		pNode->mKey = hash;
		
	} else {
		pNode = (LPCACHE_NODE)GMemMalloc(sizeof(CACHE_NODE));
		pNode->mKey = hash;
		handle->mCurCount++;
		cache_data_initial(&(pNode->mData));
	}

	cache_data_update(&(pNode->mData), width, height, format, data);

	//add node
	dl_insert_node(&(pNode->mDLNode), GNull, &(handle->mDLRoot));

	//add to rb-tree
	rb_init_node(&pNode->mRBNode);
	rbt_insert(&handle->mRBRoot, pNode);
	return ret;
}
Exemple #10
0
int main(){
    Rbt_tree_link a = rbt_create();
    Rbtlink it;
    srand(time(NULL));

    puts("Inserting...");
    for(i=0;i<N;i++) {
	num[i] = rand() % N;
	rbt_insert(a,num[i]);
    }
    
    printf("rbt_size: %d\n",rbt_size(a));

    printf("min value:%d   max value:%d\n",rbt_item(rbt_minimum(a)),rbt_item(rbt_maximum(a)));
    puts("Doing assert...");
    rbt_assert(a);
    puts("Traversing (inorder)...");
    rbt_inorder(a,func);

    for(i=0; i < N; i++)
	rbt_search(a, i);

    puts("Traversing (from max to min)...");
    it = rbt_maximum(a);
    for(i = rbt_size(a)-1; i >= 0; i--) {
	assert(n[i] == rbt_item(it));
	it = rbt_predecessor(it);
    }

    printf("rbt_size: %d\n",rbt_size(a));

    puts("Deleting all values...");
    int i = 0;
    for (i = 0; i < N; ++i) {
	printf("%d deleted\r", num[i]);
	rbt_delete(a, num[i]);
    }

    puts("\nDestroying rbt..");
    rbt_destroy(a);
    puts("OK!");
    return 0;
}
static void aoff_creating_mbc(Allctr_t *allctr, Carrier_t *carrier)
{
    AOFFAllctr_t *alc = (AOFFAllctr_t *) allctr;
    AOFF_Carrier_t *crr = (AOFF_Carrier_t*) carrier;
    AOFF_RBTree_t **root = &alc->mbc_root;

    HARD_CHECK_TREE(NULL, alc->crr_order, *root, 0);

    crr->rbt_node.hdr.bhdr = 0;
    if (alc->crr_order == FF_AGEFF || IS_DEBUG) {
        Sint64 bt = get_birth_time();
        crr->rbt_node.u.birth_time = bt;
        crr->crr.cpool.pooled.u.birth_time = bt;
    }
    rbt_insert(alc->crr_order, root, &crr->rbt_node);

    /* aoff_link_free_block will add free block later */
    crr->root = NULL;

    HARD_CHECK_TREE(NULL, alc->crr_order, *root, 0);
}
Exemple #12
0
/********************************************************************//**
Insert a block in the flush_rbt and returns a pointer to its
predecessor or NULL if no predecessor. The ordering is maintained
on the basis of the <oldest_modification, space, offset> key.
@return pointer to the predecessor or NULL if no predecessor. */
static
buf_page_t*
buf_flush_insert_in_flush_rbt(
/*==========================*/
	buf_page_t*	bpage)		/*!< in: bpage to be inserted. */
{
	buf_page_t*		prev = NULL;
	const ib_rbt_node_t*	c_node;
	const ib_rbt_node_t*	p_node;

	ut_ad(buf_pool_mutex_own());

	/* Insert this buffer into the rbt. */
	c_node = rbt_insert(buf_pool->flush_rbt, &bpage, &bpage);
	ut_a(c_node != NULL);

	/* Get the predecessor. */
	p_node = rbt_prev(buf_pool->flush_rbt, c_node);

	if (p_node != NULL) {
		prev = *rbt_value(buf_page_t*, p_node);
		ut_a(prev != NULL);
	}
/********************************************************************//**
Add a single foreign key definition to the data dictionary tables in the
database. We also generate names to constraints that were not named by the
user. A generated constraint has a name of the format
databasename/tablename_ibfk_NUMBER, where the numbers start from 1, and
are given locally for this table, that is, the number is not global, as in
the old format constraints < 4.0.18 it used to be.
@return	error code or DB_SUCCESS */
static
ulint
dict_create_add_foreign_to_dictionary(
    /*==================================*/
    ulint*		id_nr,	/*!< in/out: number to use in id generation;
				incremented if used */
    dict_table_t*	table,	/*!< in: table */
    dict_foreign_t*	foreign,/*!< in: foreign */
    trx_t*		trx)	/*!< in: transaction */
{
    ulint		error;
    ulint		i;
    pars_info_t*	info;

    ut_ad(mutex_own(&(dict_sys->mutex)));

    if (foreign->id == NULL) {
        /* Generate a new constraint id */
        ulint	namelen	= strlen(table->name);
        char*	id	= mem_heap_alloc(foreign->heap, namelen + 20);

        if (row_is_mysql_tmp_table_name(table->name)) {
            sprintf(id, "%s_ibfk_%lu", table->name,
                    (ulong) (*id_nr)++);
        } else {
            char	table_name[MAX_TABLE_NAME_LEN + 20] = "";
            uint	errors = 0;

            strncpy(table_name, table->name,
                    MAX_TABLE_NAME_LEN + 20);

            innobase_convert_to_system_charset(
                strchr(table_name, '/') + 1,
                strchr(table->name, '/') + 1,
                MAX_TABLE_NAME_LEN, &errors);

            if (errors) {
                strncpy(table_name, table->name,
                        MAX_TABLE_NAME_LEN + 20);
            }

            sprintf(id, "%s_ibfk_%lu", table_name,
                    (ulong) (*id_nr)++);

            if (innobase_check_identifier_length(
                        strchr(id,'/') + 1)) {
                return(DB_IDENTIFIER_TOO_LONG);
            }
        }
        foreign->id = id;
    }

    info = pars_info_create();

    pars_info_add_str_literal(info, "id", foreign->id);

    pars_info_add_str_literal(info, "for_name", table->name);

    pars_info_add_str_literal(info, "ref_name",
                              foreign->referenced_table_name);

    pars_info_add_int4_literal(info, "n_cols",
                               foreign->n_fields + (foreign->type << 24));

    error = dict_foreign_eval_sql(info,
                                  "PROCEDURE P () IS\n"
                                  "BEGIN\n"
                                  "INSERT INTO SYS_FOREIGN VALUES"
                                  "(:id, :for_name, :ref_name, :n_cols);\n"
                                  "END;\n"
                                  , table, foreign, trx);

    if (error != DB_SUCCESS) {

        return(error);
    }

    for (i = 0; i < foreign->n_fields; i++) {
        error = dict_create_add_foreign_field_to_dictionary(
                    i, table, foreign, trx);

        if (error != DB_SUCCESS) {

            return(error);
        }
    }

    error = dict_foreign_eval_sql(NULL,
                                  "PROCEDURE P () IS\n"
                                  "BEGIN\n"
                                  "COMMIT WORK;\n"
                                  "END;\n"
                                  , table, foreign, trx);

    if (error == DB_SUCCESS) {


        if (foreign->foreign_table != NULL) {
            ib_rbt_t*	rbt
                = foreign->foreign_table->foreign_rbt;

            if (rbt == NULL) {
                rbt = dict_table_init_foreign_rbt(
                          foreign->foreign_table);
            } else {
                rbt_delete(rbt, foreign->id);
            }

            rbt_insert(rbt, foreign->id, &foreign);
        }

        if (foreign->referenced_table != NULL) {
            ib_rbt_t* rbt
                = foreign->referenced_table->referenced_rbt;

            if (rbt == NULL) {
                rbt = dict_table_init_referenced_rbt(
                          foreign->referenced_table);
            } else {
                rbt_delete(rbt, foreign->id);
            }
            rbt_insert(rbt, foreign->id, &foreign);
        }
    }

    return(error);
}