| | |
c++ STL LIST function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
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....
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....
Local P ...
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
>>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?
#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?
Klatu Barada Nikto
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
•
•
•
•
>>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?
Local P ...
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
>>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.
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.
Klatu Barada Nikto
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
•
•
•
•
>>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
Local P ...
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
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!).
Klatu Barada Nikto
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
•
•
•
•
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!).
Last edited by localp; Nov 13th, 2008 at 4:04 pm.
Local P ...
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
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.
Klatu Barada Nikto
![]() |
Similar Threads
- problem about linked list. (C++)
- Sorting A Linked List--- Please help (C++)
- Response to time saving tips sticky (C++)
- C++ help ,am new to C++ ,PLZ Help ASAP (C++)
- Sorting arrays of pointers with function? (C)
- Function with pointer? (C++)
- using(STL)function object (bind2nd) with a user defined function object (C++)
Other Threads in the C++ Forum
- Previous Thread: plz help me
- Next Thread: Using keyboard presses to trigger internal speaker sound
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






