{"id":17702638,"url":"https://github.com/friendlymatthew/varint","last_synced_at":"2025-07-17T14:33:57.983Z","repository":{"id":227722435,"uuid":"771863306","full_name":"friendlymatthew/varint","owner":"friendlymatthew","description":"fanum tax 64-bit integers with LEB128","archived":false,"fork":false,"pushed_at":"2024-03-18T01:55:38.000Z","size":38,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T10:45:01.485Z","etag":null,"topics":["leb128","rizz","variable-integers"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/friendlymatthew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-14T04:56:20.000Z","updated_at":"2024-10-26T04:13:14.000Z","dependencies_parsed_at":"2024-10-25T20:17:42.469Z","dependency_job_id":"c388129f-47e9-41cc-a9dd-0247d523afb2","html_url":"https://github.com/friendlymatthew/varint","commit_stats":null,"previous_names":["friendlymatthew/rizz64","friendlymatthew/rizz128","friendlymatthew/varint"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/friendlymatthew/varint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlymatthew%2Fvarint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlymatthew%2Fvarint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlymatthew%2Fvarint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlymatthew%2Fvarint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/friendlymatthew","download_url":"https://codeload.github.com/friendlymatthew/varint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendlymatthew%2Fvarint/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265617054,"owners_count":23798956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["leb128","rizz","variable-integers"],"created_at":"2024-10-24T19:08:33.576Z","updated_at":"2025-07-17T14:33:57.967Z","avatar_url":"https://github.com/friendlymatthew.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003ch2 align=center\u003e\u003ci\u003erizz\u003c/i\u003e64\u003c/h2\u003e\n\u003cp align=center\u003eFanum* tax 64-bit integers.\u003c/p\u003e\n\u003cp  align=right\u003e\u003csub\u003e* Fanum is a popular streamer who taxes his friends by taking \u003ci\u003ebites\u003c/i\u003e of their food.\u003c/sub\u003e\u003c/p\u003e\n\n\u003cbr\u003e\n\nThis crate provides an efficient and powerful variable-length integer codec using [LEB128](https://en.wikipedia.org/wiki/LEB128) compression. \n\n### Why *rizz*64 is helpful\nIt's super efficient in representing smaller numbers with fewer bytes. Instead of a fixed-size solution like `u64`, this form of encoding can store values using less space or memory.\n\nBasic metrics:\n\n| Decimal            | Powers of 2      | # of Bytes Needed |\n|:-------------------|------------------|-------------------|\n| 0..127             | `2^0-1`..`2^7-1` | 1                 |\n| 128..16383         | `2^7`..`2^14-1`  | 2                 |\n| 16384..2097151     | `2^14`..`2^21-1` | 3                 |\n| 2097152..268435455 | `2^21`..`2^28-1` | 4                 |\n\n\nand so on... to compute the number of bytes required, you can use the following:\n\nThe upper bound of `log2(max(x, 1)) / 7`, where `x` is your number.\nThis is derived from the fact that each byte can represent 7 bits. *rizz*64 uses a base-2 logarithm to determine the magnitude in bits. We call `max(x, 1)` to ensure this value could never be `0`. We take the upper bound and round to the nearest whole number.\n\n### How encoding works\nFor a given `u64`, we process the number by groups of 7 bits. For every group, if there are more than 7 bits still to be encoded, we loop.\n\nIn the loop, the least significant 7 bits are extracted and packed into a buffer. The 8th bit is the most significant bit (MSB); we set the MSB to `1` to indicate there are more groups ahead. Then, we shift right (`\u003e\u003e=`) by 7 bits and we process the next group.\n\nAfter looping, the remaining bits of the number are packed into the buffer. This is the last byte and since we're halting, we don't set the MSB to `1`.\n\n\n\n\n### Literature \n[LEB128](https://en.wikipedia.org/wiki/LEB128)\u003cbr\u003e\n[sqlite variable-length ints](https://www.sqlite.org/src4/doc/trunk/www/varint.wiki)\u003cbr\u003e\n[varint.go](https://go.dev/src/encoding/binary/varint.go)\u003cbr\u003e\n\n### Todo\n- [ ] Go outside\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendlymatthew%2Fvarint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriendlymatthew%2Fvarint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendlymatthew%2Fvarint/lists"}