哈希从长网址到短网址 [英] hash from long url to short url

查看:85
本文介绍了哈希从长网址到短网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好知道如何编写一个函数来创建一个只有
字母和数字的小网址。几乎总是独一无二的。谢谢。

Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.

推荐答案



" joe" < jc ***** @ gmail.com写信息

新闻:af ************************* ********* @ m23g2000 hsc.googlegroups.com ...

"joe" <jc*****@gmail.comwrote in message
news:af**********************************@m23g2000 hsc.googlegroups.com...

你好任何人都知道如何写一个函数来生成一个小网址

仅限字母和数字。几乎总是独一无二的。谢谢。
Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.



天然不可能将36 ^ N个唯一网址折叠为36 ^(N / 4)唯一网址

小网址。

但是我的网站上有一个哈希函数。它是在Basic Algorithms下的免费

章节之一。我建议你将字符串拆分为

2,并生成2个无符号长整数。发生碰撞的可能性非常小,以至于b $ b b可以忽略不计。然后使用模数运算减少到alpahanumeric。


-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm

It''s inherently impossible to collapse 36^N unique URLs to 36^(N/4) unique
tiny urls.
However there''s a hash function on my websites. It''s in one of the free
chapters under Basic Algorithms. I recommend that you split the string into
2, and generate 2 unsigned longs. The chance of a collision is so low as to
be negligible. Then use the modulus operation to reduce to alpahanumeric.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


Malcolm McLean写道:
Malcolm McLean wrote:

>

" joe" < jc ***** @ gmail.comwrote in message
>
"joe" <jc*****@gmail.comwrote in message



news:af ***************** ***************** @ m23g2000 hsc.googlegroups.com ...

news:af**********************************@m23g2000 hsc.googlegroups.com...


>大家好知道如何编写一个函数来创建一个只有字母和数字的小网址。几乎总是独一无二的。
谢谢。
>Hello anyone knows how to write a funtion to genereate a tiny url
with letters and numbers only. Something almost always unique.
THanks.



将36 ^ N个唯一网址折叠为36 ^(N / 4)本身是不可能的/>
独特的小网址。

但是我网站上有一个哈希函数。这是在Basic Algorithms下的免费章节中的一个。我建议您将

字符串拆分为2,并生成2个无符号长整数。

碰撞的可能性很小,可以忽略不计。然后使用模数

操作来减少到alpahanumeric。

It''s inherently impossible to collapse 36^N unique URLs to 36^(N/4)
unique tiny urls.
However there''s a hash function on my websites. It''s in one of the
free chapters under Basic Algorithms. I recommend that you split the
string into 2, and generate 2 unsigned longs. The chance of a
collision is so low as to be negligible. Then use the modulus
operation to reduce to alpahanumeric.



此外,谷歌搜索似乎会出现很多TinyURL生成器,但是在B中没有AFAICS,也许OP可以学习代码并用C重写。

Also a Google search seems to show up a lot of TinyURL generators though
not, AFAICS, in C. Maybe the OP can study the code and rewrite it in C.


" Malcolm McLean" < re ******* @ btinternet.comwrites:
"Malcolm McLean" <re*******@btinternet.comwrites:

" joe" < jc ***** @ gmail.com写信息

新闻:af ************************* ********* @ m23g2000 hsc.googlegroups.com ...
"joe" <jc*****@gmail.comwrote in message
news:af**********************************@m23g2000 hsc.googlegroups.com...

>你好任何人都知道如何编写一个函数来生成一个小网址只有字母和数字。几乎总是独一无二的。谢谢。
>Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.



它本身就不可能将36 ^ N个唯一网址折叠到36 ^(N / 4)

唯一的小网址。

但是我的网站上有一个哈希函数。这是在Basic Algorithms下的免费章节中的一个。我建议您将

字符串拆分为2,并生成2个无符号长整数。

碰撞的可能性很小,可以忽略不计。

It''s inherently impossible to collapse 36^N unique URLs to 36^(N/4)
unique tiny urls.
However there''s a hash function on my websites. It''s in one of the
free chapters under Basic Algorithms. I recommend that you split the
string into 2, and generate 2 unsigned longs. The chance of a
collision is so low as to be negligible.



我觉得这是一个坏主意[1]。 Bernstein哈希函数

(这是你的那个)网站使用unsigned long但是对于任何无符号整数类型都可以使用
。如果OP可以访问

更长的整数,那么简单地使用一个更长的整数

似乎比从字符串的两个部分生成两个哈希值更安全。


[1]我没有正式的论据来支持这个,只是感觉

,因为网址经常有类似的部分你浪费哈希

函数'如果你拆分字符串的混合能力。无论如何,即使

这里没有理由担心,为什么要承担风险 - 除非

当然,你没有更长的整数类型。


-

Ben。

I have a feeling this is a bad idea[1]. The Bernstein hash function
(which is the one on your) site uses unsigned long but will work just
as well with any unsigned integer type. If the OP has access to
longer integers, it seems safer to simply use a longer integer that
than generate two hashes from two parts of the string.

[1] I have no formal argument in support of this, just the feeling
that, since URLs often have similar parts you are wasting the hash
function''s mixing ability if you split the string. Anyway, even if
there is no reason to worry here, why take the risk -- unless, of
course, you don''t have longer integer types.

--
Ben.


这篇关于哈希从长网址到短网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆