产生唯一编号来自char * [英] Generate unique no. from char*
本文介绍了产生唯一编号来自char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成唯一的编号.或char [400]中唯一的键.
因此,请告诉我任何产生唯一编号的技术或算法.或来自char [400]的键
在此先感谢:)
解决方案
一般来讲,没有办法做到,我的意思是char[400]
本身是理论上更简单的唯一键(如果您不这样做的话)
如果您需要通用的字符串哈希函数,请在此站点上查看djb2哈希: ^ ].如果我没记错的话,该通用字符串哈希函数也用在Java中.但是在先前解决方案的注释中,人们已经指出:char [400]已经是一个400 * 8的位数字,并且您不能为前一个更大的集合中的每个成员生成用更少的位表示的唯一数字.这是您必须确保正在使用的哈希函数在通常使用的输入数据集上没有很多冲突的地方.如果您不完全知道输入字符串的内容,那么通用djb2哈希对您来说将是个不错的选择.但是,例如,如果您知道您的字符串将包含0到2 ^ 32之间的数字的文本表示形式,那么将字符串转换为整数的函数就是一个完美的哈希函数(无冲突),但是要实现这一点,我们需要知道关于输入数据的一些信息(例如压缩算法).正如先前的海报所指出的那样,散列和压缩有很多共同点.散列可以提高一些简单的数据结构(如设置和映射)的性能,其中一些操作包括搜索关键字.通常通过对已排序项目列表进行二分半来完成搜索,但是如果您的哈希函数没有很多冲突(用英语,您没有很多冲突),则使用哈希可以实现更好的性能.具有相同散列的项目).
Hi,
I want to generate unique no. or key from char[400] which is unique.
So please tell me any technique or algoritm to generate unique no. or key from char[400]
Thanks in advance :)解决方案Genrally speaking there is no way to do that, I mean thechar[400]
itself is the simpler theoretically possible unique key if you don''t put constraints on your requirements.
If you need a general purpose string hash function then check out the djb2 hashing on this site: http://www.cse.yorku.ca/~oz/hash.html[^]. If I remember right this general purpose string hash function is used in java as well. But in the comments of the previous solution the guys already pointed out: char[400] is already a 400*8 bit number, and you can not generate a unique number represented in less bits for each member of the previous much bigger set. This is where you have to make sure that the hash function you are using doesn''t have a lot of collisions on the set of input data you are usually using. If you don''t exactly know what is the content of your input strings, then the general purpose djb2 hash will be nice for you. But for example if you know that your strings will contain the textual representation of numbers between 0 and 2^32, then a function that converts the string to integer is a perfect hash function (without collisions), but to achieve this we need to know something about the input data (like with compression algorithms). Hashing and compression have a lot in common as a previous poster pointed out. Hashing can improve the performance of some simple data structures like set and map where some operations include searching for a key. Searching is usually done by performing binary halving on a list of sorted items, but with hashing you can achieve much better performance if your hash function doesn''t have a lot of collisions (in english, you don''t have a lot of items with the same hash).
这篇关于产生唯一编号来自char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文