473,397 Members | 1,969 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,397 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
Jul 21 '05 #1
7 1369
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
Jul 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.

Jul 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
Jul 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

Jul 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
Jul 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.
Jul 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.

Jul 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.