zoukankan      html  css  js  c++  java
  • 宏HASH_INSERT

     

    调用 方法 

    HASH_INSERT(lock_t, hash, lock_sys->rec_hash,lock_rec_fold(space, page_no), lock);
    /*******************************************************************//**
    Inserts a struct to a hash table. */
    
    #define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)
    do {
        hash_cell_t*    cell3333; //hash_cell_t* 定义
        TYPE*        struct3333;
    
        HASH_ASSERT_OWNED(TABLE, FOLD)
    
        (DATA)->NAME = NULL;
    
        cell3333 = hash_get_nth_cell(TABLE, hash_calc_hash(FOLD, TABLE)); //函数定义
    
        if (cell3333->node == NULL) {
            cell3333->node = DATA;
        } else {
            struct3333 = (TYPE*) cell3333->node; //此时struct3333的类型是lock_t
    
            while (struct3333->NAME != NULL) {  //NAME 为 hash_node_t  hash; typedef void* hash_node_t;
           struct3333 = (TYPE*) struct3333->NAME; 
        }
        struct3333
    ->NAME = DATA;
    }
    }
    while (0)

    这里好绕

    对于下一个元素, 都习惯于使用struct  结构体名称 *next

    /**************************************************************//**
    Calculates the hash value from a folded value.
    @return    hashed value */
    UNIV_INLINE
    ulint
    hash_calc_hash(
    /*===========*/
        ulint        fold,    /*!< in: folded value */
        hash_table_t*    table)    /*!< in: hash table */
    {
        ut_ad(table);
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
        return(ut_hash_ulint(fold, table->n_cells));
    }
    
    ulint
    ut_hash_ulint(
    /*==========*/
        ulint     key,        /*!< in: value to be hashed */
        ulint     table_size)    /*!< in: hash table size */
    {
        ut_ad(table_size);
        key = key ^ UT_HASH_RANDOM_MASK2;
    
        return(key % table_size);
    }

     

     

    HASH_INSERT(lock_t, hash, lock_sys->rec_hash,
                lock_rec_fold(space, page_no), lock);
    
    
    /*********************************************************************//**
    Calculates the fold value of a page file address: used in inserting or
    searching for a lock in the hash table.
    @return    folded value */
    UNIV_INLINE
    ulint
    lock_rec_fold(
    /*==========*/
        ulint    space,    /*!< in: space */
        ulint    page_no)/*!< in: page number */
    {
        return(ut_fold_ulint_pair(space, page_no));
    }
    
    
    /*************************************************************//**
    Folds a pair of ulints.
    @return    folded value */
    UNIV_INLINE
    ulint
    ut_fold_ulint_pair(
    /*===============*/
        ulint    n1,    /*!< in: ulint */
        ulint    n2)    /*!< in: ulint */
    {
        return(((((n1 ^ n2 ^ UT_HASH_RANDOM_MASK2) << 8) + n1)
            ^ UT_HASH_RANDOM_MASK) + n2);
    }

     

  • 相关阅读:
    0112centos上面l安装卸载mysq
    0111mysql如何选择Join的顺序
    0111MySQL优化的奇技淫巧之STRAIGHT_JOIN
    0108MySQL集群搭建详解(三种结点分离)
    0106主从复制
    0104探究MySQL优化器对索引和JOIN顺序的选择
    MongoDB整理笔记の新增Shard Server
    MongoDB整理笔记の管理Sharding
    MongoDB整理笔记のSharding分片
    MongoDB整理笔记の减少节点
  • 原文地址:https://www.cnblogs.com/taek/p/4936609.html
Copyright © 2011-2022 走看看