473,397 Members | 2,084 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 from long url to short url

joe
Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.
Feb 22 '08 #1
11 3174

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

Feb 22 '08 #2
Malcolm McLean wrote:
>
"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.
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.
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.

Feb 22 '08 #3
"Malcolm McLean" <re*******@btinternet.comwrites:
"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.
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.
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.
Feb 22 '08 #4

"Ben Bacarisse" <be********@bsb.me.ukwrote in message
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.
You might well be right. If two URLs share the same introduction, which is
extremely plausible, then effectively you are wasting a long.

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

Feb 22 '08 #5
joe wrote:
>
Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.
Yes. No. You're welcome.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 22 '08 #6
joe
May be i could get the char value of each letter multiply it by the
position in the string and come up with a number. Just an idea.
On Feb 22, 2:31 pm, CBFalconer <cbfalco...@yahoo.comwrote:
joe wrote:
Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.

Yes. No. You're welcome.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account fromhttp://www.teranews.com
Feb 22 '08 #7
Malcolm McLean wrote, On 22/02/08 15:23:
>
"Ben Bacarisse" <be********@bsb.me.ukwrote in message
>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.
You might well be right. If two URLs share the same introduction, which
is extremely plausible, then effectively you are wasting a long.
There is also a significant possibility of two URLs sharing a
significant tail. E.g.
http://www.somesite/area/somewhere?p...t=prettyformat
--
Flash Gordon
Feb 22 '08 #8
joe wrote:
May be i could get the char value of each letter multiply it by the
position in the string and come up with a number. Just an idea.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>
Feb 22 '08 #9
joe <jc*****@gmail.comwrites:
Hello anyone knows how to write a funtion to genereate a tiny url with
letters and numbers only. Something almost always unique. THanks.
May be i could get the char value of each letter multiply it by the
position in the string and come up with a number. Just an idea.
[Top posting corrected]. That is one way, but there has been a lot of
study of how to turn a string into a number and your method has no
particular advantage over others that have been found to be useful.
The advice you've had to use a known hash function is good advice.

--
Ben.
Feb 23 '08 #10
"Default User" <de***********@yahoo.comwrites:
joe wrote:
>May be i could get the char value of each letter multiply it by the
position in the string and come up with a number. Just an idea.

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>
CBFalconer and Default User actively contributing to CLC in their own
inimitable manner again. Nice.
Feb 23 '08 #11
On 23 Feb 2008 at 20:37, Richard wrote:
"Default User" <de***********@yahoo.comwrites:
>joe wrote:
>>May be i could get the char value of each letter multiply it by the
position in the string and come up with a number. Just an idea.

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>

CBFalconer and Default User actively contributing to CLC in their own
inimitable manner again. Nice.
Yes - with "contributors" like these, who needs trolls?

Feb 24 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Damien Morton | last post by:
Ive been doing some investigation of python hashtables and the hash function used in Python. It turns out, that when running pystone.py, as much time is spent in string_hash() as is spent in...
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:
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
6
by: barcaroller | last post by:
I'm looking for a hash function (in C) that will convert a string of arbitrary length (but less than 1024 chars) to a reasonably-unique 16-bit short integer. Can anyone point me to such a hash...
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...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
11
by: merrittr | last post by:
Hi in the code below in the main the hash table from K&R example replaces a node when a collision occurs What I am trying to do is set it up to "chain" another structure beside the node that it...
1
by: TheCite | last post by:
I am trying to make a function to hash passwords with. Here is the code: Option Compare Database Option Explicit 'function declarations Private Declare Function CryptAcquireContext Lib...
2
by: joe shoemaker | last post by:
I would like to convert url into md5 hash. My question is that md5 hash will create collision at 2^64. If you do long(value,16), where value is the md5 hash string, would value returned from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.