hash from long url to short url

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joe

    hash from long url to short url

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

    #2
    Re: hash from long url to short url


    "joe" <jcharth@gmail. comwrote in message
    news:af9ad0f2-7db0-476f-b14f-6697b9f2cf27@m2 3g2000hsc.googl egroups.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.


    Comment

    • santosh

      #3
      Re: hash from long url to short url

      Malcolm McLean wrote:
      >
      "joe" <jcharth@gmail. comwrote in message
      >
      news:af9ad0f2-7db0-476f-b14f-6697b9f2cf27@m2 3g2000hsc.googl egroups.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.

      Comment

      • Ben Bacarisse

        #4
        Re: hash from long url to short url

        "Malcolm McLean" <regniztar@btin ternet.comwrite s:
        "joe" <jcharth@gmail. comwrote in message
        news:af9ad0f2-7db0-476f-b14f-6697b9f2cf27@m2 3g2000hsc.googl egroups.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.

        Comment

        • Malcolm McLean

          #5
          Re: hash from long url to short url


          "Ben Bacarisse" <ben.usenet@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.


          Comment

          • CBFalconer

            #6
            Re: hash from long url to short url

            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

            Comment

            • joe

              #7
              Re: hash from long url to short url

              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...@yah oo.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.co m

              Comment

              • Flash Gordon

                #8
                Re: hash from long url to short url

                Malcolm McLean wrote, On 22/02/08 15:23:
                >
                "Ben Bacarisse" <ben.usenet@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.

                --
                Flash Gordon

                Comment

                • Default User

                  #9
                  Re: hash from long url to short url - TPA

                  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 >

                  Comment

                  • Ben Bacarisse

                    #10
                    Re: hash from long url to short url

                    joe <jcharth@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.

                    Comment

                    • Richard

                      #11
                      Re: hash from long url to short url - TPA

                      "Default User" <defaultuserbr@ 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.

                      Comment

                      • Antoninus Twink

                        #12
                        Re: hash from long url to short url - TPA

                        On 23 Feb 2008 at 20:37, Richard wrote:
                        "Default User" <defaultuserbr@ 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 "contributo rs" like these, who needs trolls?

                        Comment

                        Working...