flocon

0.0.3 • Public • Published

flocon

64-bits unique ID generator for Node.js written in C++.

Due to Javascript limitations to handle 53 bits Integer, this module returns a 64 bits integer using a String representation.

flocon is meant to be used with mongoose and mongoose-long but feel free to use it with any other database.

Disclaimer

This is an experimental module. We strongly discourage you to use it production for the moment since we don't have tested it enough.

Despite, if you want to use and contribute to this module, your help is welcome!

Requirements

This module requires OS X 10.7 (or later) and Xcode 4.5 (or later) to be built.

Linux support is plan to be added in a near future.

Installation

npm install flocon --save

Usage

var flocon = require('flocon');
var id = flocon.snow();

flocon.snow()

Returns a Snowflake-inspired 64-bit IDs String object constructed using:

Input Size Comment
Time (milliseconds) 41 bits Time elapsed since epoch, hardcoded to January 1st, 2013.
Process ID 10 bits Process ID that is generating the 64-bits ID.
Can handle up to 1024 different process ID.
Counter 13 bits Incremental value starting from 0 and re initialised every ms.
Can generate 8192 per process per ms.
`.snow()` can generate a total of `18,446,744,073,709,551,616` values.

Tests

npm test or check inside bench for more tests.

References

Licence

The MIT License (MIT)

Copyright (c) 2013 Yosee <opensource@yosee.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i flocon

Weekly Downloads

1

Version

0.0.3

License

MIT

Last publish

Collaborators

  • amarcadet