{"id":21589486,"url":"https://github.com/ksw2000/simple8b-in-c","last_synced_at":"2025-03-18T09:43:33.045Z","repository":{"id":208196064,"uuid":"720999109","full_name":"ksw2000/simple8b-in-c","owner":"ksw2000","description":"An implementation of Simple8b algorithm in C","archived":false,"fork":false,"pushed_at":"2024-03-18T16:58:13.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T16:14:16.506Z","etag":null,"topics":["c","compressed-arrays","encoding","time-series"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ksw2000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-20T06:30:33.000Z","updated_at":"2024-06-05T02:03:58.000Z","dependencies_parsed_at":"2023-11-20T09:49:30.009Z","dependency_job_id":null,"html_url":"https://github.com/ksw2000/simple8b-in-c","commit_stats":null,"previous_names":["ksw2000/simple8b-in-c"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksw2000%2Fsimple8b-in-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksw2000%2Fsimple8b-in-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksw2000%2Fsimple8b-in-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksw2000%2Fsimple8b-in-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksw2000","download_url":"https://codeload.github.com/ksw2000/simple8b-in-c/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244198189,"owners_count":20414439,"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":["c","compressed-arrays","encoding","time-series"],"created_at":"2024-11-24T16:14:37.851Z","updated_at":"2025-03-18T09:43:33.013Z","avatar_url":"https://github.com/ksw2000.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple8b-in-C\n\nsimple8b.h implements the 64-bit integer encoding algorithm as published by Anh and Moffat in \"Index compression using 64-bit words\", Softw. Pract. Exper. 2010; 40:131–147\n\nSimple8b is 64-bit word-sized encoder that packs multiple integers into a single word using a 4 bit selector values and up to 60 bits for the remaining values.  Integers are encoded using the following table:\n\n|  selector   |  0   |  1   |  2   |  3   |  4   |  5   |  6   |  7   |  8   |  9   |  10  |  11  |  12  |  13  |  14  |  15  |\n| :---------: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: |\n|    bits     |  0   |  0   |  1   |  2   |  3   |  4   |  5   |  6   |  7   |  8   |  10  |  12  |  15  |  20  |  30  |  60  |\n|      N      | 240  | 120  |  60  |  30  |  20  |  15  |  12  |  10  |  8   |  7   |  6   |  5   |  4   |  3   |  2   |  1   |\n| Wasted Bits |  60  |  60  |  0   |  0   |  0   |  0   |  0   |  0   |  4   |  4   |  0   |  0   |  0   |  0   |  0   |  0   |\n\nFor example, when the number of values can be encoded using 4 bits, selected 5 is encoded in the 4 most significant bits followed by 15 values encoded used 4 bits each in the remaining 60 bits.\n\nThe code is rewritten from a Go package [github.com/jwilder/encoding](https://pkg.go.dev/github.com/jwilder/encoding)\n\n## Functions\n\n```c\nconst int simple8bEncode(const uint64_t *__restrict__ src, int srcLen, uint64_t *__restrict__ encoded);\n```\n\n`simple8bEncode()` packs as many values from the `src` into a single uint64 number `encoded` and returns the number of packed values.\n\n```c\nconst int simple8bDecode(uint64_t *__restrict__ dst, uint64_t v);\n```\n\n`simple8bDecode()` decodes a 64-bit number `v`, writes the result into a large enough list `dst`, and returns the number of unpacked values. The length of `dst` should be greater or equal to `240`\n\n## Example\n\n```c\n#include \u003cstdint.h\u003e\n#include \u003cstdio.h\u003e\n\n#include \"./src/simple8b.h\"\n\nint main() {\n    uint64_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n    uint64_t encoded;\n    int n = simple8bEncode(src, sizeof(src) / sizeof(src[0]), \u0026encoded);\n\n    uint64_t decoded[240];\n    int m = simple8bDecode(decoded, encoded);\n    for (int i = 0; i \u003c m; i++) {\n        printf(\"[%d] = %lu\\n\", i, decoded[i]);\n    }\n\n    return 0;\n}\n```\n\n**Result**\n\n```\n[0] = 1\n[1] = 2\n[2] = 3\n[3] = 4\n[4] = 5\n[5] = 6\n[6] = 7\n[7] = 8\n[8] = 9\n[9] = 10\n```\n\n## Usage\n\n**Compile Directly**\n\n```\n.\n├── src/\n│   ├── simple8b.h\n│   └── simple8b.c\n└── example.c\n```\n\n```sh\ngcc example.c src/simple8b.c -o example\n./example\n```\n\n**Static Library**\n\n```sh\nmkdir lib\ngcc -c src/simple8b.c -o lib/simple8b.o\nar rcs lib/simple8b.a lib/simple8b.o\ngcc example.c -o example -L. lib/simple8b.a\n```\n\n```\n.\n├── src/\n│   ├── simple8b.h\n│   └── simple8b.c\n├── lib/\n│   ├── simple8b.a\n│   └── simple8b.o\n├── example.c\n└── example\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksw2000%2Fsimple8b-in-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksw2000%2Fsimple8b-in-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksw2000%2Fsimple8b-in-c/lists"}