Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:10:29+00:00 2026-06-12T00:10:29+00:00

I have been struggling to understand how this works for a while in gdb

  • 0

I have been struggling to understand how this works for a while in gdb but I’m having a hard time understanding it. Basically there is an array (elements_) into which things are hashed, these things are pointers to structs containing certain hooks used for the chaining. Here is a sample struct:

struct foo
{
    Data  data;
    foo*  next;
    foo** prevNext;
};

then the hash table gets instantiated with

HashTable<foo> hash;

and it’s insertion function looks like this (i’ve ommitted the resizing and all for simplicity)

template <class T>
void HashTable<T>::insert(T* x)
{
    int bucket  = hashFunc(x->data);
    T** xPtr    = &elements_[bucket];
    x->next     = *xPtr;
    x->prevNext = xPtr;

    if (x->next)
        x->next->prevNext = &x->next;

    *xPtr = x;
}

and the removal is as follows

template<class T>
void HashTable<T>::remove(T* x)
{
    if (x->next)
        x->next->prevNext = x->prevNext;

    *x->prevNext = x->next;
}

And for reference the way it is searched is like this:

template<class T>
T* HashTable<T>::find(Data& data)
{
    int bucket = hashFunc(data);

    T* ptr = elements_[bucket];
    while (ptr != 0)
    {
        if(ptr->data == data)
            return ptr;
        ptr = ptr->next;
    }
    return 0;
}

I keep trying to follow insertion of 2-3 colliding elements (by setting the table size to be small to begin with) and deletions to see what the logic is but I’m not understanding it. Here is a diagram of what I think the removal operation (removing node 2) is doing, though it’s still a bit fuzzy in my head:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:10:30+00:00Added an answer on June 12, 2026 at 12:10 am

    Elements that fall into the same bucket are stored as a doubly-linked list (sort of).

    Lookup traverses that list until it finds an element with matching data value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for quite some time having been accustomed to
I have been struggling with this for a while now. given a set of
I have been struggling with this for a while and just can't work it
I have been struggling to understand some pieces of this code. It asks to
I have been struggling with this issue for a few hours now without understanding
Bits and bitmask are something I have been struggling to understand for a while,
I have been struggling with Core Data sigh so I decided to work this
I have been struggling with this error for more than two hours: error: aggregate
I have been struggling with encoding problems in MySQL for a while. I am
I have been struggling with this question for awhile now, and I haven't reached

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.