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

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

      <legend id='tim5t'><style id='tim5t'><dir id='tim5t'><q id='tim5t'></q></dir></style></legend>
      1. 什么是英语单词的好的哈希函数?

        What#39;s a good hash function for English words?(什么是英语单词的好的哈希函数?)

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

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

                  <bdo id='QI6GP'></bdo><ul id='QI6GP'></ul>
                • 本文介绍了什么是英语单词的好的哈希函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一长串英文单词,我想对它们进行哈希处理.什么是好的散列函数?到目前为止,我的散列函数对字母的 ASCII 值求和,然后对表大小求模.我正在寻找高效而简单的东西.

                  I have a long list of English words and I would like to hash them. What would be a good hashing function? So far my hashing function sums the ASCII values of the letters then modulo the table size. I'm looking for something efficient and simple.

                  推荐答案

                  简单地将字母相加并不是一个好的策略,因为排列会产生相同的结果.

                  To simply sum the letters is not a good strategy because a permutation gives the same result.

                  这个 (djb2) 非常受欢迎,并且与ASCII 字符串.

                  This one (djb2) is quite popular and works nicely with ASCII strings.

                  unsigned long hashstring(unsigned char *str)
                  {
                      unsigned long hash = 5381;
                      int c;
                  
                      while (c = *str++)
                          hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
                  
                      return hash;
                  }
                  

                  更多信息此处.

                  如果您需要更多替代方案和一些性能措施,请阅读此处.

                  If you need more alternatives and some perfomance measures, read here.

                  添加:这些是通用散列函数,其中输入域是事先未知的(除了一些非常一般的假设:例如,上述使用 ascii 稍微好一点输入),这是最常见的场景.如果您有一个已知的受限域(固定输入集),您可以做得更好,请参阅 Fionn 的回答.

                  Added: These are general hashing functions, where the input domain is not known in advance (except perhaps some very general assumptions: eg the above works slightly better with ascii input), which is the most usual scenario. If you have a known restricted domain (set of inputs fixed) you can do better, see Fionn's answer.

                  这篇关于什么是英语单词的好的哈希函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

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

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

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