Java 链式散列与双重探测

Java 链式散列与双重探测,java,data-structures,complexity-theory,double-hashing,Java,Data Structures,Complexity Theory,Double Hashing,我试图比较链锁和双重探测。 我需要在表大小为100的地方插入40个整数, 当我用nanotime(java)测量时间时 我知道双人的速度更快。 这是因为在链接的插入方法中,我每次创建LinkedListEntry时, 现在是增加时间的时候了。 链接怎么会比双重探测更快呢?(这是我在维基百科上读到的) 谢谢 这是链接的代码: public class LastChain { int tableSize; Node[] st; LastChain(int size) {

我试图比较链锁和双重探测。 我需要在表大小为100的地方插入40个整数, 当我用nanotime(java)测量时间时 我知道双人的速度更快。 这是因为在链接的插入方法中,我每次创建LinkedListEntry时, 现在是增加时间的时候了。 链接怎么会比双重探测更快呢?(这是我在维基百科上读到的)

谢谢

这是链接的代码:

public class LastChain
{
    int tableSize;
     Node[] st;
    LastChain(int size) {
        tableSize = size;
        st = new Node[tableSize];
        for (int i = 0; i < tableSize; i++)
            st[i] = null;
    }

    private class Node
    {
        int key;
        Node next;
        Node(int key, Node next)
        {
            this.key   = key;
            this.next  = next;
        }
    }

    public void put(Integer key) 
    {
       int i = hash(key);
       Node first=st[i];
       for (Node x = st[i]; x != null; x = x.next)
          if (key.equals(x.key))
             { 
             return; 
              }

       st[i] = new Node(key, first);

    }


    private int hash(int key)
    {  return key%tableSize;
    }

      }
}
这样,在Double中插入比链接更快。
如何修复它?

链接在高负载系数下效果最好。尝试在100个表中使用90个字符串(不是一个很好的整数选择)

此外,链接更容易实现对的删除/删除


注意:在HashMap中,无论条目对象是否链接,都会创建条目对象,而不会在其中保存。

链接在高负载系数下效果最好。尝试在100个表中使用90个字符串(不是一个很好的整数选择)

此外,链接更容易实现对的删除/删除

注意:在HashMap中,无论条目对象是否链接,都会创建条目对象,而不是不保存条目对象。

Java具有特殊的“功能”,对象占用大量内存

因此,对于大型数据集(这将具有任何相关性),双重探测将是好的

但是作为第一件事,请将整数[]更改为int[]->内存使用量将是四分之一左右,性能将得到很好的提升

但是总是有性能问题:度量,度量,度量,因为您的情况总是特殊的。

Java有一个特殊的“特性”,对象占用大量内存

因此,对于大型数据集(这将具有任何相关性),双重探测将是好的

但是作为第一件事,请将整数[]更改为int[]->内存使用量将是四分之一左右,性能将得到很好的提升


但总是有绩效问题:衡量,衡量,衡量,因为你的情况永远是特殊的。

双重探究。。。所有这些可怜的母牛。写一个有特定代码支持的特定问题,你就离得到认真关注又近了一步。双重探究。。。所有这些可怜的母牛。写一个有特定代码支持的特定问题,你就离得到认真关注又近了一步。
public class HashDouble1 {
  private Integer[] hashArray; 

  private int arraySize;

  private Integer bufItem; // for deleted items

  HashDouble1(int size) {
    arraySize = size;
    hashArray = new Integer[arraySize];
    bufItem = new Integer(-1);
  }



  public int hashFunc1(int key) {
    return key % arraySize;
  }

  public int hashFunc2(int key) {
    return 7 - key % 7;
  }

  public void insert(Integer key) {
        int hashVal = hashFunc1(key); // hash the key
        int stepSize = hashFunc2(key); // get step size
        // until empty cell or -1
        while (hashArray[hashVal] != null && hashArray[hashVal] != -1) {
          hashVal += stepSize; // add the step
          hashVal %= arraySize; // for wraparound
        }
        hashArray[hashVal]  = key; // insert item
      }





}