<bdo id='wKYCv'></bdo><ul id='wKYCv'></ul>

      <legend id='wKYCv'><style id='wKYCv'><dir id='wKYCv'><q id='wKYCv'></q></dir></style></legend>
    1. <tfoot id='wKYCv'></tfoot>
      1. <small id='wKYCv'></small><noframes id='wKYCv'>

        <i id='wKYCv'><tr id='wKYCv'><dt id='wKYCv'><q id='wKYCv'><span id='wKYCv'><b id='wKYCv'><form id='wKYCv'><ins id='wKYCv'></ins><ul id='wKYCv'></ul><sub id='wKYCv'></sub></form><legend id='wKYCv'></legend><bdo id='wKYCv'><pre id='wKYCv'><center id='wKYCv'></center></pre></bdo></b><th id='wKYCv'></th></span></q></dt></tr></i><div id='wKYCv'><tfoot id='wKYCv'></tfoot><dl id='wKYCv'><fieldset id='wKYCv'></fieldset></dl></div>
      2. 二维索引的良好散列函数

        时间:2023-08-26
          <tbody id='F3sgy'></tbody>

          1. <i id='F3sgy'><tr id='F3sgy'><dt id='F3sgy'><q id='F3sgy'><span id='F3sgy'><b id='F3sgy'><form id='F3sgy'><ins id='F3sgy'></ins><ul id='F3sgy'></ul><sub id='F3sgy'></sub></form><legend id='F3sgy'></legend><bdo id='F3sgy'><pre id='F3sgy'><center id='F3sgy'></center></pre></bdo></b><th id='F3sgy'></th></span></q></dt></tr></i><div id='F3sgy'><tfoot id='F3sgy'></tfoot><dl id='F3sgy'><fieldset id='F3sgy'></fieldset></dl></div>

              • <legend id='F3sgy'><style id='F3sgy'><dir id='F3sgy'><q id='F3sgy'></q></dir></style></legend>
                  <bdo id='F3sgy'></bdo><ul id='F3sgy'></ul>

                • <tfoot id='F3sgy'></tfoot>

                  <small id='F3sgy'></small><noframes id='F3sgy'>

                • 本文介绍了二维索引的良好散列函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个名为 Point 的结构.要点很简单:

                  I have a struct called Point. Point is pretty simple:

                  struct Point
                  {
                      Row row;
                      Column column;
                  
                      // some other code for addition and subtraction of points is there too
                  }
                  

                  RowColumn 基本上是美化的 ints,但我厌倦了不小心将输入参数转换为函数并给它们每个包装类.

                  Row and Column are basically glorified ints, but I got sick of accidentally transposing the input arguments to functions and gave them each a wrapper class.

                  现在我使用 set 点,但重复查找确实会减慢速度.我想切换到 unordered_set.

                  Right now I use a set of points, but repeated lookups are really slowing things down. I want to switch to an unordered_set.

                  所以,我想要一个 Pointunordered_set.通常,该集合可能包含例如 80x24 终端上的每个点 = 1920 个点.我需要一个好的散列函数.我只是想出了以下内容:

                  So, I want to have an unordered_set of Points. Typically this set might contain, for example, every point on a 80x24 terminal = 1920 points. I need a good hash function. I just came up with the following:

                  struct PointHash : public std::unary_function<Point, std::size_t>
                  {
                      result_type operator()(const argument_type& val) const
                      {
                          return val.row.value() * 1000 + val.col.value();
                      }
                  };
                  

                  但是,我不确定这是否真的是一个很好的散列函数.我想要一些快速的东西,因为我需要非常快速地进行很多查找.有没有更好的散列函数我可以使用,或者这可以吗?

                  However, I'm not sure that this is really a good hash function. I wanted something fast, since I need to do many lookups very quickly. Is there a better hash function I can use, or is this OK?

                  推荐答案

                  遵循 Effective Java (2nd edition) 中给出的技术,并在 Programming in Scala 中引用了该技术em>.有一个素数常数(我们会说 53,但你可能会发现更大的常数会得到更均匀的分布),并按如下方式执行乘法和加法:

                  Following the technique is given in Effective Java (2nd edition), and quoted from there in Programming in Scala. Have a prime constant (we'll say 53 but you may find something larger will give more even distribution here), and perform multiplication and addition as follows:

                  (53 + int_hash(row)) * 53 + int_hash(col)
                  

                  对于更多值(假设您添加 z 坐标),只需继续嵌套,例如

                  For more values (say you add a z coordinate), just keep nesting, like

                  ((53 + int_hash(row)) * 53 + int_hash(col)) * 53 + int_hash(z)
                  

                  其中 int_hash 是用于散列单个整数的函数.您可以访问此页面找到 一堆很好的散列函数用于单个整数.

                  Where int_hash is a function for hashing a single integer. You can visit this page to find a bunch of good hash functions for single integers.

                  这篇关于二维索引的良好散列函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:所有 STL 容器的通用哈希函数 下一篇:如何使用 Qt 获取文件的 SHA-1/MD5 校验和?

                  相关文章

                      <bdo id='XgTVD'></bdo><ul id='XgTVD'></ul>

                  1. <small id='XgTVD'></small><noframes id='XgTVD'>

                    <legend id='XgTVD'><style id='XgTVD'><dir id='XgTVD'><q id='XgTVD'></q></dir></style></legend>

                      <i id='XgTVD'><tr id='XgTVD'><dt id='XgTVD'><q id='XgTVD'><span id='XgTVD'><b id='XgTVD'><form id='XgTVD'><ins id='XgTVD'></ins><ul id='XgTVD'></ul><sub id='XgTVD'></sub></form><legend id='XgTVD'></legend><bdo id='XgTVD'><pre id='XgTVD'><center id='XgTVD'></center></pre></bdo></b><th id='XgTVD'></th></span></q></dt></tr></i><div id='XgTVD'><tfoot id='XgTVD'></tfoot><dl id='XgTVD'><fieldset id='XgTVD'></fieldset></dl></div>
                    1. <tfoot id='XgTVD'></tfoot>