https://github.com/hawkkiller/snowflaker
Twitter's snowflake algorithm implementation in Dart. The Snowflake algorithm is a unique ID generator that was originally developed by Twitter. The algorithm generates 64-bit IDs that are composed of a timestamp, a worker ID, and a sequence number.
https://github.com/hawkkiller/snowflaker
Last synced: about 1 year ago
JSON representation
Twitter's snowflake algorithm implementation in Dart. The Snowflake algorithm is a unique ID generator that was originally developed by Twitter. The algorithm generates 64-bit IDs that are composed of a timestamp, a worker ID, and a sequence number.
- Host: GitHub
- URL: https://github.com/hawkkiller/snowflaker
- Owner: hawkkiller
- License: mit
- Created: 2023-06-08T17:04:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-26T10:34:19.000Z (almost 3 years ago)
- Last Synced: 2025-04-11T05:14:31.051Z (about 1 year ago)
- Language: Dart
- Homepage: https://pub.dev/packages/snowflaker
- Size: 44.9 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Snowflake ID Generator
A Dart library for generating unique, sortable ID strings using the Twitter's Snowflake algorithm.
## Features
* Thread-safe generation of unique IDs.
* Each ID contains a timestamp with millisecond precision.
* Customizable worker and datacenter identifiers.
## Usage
Add the following to your `pubspec.yaml` file:
```yaml
dependencies:
snowflaker: ^1.0.0
```
Then import the library:
```dart
import 'package:snowflaker/snowflaker.dart';
```
To generate a new ID, create a new instance of `snowflaker` and call its `nextId()` method:
```dart
// Create a new instance of snowflaker with a worker ID of 1 and a datacenter ID of 1.
final snowflaker = Snowflaker(workerId: 1, datacenterId: 1);
// Generate a new ID.
final id = snowflaker.nextId();
```