I'm trying to implement my own extendable hashing method in my program to practice and better understand extendable hashing but after creating the bucket class and directory class and the hash function, I have no idea how to actually link the directory to the buckets.
Directory class
public class Directory { /* Instance Variables */ int GlobalDepth = 1; int directories[]; public Directory() { int temp = (int)Math.pow(2, GlobalDepth); loadDirectories(temp); } public void loadDirectories(int n) { int temp[] = new int[n * 2]; for (int i = 0; i < n; i ++) { String BinaryKey = Integer.toBinaryString(i); String tempKey = BinaryKey.substring(0, this.GlobalDepth); int depthKey = Integer.parseUnsignedInt(tempKey); temp[i] = depthKey; } this.directories = temp; } public void increaseGlobalDepth() { this.GlobalDepth ++; loadDirectories((int)(Math.pow(2, this.GlobalDepth))); }
Bucket class
public class Bucket { /* Instance Variables */ private SomeObject[] item; // class to hold all the required info 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[] getAllObjects() { return this.item; } public boolean addSomeObjects(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/null spot in the bucket this.item[i] = item; this.item[i].setKey(key); inserted = true; break; } } return inserted; }
So now that I have the 2 classes, how would i go about actually linking them together?
My bad if this is not the sub forum to ask this question in, just joined.