Cant Solve Seperate Chaining for hash map

I am trying to add a word into a node, into a map. insertAsFirst takes care of single linked list details, while i am doing what i know how to do to access the elements of a map.
This is what i have. just to know how to make this work would be great.
1
2
3
4
std::pair <unint,chainBucket> b;
		b.first= inputHash;
b.second.bucketList->insertAsFirst(text);//causes a read access violation
		chainingTable.emplace(b);

Would try to link remaining code but it's a lot and repo is private
Last edited on
What is b.second.bucketList pointing to?
Your link doesn't work.
You made a couple of small mistakes with your code tags. Your opening tag needs to have a lower case "c", and your closing tag needs to have square brackets rather than curly braces.

Thanks for trying to use code tags. Please edit your initial post and fix these minor errors.
B.second points to the container in the map named bucket list
Without seeing your chainBucket header file or code for the chainBucket constructors, I'm guessing that chainBucket::bucketList is a pointer to a list that is never instantiated allocated. You have a pointer populated with garbage that you are trying to dereference.

You need to do something like

b.second.bucketList = new std::list<Bucket>;

Of course, I'm guessing that it's a std::list and that it contains objects of type Bucket.

It's very difficult to debug code we can't read. When your repo is huge and private, create a minimal example program that exhibits the incorrect behavior you are seeing, and post that. Make it as easy as possible for us to help you.
Last edited on
Topic archived. No new replies allowed.