{"id":24324741,"url":"https://github.com/uatuko/libxid","last_synced_at":"2026-05-27T18:32:41.405Z","repository":{"id":57665550,"uuid":"525267883","full_name":"uatuko/libxid","owner":"uatuko","description":"A globally unique id generator","archived":false,"fork":false,"pushed_at":"2023-08-09T06:35:22.000Z","size":41,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T04:43:31.920Z","etag":null,"topics":["cmake","cplusplus","cplusplus-17","cpp17","xid"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uatuko.png","metadata":{"files":{"readme":"README.md","changelog":"changelog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-16T07:06:27.000Z","updated_at":"2025-03-01T04:52:11.000Z","dependencies_parsed_at":"2022-09-26T20:41:30.116Z","dependency_job_id":null,"html_url":"https://github.com/uatuko/libxid","commit_stats":null,"previous_names":["uatuko/libxid"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/uatuko/libxid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uatuko%2Flibxid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uatuko%2Flibxid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uatuko%2Flibxid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uatuko%2Flibxid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uatuko","download_url":"https://codeload.github.com/uatuko/libxid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uatuko%2Flibxid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33579665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cplusplus","cplusplus-17","cpp17","xid"],"created_at":"2025-01-17T20:00:32.582Z","updated_at":"2026-05-27T18:32:41.387Z","avatar_url":"https://github.com/uatuko.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libxid\n\n[![license](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/uatuko/libxid/main/LICENSE)\n[![codecov](https://codecov.io/gh/uatuko/libxid/branch/main/graph/badge.svg?token=cLI6mChQ6V)](https://codecov.io/gh/uatuko/libxid)\n[![build](https://github.com/uatuko/libxid/actions/workflows/build.yaml/badge.svg?branch=main)](https://github.com/uatuko/libxid/actions/workflows/build.yaml)\n[![release](https://img.shields.io/github/v/release/uatuko/libxid)](https://github.com/uatuko/libxid/releases)\n\nA globally unique id generator.\n\n\u003e This is a c++ implementation of the Golang package found at: [https://github.com/rs/xid](https://github.com/rs/xid)\n\nXid uses MongoDB Object ID algorighm[^1] to generate globally unique ids with base32 serialzation to produce shorter strings.\n\n\n## Binary representation\n\n```\n+---+----+----+----+----+----+----+----+----+----+-----+-----+\n| 0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 |  10 |  11 |\n+---+----+----+----+----+----+----+----+----+----+-----+-----+\n \\----- time -----/ \\ machine id / \\- pid -/ \\--- counter ---/\n```\n\n- 4-byte value representing the seconds since the Unix epoch,\n- 3-byte machine identifier,\n- 2-byte process id, and\n- 3-byte counter, starting with a random value.\n\nThe binary representation of the id is compatible with MongoDB's 12 bytes Object IDs.\nThe string representation is using base32hex (w/o padding)[^2] for better space efficiency when stored in string form (20 bytes). The hex variant of base32 is used to retain the\nsortable property of the id.\n\n\n## Features\n\n- Size: 12 bytes (96 bits), smaller than UUID, larger than Twitter Snowflake[^3]\n- Base32hex encoded by default (20 chars when transported as printable string, still sortable)\n- Configuration free: there is no need to set a unique machine and/or data center id\n- K-ordered\n- Embedded time with 1 second precision\n- Unicity guaranteed for 16,777,216 (24 bits) unique ids per second and per host/process\n- Lock-free (unlike UUIDv1 and v2)\n\n\n## Comparison\n\n| Name        | Binary Size | String Size    | Features\n|-------------|-------------|----------------|----------------\n| [UUID]      | 16 bytes    | 36 chars       | configuration free, not sortable\n| [shortuuid] | 16 bytes    | 22 chars       | configuration free, not sortable\n| [Snowflake] | 8 bytes     | up to 20 chars | needs machine/DC configuration, needs central server, sortable\n| [MongoID]   | 12 bytes    | 24 chars       | configuration free, sortable\n| xid         | 12 bytes    | 20 chars       | configuration free, sortable\n\n[UUID]: https://en.wikipedia.org/wiki/Universally_unique_identifier\n[shortuuid]: https://github.com/stochastic-technologies/shortuuid\n[Snowflake]: https://blog.twitter.com/2010/announcing-snowflake\n[MongoID]: https://www.mongodb.com/docs/manual/reference/method/ObjectId/\n\n\n## Install\n### CMake\n\n```cmake\ninclude(FetchContent)\n\n#libxid\nFetchContent_Declare(libxid\n  URL      https://github.com/uatuko/libxid/archive/refs/tags/v0.1.0.tar.gz\n  URL_HASH SHA256=31589bb5274c9d25a8b6c49ee04a6c76151f10082e7feb13314be02a4b2d58c8\n)\nFetchContent_MakeAvailable(libxid)\n```\n\n```cmake\ntarget_link_libraries(\u003ctarget\u003e\n  PRIVATE\n    libxid::xid\n)\n```\n\n\n## Usage\n\n```c++\n#include \u003cxid/xid.h\u003e\n\nauto id = xid::next(); // generate the next id\nstd::string s = xid::next(); // generate the next id and convert it to a string\n```\n\n```c++\n// Get embedded info\nauto id = xid::next();\n\nid.time();\nid.machine();\nid.pid();\nid.counter();\n```\n\n```c++\n// Decode id strings\nauto id = xid::id(\"cc0a2mn6i1e6brmdbip0\");\nauto bytes = xid::id::decode(\"cc0aar76i1e6jr6no620\");\n```\n\n\n[^1]: https://www.mongodb.com/docs/manual/reference/method/ObjectId/\n[^2]: https://datatracker.ietf.org/doc/html/rfc4648#section-7\n[^3]: https://blog.twitter.com/2010/announcing-snowflake\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuatuko%2Flibxid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuatuko%2Flibxid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuatuko%2Flibxid/lists"}