473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Hash table

Hello,

Does anyone has to face the problem of hashing a string of 12 characters
AND avoid any collision?

I'm looking for some algorithm who could return a good (small) hash
value for any string of 12 characters.

Do you have any idea?

Marty
Nov 21 '05 #1
7 1315
Marty <re***@to.forum> wrote:
Does anyone has to face the problem of hashing a string of 12 characters
AND avoid any collision?

I'm looking for some algorithm who could return a good (small) hash
value for any string of 12 characters.


For 12 characters to have a non-colliding hash, you'll need more than
24 bytes of hash. There are various ways of making it non-colliding -
an identity hash would do, to start with, if your one goal is to avoid
collisions. You obviously can't have a shorter hash and have no
collisions - there are too many strings and not enough possible hash
values! The point of a hash is usually to take a large amount of data
and hash it into a smaller value which is *unlikely* to collide with
that created by a different chunk of source data - but once you specify
that collisions mustn't occur at all, hashing just doesn't work as a
concept.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 21 '05 #2
Thanks Jon,

Ok, I can handle collisions. Where can I look to learn this identity
hash algorithm?

Regards,

Marty
Jon Skeet [C# MVP] wrote:
Marty <re***@to.forum> wrote:
Does anyone has to face the problem of hashing a string of 12 characters
AND avoid any collision?

I'm looking for some algorithm who could return a good (small) hash
value for any string of 12 characters.

For 12 characters to have a non-colliding hash, you'll need more than
24 bytes of hash. There are various ways of making it non-colliding -
an identity hash would do, to start with, if your one goal is to avoid
collisions. You obviously can't have a shorter hash and have no
collisions - there are too many strings and not enough possible hash
values! The point of a hash is usually to take a large amount of data
and hash it into a smaller value which is *unlikely* to collide with
that created by a different chunk of source data - but once you specify
that collisions mustn't occur at all, hashing just doesn't work as a
concept.

Nov 21 '05 #3
Marty <re***@to.forum> wrote:
Ok, I can handle collisions.
In that case I suggest you use String.GetHashCode(), which should be
fine.
Where can I look to learn this identity hash algorithm?


That was sort of a joke. It's a "hash algorithm" which doesn't change
the data at all - your 12 characters end up as 24 bytes, maybe with a
25th being the length (and 0 padding if the length is less than 12
characters). It's not useful as a hash algorithm, trust me.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 21 '05 #4
That was sort of a joke. It's a "hash algorithm" which doesn't change
the data at all - your 12 characters end up as 24 bytes, maybe with a
25th being the length (and 0 padding if the length is less than 12
characters). It's not useful as a hash algorithm, trust me.


Ok I see, as you said it is not useful. I'll go ahead with the
string.getHash ...

Have a nice day! :)

Marty

Nov 21 '05 #5
From what I recall, make your hash table size like this:
find the lowest prime number greater than 2*n (where n is number of
elements)
Then use quadratic collision handling.

"Marty" <re***@to.forum> wrote in message
news:oX6Vc.39819$fz2.1697@edtnps89...
Hello,

Does anyone has to face the problem of hashing a string of 12 characters
AND avoid any collision?

I'm looking for some algorithm who could return a good (small) hash
value for any string of 12 characters.

Do you have any idea?

Marty

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 21 '05 #6
Tom
If you can't have a collision at all you need a different algorythim.
Use a LMV or a CRC32 Checksum if the default GetHashCode is not good
enough. Otherwise use a MD5 or SHA has if you are parnoid about
collsions. However they still can happen so you still need to take
that into consideration.
Nov 21 '05 #7
Finally I've handled the collisions. I've been using the getHashCode
wich I applied another transformation wich give me a small hash key.

I'm curious about the algorithm that you specified, I'll have a look.

Thanks you!
Marty

Tom wrote:
If you can't have a collision at all you need a different algorythim.
Use a LMV or a CRC32 Checksum if the default GetHashCode is not good
enough. Otherwise use a MD5 or SHA has if you are parnoid about
collsions. However they still can happen so you still need to take
that into consideration.

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pelo GANDO | last post by:
Hi everybody ! I am a beginner in C++. I am looking for a (simple if it's possible) source code in C++ about hash table... Thank you ! Pelo
34
by: pembed2003 | last post by:
Hi All, Does C++/STL have hashtable where I can do stuff like: Hashtable h<int>; h.store("one",1); h.store("two",2); and then later retrieve them like:
7
by: Matthias Käppler | last post by:
Hi, I need to store objects of a FileInfo class containing information about a specific file. I can uniquely identify these files by their serial number. I thought it would be a good idea to use...
2
by: Ravi | last post by:
Hi, I am working on a winform app. I need to use an object which can store some information(key/value pairs) and also can be acessed by multiple threads(read/write). From what I heard Hash table...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
44
by: gokkog | last post by:
Hi there, There's a classic hash function to hash strings, where MULT is defined as "31": //from programming pearls unsigned int hash(char *ptr) { unsigned int h = 0; unsigned char *p =...
11
by: Douglas Dude | last post by:
how much time does it take to lok for a value - key in a hash_map ? Thanks
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
1
by: jacob navia | last post by:
Everybody knows that hash tables are fast. What is less known is that perfect hash tables are even faster. A perfect hash table has a hash function and a table layout that avoids collisions...
6
by: j1mb0jay | last post by:
I am currently working on a dictionary populating program. I currently have a socket connection my local news server and am trawling through all of the articles looking for new words. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.