English 中文(简体)
简单的散射机
原标题:Simple hash function techniques

在贾瓦和伊夫的洗.中,我很新鲜。 我有400件物品清单(储存在1.5x=600件清单中),该物品在1-10k之间。 我一直在研究一些散列函数,我最初在包装单上抄录了例子,这套包装刚刚使用。 我注意到,我已经获得大约50-60%的废 no,这似乎太多。 我还注意到,仅仅用600 子 mo,就会将其削减到50%的固体垃圾。

My current hash function looks something like, and for being as ugly as it is, it s only a 1% decrease in nulls from a simple modding, with an avg list length of 1.32...

   public int getHash( int id )
   {
      int hash = id;

      hash <<= id % 3;
      hash += id << hash % 5;

      /* let s go digit by digit! */          
      int digit;
      for( digit = id % 10;
           id != 0;
           digit = id % 10, id /= 10 )
      {
         if ( digit == 0 ) /* prevent division by zero */
            continue;
         hash += digit * 2;
      }

      hash >>= 5;
      return (hash % 600);
   }

创建<<simpleh>的机能是什么?

最佳回答

我将保持简单。 将贵元素的<代码>id作为贵重编码,如果认为需要,则让大家对重签表示怀疑。 Your objective should be made a hash code separate to their Object.

Java HashMap使用以下翻新方法:

/**
 * Applies a supplemental hash function to a given hashCode, which
 * defends against poor quality hash functions.  This is critical
 * because HashMap uses power-of-two length hash tables, that
 * otherwise encounter collisions for hashCodes that do not differ
 * in lower bits. Note: Null keys always map to hash 0, thus index 0.
 */
static int hash(int h) {
    // This function ensures that hashCodes that differ only by
    // constant multiples at each bit position have a bounded
    // number of collisions (approximately 8 at default load factor).
    h ^= (h >>> 20) ^ (h >>> 12);
    return h ^ (h >>> 7) ^ (h >>> 4);
}
问题回答

http://www.concentric.net/~ttwang/tech/inthash.htm“rel=“nofollow”>。 另外,Wikipedia article on hash functions是一个很好的概述。 它建议使用芯片检验来评估贵重功能的质量。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签