在制作我自己的可扩展散列项目时,如何让目录“指向”正确的存储桶?

问题描述

我已经阅读了有关创建可扩展哈希表 Extendable Hashing 的 wiki 页面。现在我正在尝试将其实现到程序中以更好地理解它,但我无法弄清楚如何将目录实际指向存储桶。

目录类:

int GlobalDepth = 1;
int directories[];

public Directory() {
    int temp = (int)Math.pow(2,GlobalDepth);

    loadDirectories(temp);

}

public void loadDirectories(int n) {
    for (int i = 0; i < n; i ++) {
        String BinaryKey = Integer.toBinaryString(i);
        String tempKey = BinaryKey.substring(0,this.GlobalDepth); // LSB
        int depthKey = Integer.parseUnsignedInt(tempKey);

        this.directories[i] = depthKey;

    }

}

public void increaseGlobalDepth() {
    this.GlobalDepth ++;

    loadDirectories((int)(Math.pow(2,this.GlobalDepth))); // This method might throw an error because i think im changing the array size illegally and should instead create a temp array and copy/equal that array to this.directories

}

桶类:

private SomeObject[] item; // Class I'm using to hold all the information of something
private int Key,MaxBucketsize,LocalDepth = 1;
//Bucket next;

public Bucket() {

}

public Bucket(int BucketSize) {
    this.item = new SomeObject[BucketSize]; // Initalises the number of items held in the bucket
    this.MaxBucketsize = BucketSize; // Stores the max number of items that can be held in the bucket

}


public SomeObject[] getobjects() {
    return this.item;

}

public boolean addobjects(int key,SomeObject item) {
    boolean inserted = false;

    for (int i = 0; i < this.MaxBucketsize; i ++) {
        if (this.item[i] == null) { // only inserts if there is an empty spot in the bucket
            this.item[i] = item;
            this.item[i].setKey(key);

            inserted = true;

            break;

        }

    }

    return inserted;

}

做完这一切之后,我不知道如何像在 wiki 页面中那样将这两个链接在一起。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)