Thread: Dynamic Hash Table Implementation?!?

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    9

    Dynamic Hash Table Implementation?!?

    Okay so this may be a little hard to follow, A because logic can be tough to get your head around without a visual aid & B i might not explain it the best haha.. so bare with me please...

    ok so I have 4 .cpp files with their corresponding .h files; (Person.cpp/h) (ListNode.cpp/h) (LinkedList.cpp/h) and (HashTable.cpp/h)

    The ListNode class contains a pointer to a persons data:

    Code:
    class ListNode{
        private:
            Person* data;
            ListNode* next;

    However there is multiple values stored in the person class... so I was wondering what would be the best method of storing the information in the (Person.cpp/h) implementation? Is there an effective way to store a collection of values which can later be individually accessed and manipulated?????


    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2016
    Posts
    9
    TO CLARIFY: i want the " Person* data " to return a collection of all the fields in the Person class (name, address, number etc.) so that i can access each field and change the data when adding a new person to the system ****THERE ARE MULTIPLE DATA TYPES
    Last edited by CodeTheLoad; 11-16-2016 at 10:35 AM.

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    You might want to sit down and familiarize yourself more with pointers. A pointer to a person means that when you dereference it, you get the person at that address. You can mutate the data pointed to it all you want. So there's nothing special you have to do, just define your person class and then you can dereference it like normal.

  4. #4
    Registered User
    Join Date
    Oct 2016
    Posts
    9
    will i still be able to dereference the pointer to Person if the data in the Person class is private? Or should i just make it public?

  5. #5
    Registered User
    Join Date
    Oct 2016
    Posts
    9
    Quote Originally Posted by MutantJohn View Post
    You might want to sit down and familiarize yourself more with pointers. A pointer to a person means that when you dereference it, you get the person at that address. You can mutate the data pointed to it all you want. So there's nothing special you have to do, just define your person class and then you can dereference it like normal.
    Originally I had made the Persons data private with the intention of using accessors and mutators in the .cpp file. If I was to make the data public in the Person.h file would that not make the Person.cpp file irrelevant?.. as i would no longer need any functions to access the data??

    ListNode files include the Person.h file btw

  6. #6
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Okay, before we go any further, we might need to take a step back. In C++ it's easy to start drowning in details. Before we go down that road, let's discuss your algorithm from a higher level.

    First and foremost, what are we trying to accomplish here? It seems to me like you're trying to create a Persons database which you can query and then use to mutate the Person's data. Is this correct?

  7. #7
    Registered User
    Join Date
    Oct 2016
    Posts
    9
    Yeah, that's pretty much the goal. I want to implement it as a chained hashtable, using the hash table as a table of buckets to store individual linked lists. Each List Node then has a pointer to a person (Person* data) and a next pointer.

    I have now made the Person class fields (string name, int number, string address etc) public so that the data can be mutated by using a pointer of the type person(Person* data), it seems to be working now.. well i haven't tested it yet but it has compiled alright anyway haha

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-23-2015, 08:49 PM
  2. Dynamic Hash Table Implementation
    By james123 in forum C Programming
    Replies: 1
    Last Post: 12-30-2009, 11:07 AM
  3. Debugging Hash Table Implementation
    By aim4sky in forum C Programming
    Replies: 9
    Last Post: 03-14-2008, 05:01 PM
  4. Hash Table implementation
    By supaben34 in forum C++ Programming
    Replies: 6
    Last Post: 09-26-2003, 12:48 PM
  5. hash table data structure implementation
    By sanju in forum C Programming
    Replies: 1
    Last Post: 09-27-2002, 05:06 AM

Tags for this Thread