Let’s say I have a:
std::vector<std::list<Node> >
And let’s say Node is:
class Node {
Node* next;
int data;
};
The vector cells correspond to hash function values for fast look-ups. The idea is you insert your elements to the vector, but still chain them together with the Node-> next member. So you have a list where the elements can efficiently be looked up by key using a hash function to find the correct vector cell to start from.
Anyway, all that aside. My question is:
Can I have my Node::next pointers point to other nodes in a list (be it the same one, or another one from a different vector cell) without causing problems? I wasn’t sure if the standard library implementation of a list would allow this. I seem to be running into problems (my code’s not accessible here) and I wanted to see if this could be the cause.
If you want it to point to other nodes in the list, that’s totally doable, yes. However, I would propose a different design: a
std::list<int>and astd::unordered_map<int, std::list<int>::iterator>, both members of a class who’s only purpose is to keep the two containers synchonized. This should be easier, safer, and faster than (my interpretation of) your current plan.Adding and removing objects to both lists is a breeze: