Coder Social home page Coder Social logo

snow_flake's Introduction

snow_flake

snow_flake算法golang实现

算法介绍

将64bit的二进制数字分成若干部分,每一部分存储有特定含义的数据,比如说时间戳、机器ID、序列号等等,最终生成全局唯一的有序ID。 用41位表示时间戳(大概可以支撑pow(2,41)/1000/60/60/24/365年,约等于69年),10位表示机器ID(可以继续划分为 2~3 位的 IDC 标示,可以支撑 4 个或者 8 个 IDC 机房,和7~8 位的机器 ID,支持 128-256 台机器,12位表示序列号(代表着每个节点每毫秒最多可以生成 4096 的 ID)

使用示例

import "github.com/hhq163/snow_flake/gen_id"

node, err := gen_id.New(13)
if err != nil {
    fmt.Println(err)
    return
}
id := node.GenId()

snow_flake's People

Contributors

hhq163 avatar

Stargazers

 avatar

Watchers

 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.