-
Notifications
You must be signed in to change notification settings - Fork 0
feat: re-add ElementId as UUID v5 across primitives #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5fdabb
feat: SHA-1, UUID v5, and ElementId-as-UUIDv5 foundation
vieiralucas 59ce1b8
feat: wire ElementId into Counter/Register/Map, helpers derive, merge…
vieiralucas 25e451c
fix: uuid_parse contract, sha1.h system header, uuid_v5_update size_t…
vieiralucas 6152edc
fix(uuid): chunk uuid_v5_update to handle len > UINT32_MAX
vieiralucas 958e09e
fix: harden sha1 endian selection, include elementid.h in element.h a…
vieiralucas 2989086
fix(sha1): make sha1_endian static to keep symbol TU-local
vieiralucas 422d990
fix(elementid): include stdbool/stddef/stdint explicitly
vieiralucas 05eafa1
docs: fix elementid_derive signature in 3 headers, uuid version-range…
vieiralucas 7670973
fix: project-scoped sha1.h include guard, drop stale UUID version range
vieiralucas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include "elementid.h" | ||
|
|
||
| ElementId elementid_from_bytes(const uint8_t bytes[16]) { | ||
| ElementId id; | ||
| for (int i = 0; i < 16; i++) { | ||
| id.uuid.bytes[i] = bytes[i]; | ||
| } | ||
| return id; | ||
| } | ||
|
|
||
| ElementId elementid_root(void) { | ||
| ElementId id; | ||
| for (int i = 0; i < 16; i++) { | ||
| id.uuid.bytes[i] = 0; | ||
| } | ||
| return id; | ||
| } | ||
|
|
||
| bool elementid_eq(ElementId a, ElementId b) { | ||
| for (int i = 0; i < 16; i++) { | ||
| if (a.uuid.bytes[i] != b.uuid.bytes[i]) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| int elementid_cmp(ElementId a, ElementId b) { | ||
| for (int i = 0; i < 16; i++) { | ||
| if (a.uuid.bytes[i] < b.uuid.bytes[i]) { | ||
| return -1; | ||
| } else if (a.uuid.bytes[i] > b.uuid.bytes[i]) { | ||
| return 1; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| ElementId elementid_derive(ElementId parent, const void *key, size_t key_len, | ||
| uint8_t kind) { | ||
| UuidV5Ctx ctx = {0}; | ||
| uuid_v5_init(&ctx, parent.uuid.bytes); | ||
| uuid_v5_update(&ctx, key, key_len); | ||
| uuid_v5_update(&ctx, &kind, sizeof(kind)); | ||
|
|
||
| ElementId derived = {0}; | ||
| derived.uuid = uuid_v5_final(&ctx); | ||
| return derived; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #ifndef _CRDT_ELEMENTID_H | ||
| #define _CRDT_ELEMENTID_H | ||
|
|
||
| // ElementId: stable identity of a composite element (Register / Counter / | ||
| // Map), shared across replicas. Stamped on the composite at create, never | ||
| // mutated afterwards. | ||
| // | ||
| // Wire format: 16-byte UUID per RFC 4122 / RFC 9562. Convergent derivation | ||
| // uses UUID v5 (SHA-1 over namespace + name). The version/variant bits are | ||
| // set per spec so the result is a valid UUID — useful for cross-language | ||
| // interop, debugging, and standard tooling. | ||
| // | ||
| // Two replicas independently calling elementid_derive with matching | ||
| // inputs land on the same UUID by construction. That's how map_merge's | ||
| // recursive guard knows two slots refer to the same logical element. | ||
| // | ||
| // Manual construction (elementid_from_bytes) is supported for imports and | ||
| // for cases where the app provides its own convergence guarantee. | ||
|
|
||
| #include "uuid.h" | ||
|
vieiralucas marked this conversation as resolved.
|
||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| typedef struct ElementId { | ||
| UuidV5 uuid; | ||
| } ElementId; | ||
|
|
||
| ElementId elementid_from_bytes(const uint8_t bytes[16]); | ||
|
|
||
| ElementId elementid_root(void); | ||
|
|
||
| bool elementid_eq(ElementId a, ElementId b); | ||
|
|
||
| int elementid_cmp(ElementId a, ElementId b); | ||
|
|
||
| ElementId elementid_derive(ElementId parent, const void *key, size_t key_len, | ||
| uint8_t kind); | ||
|
|
||
| #endif // _CRDT_ELEMENTID_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.