开发者

How to hash a 32bit int to 10bit int? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center开发者_开发百科. Closed 11 years ago.

How to hash a 32bit unsigned int(0~4294967295) to 10bit unsigned int(0~1023)? least collisions and fast are important.Please write samples in C/C++ if convenient.

Sorry, I didn't ask in a good way, this is not my homework. Maybe the question background would be helpful. I'm writing a server, this server must handle < 1024 connections from every single client. every client has its independent IP address, stored as 32bit unsigned int.That's how the question goes from.


Under certain conditions (like having to hash at most 2^10 known items), you can have no collisions. For more speed, tolerating a bit of collision might help. More about that here http://en.wikipedia.org/wiki/Perfect_hash_function

GNU Perfect Hash Function Generator http://www.gnu.org/software/gperf/

A cheap, low-size key hashing is Pearson Hashing http://en.wikipedia.org/wiki/Pearson_hashing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜