i want to create a hash table ( independent rehashing ), using STL LIST...

in Independent rehashing we use a function to

we need to generate the index
then check if there is any collisions
if there is we need to rehash it
and then put it in to the hash table

then we gotta sort (alphabatical order), b4 presenting to the user..

wat r the STL member functions used for these, and also please send the header files also

please help ..

please be great enough to provide a sample code....

>>please send the header
#include<list>

>>STL member functions used
here's a listing of the member functions with examples:

http://www.cppreference.com/wiki/stl/list/start

>>then we gotta sort (alphabatical order), b4 presenting to the user..
On first blush that seems to defeat the purpose of the hash table?

>>please send the header
#include<list>

>>STL member functions used
here's a listing of the member functions with examples:

http://www.cppreference.com/wiki/stl/list/start

>>then we gotta sort (alphabatical order), b4 presenting to the user..
On first blush that seems to defeat the purpose of the hash table?

it is a string that i am planning to enter, so how am i going to generate the index of the word, and how to do the hashing and rehashing, are there any predifined functions for thses. ?

>>it is a string that i am planning to enter, so how am i going to generate the index of the word, and how to do the hashing and rehashing, are there any predifined functions for thses. ?

Not that I know of.

When I think of hash tables I think of the "index" as being some integer value determined by a hash function. The hash function is whatever you want it to be, maybe something like the sum of all the ASCII values for all the char of the string modulo 26 then add 1 to place the index in a range from 1 to 26 inclusive. The hash function can be whatever you wish, though. The index then indicates how far from an arbitrary spot (say the beginning of a list or the first element of an array) you go to enter the current element of the hash table. Given that many hash tables don't have an entry at every possible index, I tend to think of arrays rather than lists to create them, but I am not a big user of hash tables so I don't know if there is a prefered container on which to develop the table or not.

>>it is a string that i am planning to enter, so how am i going to generate the index of the word, and how to do the hashing and rehashing, are there any predifined functions for thses. ?

Not that I know of.

When I think of hash tables I think of the "index" as being some integer value determined by a hash function. The hash function is whatever you want it to be, maybe something like the sum of all the ASCII values for all the char of the string modulo 26 then add 1 to place the index in a range from 1 to 26 inclusive. The hash function can be whatever you wish, though. The index then indicates how far from an arbitrary spot (say the beginning of a list or the first element of an array) you go to enter the current element of the hash table. Given that many hash tables don't have an entry at every possible index, I tend to think of arrays rather than lists to create them, but I am not a big user of hash tables so I don't know if there is a prefered container on which to develop the table or not.

ok so , just imagine i entered the word flower, and its hash value is 5, and i go and insert in as follows ::::
push_front(num);//num is the value of the flower

so how am i going to store the word flower,,, and where is it going to be

Again, I'm not a routine user of hash tables. I would think if the word flower had a hash value of 5 and you were using a array/vector of strings called hashTable with size() 0f 100, then flower would be entered at hashTable[4]. If I were trying to use a list to do it then I would use a node that contained a string as a data member which is empty as a default value. I would check the length of the current list (using an appropriate variable to keep track of same) and if it were longer than 5 nodes, then I would start at head node, move to node 5 and if string value at node 5 was empty, then I'd assign flower to the string in node 5. Alternatively the node could have a string to hold the desired data and an int to keep track of the node number. Then I wouldn't need to keep a separate variable to keep track of the length of the list. If the list wasn't long enough to handle the current index value, then I would empty nodes to the list until it did. I would also consider looking at Narue's website called EternallyConfuzzled, or something like that. I seem to remember she had a section on hash tables there, but I may wrong (even if i am it's a good site to be aware of!).

Again, I'm not a routine user of hash tables. I would think if the word flower had a hash value of 5 and you were using a array/vector of strings called hashTable with size() 0f 100, then flower would be entered at hashTable[4]. If I were trying to use a list to do it then I would use a node that contained a string as a data member which is empty as a default value. I would check the length of the current list (using an appropriate variable to keep track of same) and if it were longer than 5 nodes, then I would start at head node, move to node 5 and if string value at node 5 was empty, then I'd assign flower to the string in node 5. Alternatively the node could have a string to hold the desired data and an int to keep track of the node number. Then I wouldn't need to keep a separate variable to keep track of the length of the list. If the list wasn't long enough to handle the current index value, then I would empty nodes to the list until it did. I would also consider looking at Narue's website called EternallyConfuzzled, or something like that. I seem to remember she had a section on hash tables there, but I may wrong (even if i am it's a good site to be aware of!).

is there a STL function where we can find if an index is already present in the list, and returns true or false, based on the result .

If you want me to be bombastic, the answer is no. If yoy want me to be more user friendly, the answer is, not that I know of, at least in the way I interpret your question. STL lists do have a size() function that will return the number of nodes in the list. If the index coincides with the distance from the first node, begin, then if the desired index number is less than the return value of size(), then the node at that location will exist. But even then, it doesn't say if there is anything in that node, or if it is blank/empty/default value.

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.