Created
July 3, 2025 11:52
-
-
Save dhbrojas/ef578b098cdc73e07f47029eb9e62fb0 to your computer and use it in GitHub Desktop.
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
| import random | |
| YEAR_SHIFT = 32 | |
| def encode(uid, year): | |
| return (year << YEAR_SHIFT) | uid | |
| def decode(docid): | |
| return docid & ((1 << YEAR_SHIFT) - 1), docid >> YEAR_SHIFT | |
| id = random.randint(0, 2**32) | |
| year = random.randint(0, 2**16) | |
| print(id, year) | |
| enc = encode(id, year) | |
| print(enc) | |
| (id, year) = decode(enc) | |
| print(id, year) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment