packages/library/odin-snowflake
o

odin-snowflake

c153c1clibrary

Twitter like snowflakes for Odin lang.

0 stars0 forksUnlicenseupdated 7 months ago
Open repo

Odin Snowflake

Generate Twitter like snowflake ID in Odin. These ID will never repeat themselves as they are time-based.

usage

import sf "../odin_snowflake"

main :: proc() {
    gen := sf.make_generator(
        // defaults to rand.int31_max(32)
        // range [0,31]
        datacenter_id = 1, 
        // defaults to rand.int31_max(32)
        // range [0,31]
        machine_id = 1,
        // defaults to 1288834974657
        // which is twitter's default
        custom_epoch = 1288834974657,
    )
    // its on the heap, you need to free it
    defer free(gen)

    for i in 1 ..= 10 {
        flake := sf.mkflake(gen)
        fmt.println(flake)

        // convert snowflake to a bit_field
        fmt.println(sf.Snowflake(flake))
    }
}
Package Info
Version
c153c1c
License
Unlicense
Author
@wht-src
Type
library
Forks
0
Created
7 months ago
Updated
7 months ago
Health
maintained
has releases
has readme
has license
Activity
last 56 weeks