Coder Social home page Coder Social logo

noritama's Introduction

NoritamaFlake

  • NoritamaFlake is a library that generates decentralized and K-ordered id, affected by SnowFlake and ObjectId(Mongo-id)
  • Implemented in pure Rust

wercker status MIT licensed Rust Version

Key features

  • Globally unique
  • K-ordered
  • Decentralized
    • local ip is cluster safe
    • multi process
  • Configuration free
  • Compact representation
    • URL-safe

[TODO] Specification

[timestamp:40bit][sequence:16bit][machine-id:32bit][process-id:8bit]

hex sample: 0677c8ecd600007f0000014a

[TODO] Limitation

  • Expiration date is 34 years from epoch

Usage

[WIP] Library

  • Issue a new id(use default Epoch)
//! ```cargo
//! [dependencies]
//! noritama = { git = "https://github.com/watawuwu/noritama" }
//! ```

use noritama::flake::*;
use noritama::flaker::*;

// create client
let flaker: Flaker = Flaker::new().unwrap();

// create id
let flake : Flake  = flaker.id().unwrap();
let id    : String = flake.hex();
  • Specify the epoch
//! ```cargo
//! [dependencies]
//! noritama = { git = "https://github.com/watawuwu/noritama" }
//! time     = "*"
//! ```

use noritama::flake::*;
use noritama::flaker::*;
use time::*;

// create client
let epoch : Tm     = time::now;
let flaker: Flaker = Flaker::new_with_epoch_timestamp(epoch).unwrap();

// create id
let flake : Flake  = flaker.id().unwrap();
let id    : String = flake.hex();

[WIP] Command line

  • Help
$ noritama -h
Noritama produces k-sorted ids. 0.1
watawuwu <[email protected]>
Noritama produces k-sorted ids.

USAGE:
    noritama [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -d, --decode <decode>              decoded hexed id
    -s, --start-epoch <start-epoch>    epoch used for internal timestamp
  • Issue a new id
$ noritama
0677c8ecd600007f0000014a

  • Decode id
$ noritama -d 0677c8ecd600007f0000014a
hex: 0677c8ecd600007f0000014a([6, 119, 200, 236, 214, 0, 0, 127, 0, 0, 1, 74]), unix_ts: 1485693060310, internal_ts: 27779460310, seq: 0, mid: 2130706433, pid: 74, start_epo: 1457913600000

[TODO] Comparison

Name Bit Representation Configuration Sortable Feild
UUID 128bit 36chars(16base) free no timestamp(60bit):
=>3653 years
clock sequence(14bit):
=>random + inc
node(40bit):
=>MAC address
Cassandra UUID(v1?) 128bit 36chars(16base) free no timestamp(60bit):
=>3653 years
clock sequence(14bit):
=>random + inc
node(40bit):
=>IP address
ObjectId
(mongo-id)
96bit 24chars[16base] free yes timestamp(32bit):
=>second
machine-id(24bit):
process-id(16bit)
counter(24bit)
Snowflake 64bit 20chars(10base) machine/DC yes timestamp(41bit)
=>69 year
machine-id(5bit):
=>central
process-id(5bit)
counter(12bit)
Flake(by Erlang) 128bit 18chars(62base) no yes timestamp(64bit)
worker-id(48bit):
=>MAC Address
sequence(16bit)
NoritamaFlake 96bit 24chars(16base) no yes timestamp(40bit):
=>34 year
sequence(16bit):
=>inc
machine-id(32bit):
=>ip address(ip4)
process-id(8bit)

noritama's People

Contributors

3bi 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.