And then hash character takes in any string or character, single character, gives me back a number. Notice what I do.
然后哈希接受任何字符串或字母,单个字符,返回给我一个数字,注意我要做什么。
Characters are simple. Suppose you want to represent sets of strings, well you basically just generalize the hash function.
字母是是很简单的,如果你想表示一组字符串,基本上你要做的就是归纳出哈希函数。
I wanted to go back and leer at my strange Dickensian mother in the hash joint. I tingled all over from head to foot.
这时的我已经有些神志不清,真想回去看看,小饭馆里奇怪的幽灵一般的母亲。
Here, this is a more modern example with a little hash cafe next to it or something.
看这个,这个例子就更现代一些了,旁边还有些小咖啡馆杂然而列
Now at Harvard Thinks Big I happened to tear into this thing myself and it would seem a little pointless to re-hash that same demo so instead I thought I'd solicit an ideally sufficiently strong volunteer to come on up.
现在在“哈佛大梦想”的讨论会上,我反复思考这件事,觉得再演示一遍似乎意义不大,因此我想找一位合适的志愿者,上讲台来。
Second thing I want to note is, the little hash mark or the pound sign, that's identifying a comment.
我想要说的第二件事是,这个小斜杠或者是井字号,这是用来标注注释的。
You've got a picture of somebody's face, it's a million pixels. Each pixel has a range of values from zero to 256. I want to hash a face with some function into an integer.
你有一个人的脸部照片,它有一百万个像素,每个像素的值范围在0到256之间,我想用某个函数将一张脸部照片。
So what you typically do and a hash case is you design your code to deal with that.
你所需要做的就是通过设计你的代码,来解决上面的问题。
And then, if I want to find out if something's there, I do the same thing. But notice now, hash is converting the input into an integer.
然后,我想查找出某些元素是否在列表中,我做同样的事,但是现在注意,哈希是将输入转化成一个整数,所以,其思想是什么?
There's been a lot of work done on these over the years, but in fact, it's pretty hard to invent a good hash function. So my advice to you is, if you want to use something was a hash, go to a library. Look up a good hash function.
已经做过了很多的尝试和努力,但是事实是,很难发明出一个好的哈希函数,所以我给你们的建议是,如果你们想使用哈希功能,到函数库中查找一个好的哈希函数。
The good news is the elements in any one spot in a hash table are likely to be a small number, three, four, five.
好的一点是在哈希表中,任何一个存贮点上的元素数据是很小的,三个,四个,五个。
Well the idea of a hash, in fact, what's called a hash function is to have some way of mapping any kind of data into integers.
我要怎么做?实际上想法还是哈希,通过一个哈希函数,把任何种类的数据都映射成整数。
So let's look at the second example, all right, I keep doing that -- this piece of code from here to here gives me a way of now creating a hash table of size 256.
所以让我们来看一下第二个例子,好的,我继续做那件事,这段代码中从这里到这里,是创建一个大小为256的哈希表。
For those perhaps familiar with some of the jargon do we introduce what we call link lists and hash tables and tries, increasingly sophisticated data structures, that allow us to solve problems that are much bigger and much more interesting than the very familiar one that we started with here.
那些对编程的术语较熟悉的同学,我们会教授,链接列表,哈希表,以及日益复杂的数据结构,以便帮助我们解决其他的,比现在所学的更大也更有趣的问题。
So, what's the idea? If I know what my hash function does, it maps, in this case characters into a range zero to 256, which is zero to 255, I create a list that long, and I simply mark things.
我知道我的哈希函数做什么,在这个例子中,它将字母,映射成0到255的256个数字,我创建了一个这么长的列表,并且我只是简单的标志这些东西。
You try to design actually I'm going to come back to that in a second. It's like you're trying to use a hash function that spread things out pretty evenly. But the places you store into in those lists may have to themselves have a small list in there, and when you go to check something, you may have to do a linear search through the elements in that list.
你尝试着去设计,实际上过会儿我会回头讲解这个问题,类似于你需要用一个哈希函数,非常平均的将物体分发出去,但是在列表中你数据,映射到的地方可能会有自己的一小段列表,当你回头查找数据的时候,你可能需要在那一小段列表中做线性查找。
The answer is I can't. OK, in the simple case of integers I can, but in the case of something more complex like faces or fingerprints or passwords for that matter, it's hard to design a hash function that has completely even distribution, meaning that it takes any input into exactly one output spot.
答案是我不能,好吧,在简单的整数的例子中,我可以做到,但是在一些更复杂的场景中,比如面部,指纹,密码相关的问题中,很难设计一个哈希函数具备完全平均的分配,也就是说,做到对任一输入,可以准确地得到相应的唯一输出,因此在一个哈希问题中。
That in many cases, I can gain efficiency if I'm willing to give up space. Having said that though, there may still be a problem, or there ought to be a problem that may be bugging you slightly, which is how do I guarantee that my hash function takes any input into exactly one spot in the storage space?
普遍存在的增益和权衡,在许多的例子中,可以通过牺牲空间而得到效率方面的增加,话说回来,仍然存在一个问题,或者应该会有一个问题困扰着你,就是我如何保证我的哈希函数能够准确将,任一输入映射到相应的唯一的存贮空间中去?
应用推荐