Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: trouble linking directory to buckets in extendable hashing

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trouble linking directory to buckets in extendable hashing

    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.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: trouble linking directory to buckets in extendable hashing

    how to actually link the directory to the buckets.
    Can you describe what that means? How is the directory related to the buckets?

    What are the classes supposed to do? Do you have a test script (class with a main() method) for testing these classes?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: trouble linking directory to buckets in extendable hashing

    Extendable hashing as described on this wikipedia page: https://en.wikipedia.org/wiki/Extendible_hashing and https://www.geeksforgeeks.org/extend...roach-to-dbms/. I do have a main method but I don't have a method to actually implement this as I said, I have no idea how to link the directory to the buckets which is required to properly store the data and to test the program in some way.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: trouble linking directory to buckets in extendable hashing

    It looks like the link from a directory slot to a bucket would be a variable that contains a reference to a bucket object.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Password hashing & Salts
    By sci4me in forum Algorithms & Recursion
    Replies: 1
    Last Post: July 22nd, 2014, 07:36 AM
  2. Having Trouble Linking a method from another class!
    By blobby404 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 17th, 2014, 02:34 PM
  3. How to know size and number of buckets in bucket sort
    By IHeartProgramming in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 11th, 2012, 12:06 PM
  4. hashing / collisions
    By Herah in forum Java Theory & Questions
    Replies: 1
    Last Post: November 29th, 2011, 11:16 PM
  5. Doubling hashing, infinite loop?
    By vluong in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 8th, 2009, 01:26 AM