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);
    }

     

  • 相关阅读:
    C# 开发规范
    C# 调用webserver 出现:未能从程序集“jgd3jufm, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”中加载类型
    C# 组装XML传给webserver+XML 返回获取多个xml,根据多个XML 返回dataset类型
    linux下搭建git服务器
    Linux整合Apache和SVN
    JAVA通过Gearman实现MySQL到Redis的数据同步(异步复制)
    比尔盖茨的十句忠告
    Spring核心接口之InitializingBean
    mongodb安装和配置
    redis主从配置
  • 原文地址:https://www.cnblogs.com/taek/p/4936609.html
Copyright © 2011-2022 走看看