|
-
July 25th, 2010, 09:51 PM
#1
hash table with negative number
Here when I talk about hash table, I mean it is simply an array and it has nothing to do with STL hash map. For example, there is an array, int a[] = {3, 5,6, 7, 11}. The key for hash table could be the elements of array a. What if there is negative item in the array, for example, int a[] = {3, -1, 5, 7, -6}? How'd I build a hash table based on this array? Thanks.
-
July 26th, 2010, 03:24 AM
#2
Re: hash table with negative number
Assuming int is 32 bits, how would you build a hash table for unsigned int a[] = {3, 4294967295, 5, 7, 4294967290}?
-
July 26th, 2010, 08:38 AM
#3
Re: hash table with negative number
Actually, my question is how to build a hash table for negative integer. Any idea? Thanks.
 Originally Posted by S_M_A
Assuming int is 32 bits, how would you build a hash table for unsigned int a[] = {3, 4294967295, 5, 7, 4294967290}?
-
July 26th, 2010, 12:58 PM
#4
Re: hash table with negative number
Well a negative number is just a positive number interpreted as being negative. I.e. a 32 bit signed integer set to -1 will have the same content as an unsigned int set to 4294967295 (0xFFFFFFFF). That's why I asked you how you would handle those numbers instead.
-
July 26th, 2010, 01:03 PM
#5
Re: hash table with negative number
Obviously it is not good to handle a negative numbge with a 2's complement because it will use too much space to build a hashtable. Basically I need a way to map a key as a negative number to a value in such a hash table.
 Originally Posted by S_M_A
Well a negative number is just a positive number interpreted as being negative. I.e. a 32 bit signed integer set to -1 will have the same content as an unsigned int set to 4294967295 (0xFFFFFFFF). That's why I asked you how you would handle those numbers instead.
-
July 26th, 2010, 02:10 PM
#6
Re: hash table with negative number
 Originally Posted by LarryChen
Obviously it is not good to handle a negative numbge with a 2's complement because it will use too much space to build a hashtable. Basically I need a way to map a key as a negative number to a value in such a hash table.
You just need to construct an appropriate hash function. I don't see what is the problem.
-
July 26th, 2010, 04:58 PM
#7
Re: hash table with negative number
How does hash function work with an array since my hash table is implemented on an array?
 Originally Posted by laserlight
You just need to construct an appropriate hash function. I don't see what is the problem.
-
July 27th, 2010, 12:52 AM
#8
Re: hash table with negative number
 Originally Posted by LarryChen
How does hash function work with an array since my hash table is implemented on an array?
Same idea as when you want to compute a hash value given a string.
-
July 27th, 2010, 01:00 AM
#9
Re: hash table with negative number
Would you please tell me how to compute a hash value given a string? Here hash table is implemented as an array and it has nothing to do with stl hash map. Thanks.
 Originally Posted by laserlight
Same idea as when you want to compute a hash value given a string.
-
July 27th, 2010, 10:15 AM
#10
Re: hash table with negative number
Hash function examples. Scroll to the bottom.
Viggy
-
August 18th, 2010, 01:52 PM
#11
Re: hash table with negative number
I know hash function. Which data structure would you use to store the keys and values? Thanks.
 Originally Posted by MrViggy
-
August 18th, 2010, 01:53 PM
#12
Re: hash table with negative number
One method is to use an array of lists.
Viggy
-
August 18th, 2010, 02:33 PM
#13
Re: hash table with negative number
What is array of lists? Would you mind giving me a simple example? Thanks.
 Originally Posted by MrViggy
One method is to use an array of lists.
Viggy
-
August 18th, 2010, 02:59 PM
#14
Re: hash table with negative number
An array, who's data type is a list:
Code:
std::vector <std::list<foo> >
Viggy
-
August 18th, 2010, 03:13 PM
#15
Re: hash table with negative number
Can you use hash function without using any of STL? I repeat my original quesiton. There is an array, int a[] = {3, -1, 5, 7, -6}. How'd I build a hash table based on this array without using any of STL? Thanks.
 Originally Posted by MrViggy
An array, who's data type is a list:
Code:
std::vector <std::list<foo> >
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|