Code Monkey home page Code Monkey logo

short-url's Introduction

短链接生成算法

usage

import "ShortUrlGenerator"

result, err := ShortUrlGenerator.Transform("www.baidu.com")
if err != nil {
     fmt.Println(err)
     return
}

algorithm

  1. 将原长链接进行md5校验和计算,生成32位字符串
  2. 将32位字符串每8位划分一段,得到4段子串。将每个字串(16进制形式)转化为整型数值,与0x3FFFFFFF按位与运算,生成一个30位的数值
  3. 将上述生成的30位数值按5位为单位依次提取,得到的数值与0x0000003D按位与,获取一个0-61的整型数值,作为从字符数组中提取字符的索引。得到6个字符就生成了一个短链
  4. 4段字串共可以生成4个短链

short-url's People

Contributors

by-zhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.