From f43327aa00f78d87e2bf7025639ee00132eee27a Mon Sep 17 00:00:00 2001 From: cbax Date: Tue, 24 Sep 2024 17:44:29 -0400 Subject: [PATCH] wrote spec --- .gitignore | 1 + Cargo.toml | 8 ++++++++ README.md | 29 +++++++++++++++++++++++++++++ src/lib.rs | 14 ++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..665680c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "icechip" +version = "0.1.0" +edition = "2021" +repository = "https://git.cbax.dev/icechip" +license = "MIT OR Apache-2.0" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ae52e3d --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Icechip + +A snowflake library that actually does what it is supposed to. + +Adheres to the twitter specification, but also has an improved mode. + +## Twitter Specification +| u64 or i64 | | | | +|:-:|:-:|:-:|:-:| +| bits 0-40 | bits 41-51 | bits 51-62 | 63 | +| time since an epoch in ms | machine id | sequence number | sign | + +## Enhanced Specification + +Utilizes a 64 bit unsigned integer, moves the now spare sign bit and one sequence bit to the machine ID. + +| u64 ||| +|:-:|:-:|:-:| +| 0-40 | 41-52 | 53-63 | +| time since an epoch in ms | machine id | sequence number | + +## Extended Enhanced Specification + +Utilizes a 128 bit unsigned integer. 32bit machine id, 32bit sequence number. (*Ought to be enough for anybody™*) + +| u128 ||| +|:-:|:-:|:-:| +| 0-63 | 64-96 | 96-127 | +| full unix timestamp ms | machine id | sequence number | diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +}