![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | something better than String.getHashCode On Jun 27, 7:12*am, "buu" <a...@xxxxxx> wrote: Quote: > You're right... > but, what if I want to check if some name & address exist, and by that > 'hash-key' there are some entries in dictionary wich are same by the key, > but not same by the content? you'll need a dictionary for each kind of key you want to look things up by. Jon |
My System Specs![]() |
| | #2 (permalink) |
| | Re: something better than String.getHashCode buu <aha@xxxxxx> wrote: Quote: > I'm using getHashCode sub from String object, but sometimes it gives me > duplicate values for different strings. Quote: > Difference is always when there are some numbers in strings. > > Is there any better/new getHash code function or any way to do some better > hashing? "source" values than "hash" values (as there clearly are in the case of strings hashing to any fixed size hash). If you want to use a hash for integrity checking etc you should use the classes derived from System.Security.Cryptography.HashAlgorithm - but if it's just for a hash table or similar structure, then GetHashCode should be absolutely fine. What's your actual use case? -- Jon Skeet - <skeet@xxxxxx> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon_skeet C# in Depth: http://csharpindepth.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: something better than String.getHashCode "Jon Skeet [C# MVP]" <skeet@xxxxxx> wrote in message news:MPG.22ce010d61403b4edc2@xxxxxx Quote: > buu <aha@xxxxxx> wrote: Quote: >> I'm using getHashCode sub from String object, but sometimes it gives me >> duplicate values for different strings. > Yes, it will. > Quote: >> Difference is always when there are some numbers in strings. >> >> Is there any better/new getHash code function or any way to do some >> better >> hashing? > Hashing will always give duplicate values when there are more potential > "source" values than "hash" values (as there clearly are in the case of > strings hashing to any fixed size hash). > > If you want to use a hash for integrity checking etc you should use the > classes derived from System.Security.Cryptography.HashAlgorithm - but > if it's just for a hash table or similar structure, then GetHashCode > should be absolutely fine. > > What's your actual use case? > > -- > Jon Skeet - <skeet@xxxxxx> > Web site: http://www.pobox.com/~skeet > Blog: http://www.msmvps.com/jon_skeet > C# in Depth: http://csharpindepth.com be best to search at the way to create a hashCode of that string and to use as a key in a dictionary. It's good, because it's fast, but it gives me duplicate hashCodes sometimes... |
My System Specs![]() |
| | #4 (permalink) |
| | Re: something better than String.getHashCode buu <aha@xxxxxx> wrote: Quote: > I have a collection of Strings (names & addresses together) wich I found to > be best to search at the way to create a hashCode of that string and to use > as a key in a dictionary. > It's good, because it's fast, but it gives me duplicate hashCodes > sometimes... the whole point of dictionaries! The dictionary is going to take the hash code and use that itself (without assuming it's going to be unique) - why do you feel the need to take a hash yourself to start with? -- Jon Skeet - <skeet@xxxxxx> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon_skeet C# in Depth: http://csharpindepth.com |
My System Specs![]() |
| | #5 (permalink) |
| | Re: something better than String.getHashCode Buu, I don't know if you use this in a kind of batch process, otherwise remember that any interaction with a user will const much more time then you can win with any optimalizing of methods you describe now. A user will almost for sure not see the by you gained time by this. Cor "buu" <aha@xxxxxx> schreef in bericht news:1214511058.992007@xxxxxx Quote: > > "Jon Skeet [C# MVP]" <skeet@xxxxxx> wrote in message > news:MPG.22ce010d61403b4edc2@xxxxxx Quote: >> buu <aha@xxxxxx> wrote: Quote: >>> I'm using getHashCode sub from String object, but sometimes it gives me >>> duplicate values for different strings. >> Yes, it will. >> Quote: >>> Difference is always when there are some numbers in strings. >>> >>> Is there any better/new getHash code function or any way to do some >>> better >>> hashing? >> Hashing will always give duplicate values when there are more potential >> "source" values than "hash" values (as there clearly are in the case of >> strings hashing to any fixed size hash). >> >> If you want to use a hash for integrity checking etc you should use the >> classes derived from System.Security.Cryptography.HashAlgorithm - but >> if it's just for a hash table or similar structure, then GetHashCode >> should be absolutely fine. >> >> What's your actual use case? >> >> -- >> Jon Skeet - <skeet@xxxxxx> >> Web site: http://www.pobox.com/~skeet >> Blog: http://www.msmvps.com/jon_skeet >> C# in Depth: http://csharpindepth.com > I have a collection of Strings (names & addresses together) wich I found > to be best to search at the way to create a hashCode of that string and to > use as a key in a dictionary. > It's good, because it's fast, but it gives me duplicate hashCodes > sometimes... > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: something better than String.getHashCode "Jon Skeet [C# MVP]" <skeet@xxxxxx> wrote in message news:MPG.22ce13419c129527dc4@xxxxxx Quote: > buu <aha@xxxxxx> wrote: Quote: >> I have a collection of Strings (names & addresses together) wich I found >> to >> be best to search at the way to create a hashCode of that string and to >> use >> as a key in a dictionary. >> It's good, because it's fast, but it gives me duplicate hashCodes >> sometimes... > You should use the string itself as the key in the dictionary. That's > the whole point of dictionaries! The dictionary is going to take the > hash code and use that itself (without assuming it's going to be > unique) - why do you feel the need to take a hash yourself to start > with? > > -- > Jon Skeet - <skeet@xxxxxx> > Web site: http://www.pobox.com/~skeet > Blog: http://www.msmvps.com/jon_skeet > C# in Depth: http://csharpindepth.com but, what if I want to check if some name & address exist, and by that 'hash-key' there are some entries in dictionary wich are same by the key, but not same by the content? |
My System Specs![]() |
| | #7 (permalink) |
| | Re: something better than String.getHashCode On Jun 27, 7:12*am, "buu" <a...@xxxxxx> wrote: Quote: > You're right... > but, what if I want to check if some name & address exist, and by that > 'hash-key' there are some entries in dictionary wich are same by the key, > but not same by the content? you'll need a dictionary for each kind of key you want to look things up by. Jon |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| object.GetHashCode()? | .NET General | |||
| Find a string within a variable string | PowerShell | |||
| problems with $var | select-string -pattern $string -q | PowerShell | |||
| How export-csv deals with string versus string[] | PowerShell | |||
| String PRODUCT_NAME was not found in string table | Vista General | |||