您现在的位置:主页 > 技术中心 > 数据库技术 > Mysql

Mysql源码学习——没那么简单的Hash(12)

来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:17 点击:

    /* Check if more records in same hash-nr family */

    empty[0]=pos[0];

    gpos= data + my_hash_rec_mask(info, pos, info->blength, info->records + 1);

    if (pos == gpos)

    {

      pos->data=(uchar*) record;

      pos->next=(uint) (empty - data);

    }

    else

    {

      pos->data=(uchar*) record;

      pos->next=NO_RECORD;

      movelink(data,(uint) (pos-data),(uint) (gpos-data),(uint) (empty-data));

    }

  }

  if (++info->records == info->blength)

    info->blength+= info->blength;

  return(0);

}

    同时给出动态hash函数如下:

 

static uint my_hash_mask(my_hash_value_type hashnr, size_t buffmax,

                         size_t maxlength)

{

  if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1));

  return (hashnr & ((buffmax >> 1) -1));

}

<font size="3">  </font>

   可以看出,hash函数是hash key与buffmax的模运算,buffmax即HASH结构中的blength,由my_hash_insert中最后几行代码可知:info->blength+= info->blength; 其初始值为1,即blength = 2^n,而且blengh始终是大于records。这个动态hash函数的基本意思是key%(2^n)。依然用图解这个动态hash函数

 

image

    

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片

推荐热点

  • mysql-mmm
  • mysqldump命令——MySQL数据库备份还原
  • Oracle数据导入MySQL的快捷工具:MySQL Migration Tool
  • 简简单单储存过程——循环一个select结果集
  • MySQL数据库十大优化技巧
  • Mysql安装笔记
  • Mysql主主复制架构配置
  • Mysql的Procedure 参数为NULL问题分析
  • MySQL Stmt预处理提高效率问题的小研究
?? - ?? - ÝřŝžľŘÝź - TAGąęÇŠ - RSSśŠÔÄ - ??
Copyright © 2004-2024 上海卓卓网络科技有限公司