I want to merge 2 or more hashtables together..It doesn't matter what the final form is, as long as I can iterate through it. Here the final form is an array.

So I have an unsigned long long as the key, the value is a string,int pair. Each key maps to a bin, each bin can have collisons. Instead of copying the entire hashtable into the array i copy it bin by bin, that way i will not need to iterate through the entire array. First I copy the first bin of the first hashtable into an array of Pairs, with the string and int as it's fields(the key is ignored)'

Something like

Class Pair{
char* s;
int frequency;
};

To add it to the array I would have something like this...

Pair pair
pair.s=string of the hashtable value
pair.s=integer of the hashtable value
array[index]=pair;

Then to merge the 1st bin of the 2nd hashtable into the array, I first check if the string of the value of the hashtable is already in the array, if it is I just update the int part of the class pair corresponding to the string that is in the array, if it isn't I add it to the array.

Then I go on to the next bin..copy the 2nd bin of the first hashtable to the array..then instead of iterating through the entire array to check something in the 2nd bin of the 2nd hashtable is in the array, I start searching from the array index where the first element of the 2nd bin was inserted into array.

The problem is even iterating that way is still pretty lengthy as each bin can contain 1000+ collisons and there are thousands of bins to go through.I want to avoid that. I was thinking since each key (which is a long long) is unique with each string, to set the offset at that key number to 1 if it is in the array, and 0 if it isn't. That way I only need to iterate through the array if it is in the array. The problem with that is a long long is simply too big. I can't allocate an array with that many bits...

Is there another way?

Recommended Answers

All 2 Replies

Why must you combine the tables if you only need to iterate through them, why not chain the iterations of th tables? I do not know exact way, but in Python I would use itertools.chain(sequence_of_dicts)

Why must you combine the tables if you only need to iterate through them, why not chain the iterations of th tables? I do not know exact way, but in Python I would use itertools.chain(sequence_of_dicts)

Oh my purpose for combining the hashtables is not to iterate through them. I put that as a requirement so i can write that data in the merged hashtable to file later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.