#id-generator #unique-id #sonyflake

wd_sonyflake

unique id generator by sonyflake

1 unstable release

0.0.1 Dec 7, 2020

#52 in #id-generator


Used in wd_tools

MIT/Apache

7KB
85 lines

Sonyflake 雪花算法

Overview

|--0--|--timestamp--|--node_id--|--count--|

|-- 1 --|---- 41 -----|-- 10 --|--12 --|

Example

use wd_sonyflake::SonyFlakeEntity;

fn main() {
    let sfe = SonyFlakeEntity::new_default();
    let start = std::time::Instant::now();
    for i in 0..1000000{
        let id = sfe.get_id();
        // println!("生成一条id:{:x}",id)
    }
    println!("一百万条id需要:{:?}s", start.elapsed().as_secs());
}

lib.rs:

Sonyflake 雪花算法

Overview

|--0--|--timestamp--|--node_id--|--count--|

|-- 1 --|---- 41 -----|-- 10 --|--12 --|

Example

use wd_sonyflake::SonyFlakeEntity;

fn main() {
    let sfe = SonyFlakeEntity::new_default();
    let start = std::time::Instant::now();
    for i in 0..1000000{
        let id = sfe.get_id();
        // println!("生成一条id:{:x}",id)
    }
    println!("一百万条id需要:{:?}s", start.elapsed().as_secs());
}

Dependencies

~1MB
~18K SLoC