{"id":21963044,"url":"https://github.com/kampersanda/succinctrits","last_synced_at":"2025-04-23T22:28:00.459Z","repository":{"id":93201460,"uuid":"202519645","full_name":"kampersanda/succinctrits","owner":"kampersanda","description":"Succinct Rank/Select Data Structures on Trits","archived":false,"fork":false,"pushed_at":"2019-11-21T10:56:09.000Z","size":42,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T19:05:59.582Z","etag":null,"topics":["succinct-data-structure","trits"],"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/kampersanda.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":"2019-08-15T10:12:01.000Z","updated_at":"2021-03-01T00:24:18.000Z","dependencies_parsed_at":"2023-04-07T22:47:38.526Z","dependency_job_id":null,"html_url":"https://github.com/kampersanda/succinctrits","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kampersanda%2Fsuccinctrits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kampersanda%2Fsuccinctrits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kampersanda%2Fsuccinctrits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kampersanda%2Fsuccinctrits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kampersanda","download_url":"https://codeload.github.com/kampersanda/succinctrits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250525673,"owners_count":21445067,"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":["succinct-data-structure","trits"],"created_at":"2024-11-29T10:59:31.815Z","updated_at":"2025-04-23T22:28:00.439Z","avatar_url":"https://github.com/kampersanda.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# succinctrits\nThis library provides succinct Rank/Select data structures on trits (i.e., ternary digits). A vector consisting of n values from {0,1,2} is stored in 1.6n bits of space, which is close to the theoretically-optimal space usage of 1.57n bits [1]. The Rank/Select data structures are implemented in 0.32n additional bits of space in a similar manner to traditional approaches for bit vectors (e.g., [2]).\n\nThe trit-vector implementation is based on Fischer's approach presented in [3].\n\n## Install\n\nThis library consists of only header files. Please pass the path to the directory [`succinctrits/include`](https://github.com/kampersanda/succinctrits/tree/master/include).\n\n## Sample usage\n\n```c++\n#include \u003ciostream\u003e\n#include \u003crandom\u003e\n\n#include \u003crs_support.hpp\u003e\n#include \u003ctrit_vector.hpp\u003e\n\nint main() {\n    std::vector\u003cuint8_t\u003e trits = {1, 0, 1, 2, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 2, 1, 2, 0, 1};\n    succinctrits::trit_vector tv(trits.begin(), trits.size());\n\n    std::cout \u003c\u003c \"=== Trie Array ===\" \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"addr: \";\n    for (uint64_t i = 0; i \u003c tv.get_num_trits(); ++i) {\n        std::cout \u003c\u003c i % 10 \u003c\u003c ' ';\n    }\n    std::cout \u003c\u003c std::endl \u003c\u003c \"trit: \";\n    for (uint64_t i = 0; i \u003c tv.get_num_trits(); ++i) {\n        std::cout \u003c\u003c uint32_t(tv[i]) \u003c\u003c ' ';\n    }\n    std::cout \u003c\u003c std::endl;\n\n    succinctrits::rs_support\u003c0\u003e tv_rs_0(\u0026tv);\n    succinctrits::rs_support\u003c1\u003e tv_rs_1(\u0026tv);\n    succinctrits::rs_support\u003c2\u003e tv_rs_2(\u0026tv);\n\n    std::cout \u003c\u003c \"=== Operations ===\" \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"rank_0(6)   = \" \u003c\u003c tv_rs_0.rank(6) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"rank_1(10)  = \" \u003c\u003c tv_rs_1.rank(10) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"rank_2(3)   = \" \u003c\u003c tv_rs_2.rank(3) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"select_0(3) = \" \u003c\u003c tv_rs_0.select(3) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"select_1(5) = \" \u003c\u003c tv_rs_1.select(5) \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"select_2(0) = \" \u003c\u003c tv_rs_2.select(0) \u003c\u003c std::endl;\n\n    std::cout \u003c\u003c \"=== Statistics ===\" \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"num trits: \" \u003c\u003c tv.get_num_trits() \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"num 0s:    \" \u003c\u003c tv_rs_0.get_num_target_trits() \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"num 1s:    \" \u003c\u003c tv_rs_1.get_num_target_trits() \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"num 2s:    \" \u003c\u003c tv_rs_2.get_num_target_trits() \u003c\u003c std::endl;\n\n    {\n        std::ofstream ofs(\"trits.idx\");\n        tv.save(ofs);\n        tv_rs_0.save(ofs);\n        tv_rs_1.save(ofs);\n        tv_rs_2.save(ofs);\n    }\n\n    {\n        std::ifstream ifs(\"trits.idx\");\n        succinctrits::trit_vector other_tv;\n        succinctrits::rs_support\u003c0\u003e other_tv_rs_0;\n        succinctrits::rs_support\u003c1\u003e other_tv_rs_1;\n        succinctrits::rs_support\u003c2\u003e other_tv_rs_2;\n        other_tv.load(ifs);\n        other_tv_rs_0.load(ifs);\n        other_tv_rs_1.load(ifs);\n        other_tv_rs_2.load(ifs);\n        other_tv_rs_0.set_vector(\u0026other_tv);\n        other_tv_rs_1.set_vector(\u0026other_tv);\n        other_tv_rs_2.set_vector(\u0026other_tv);\n    }\n\n    std::remove(\"trits.idx\");\n    return 0;\n}\n```\n\nThe output will be\n\n```\n=== Trie Array ===\naddr: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 \ntrit: 1 0 1 2 1 0 0 1 0 1 0 0 1 1 1 2 1 2 0 1 \n=== Operations ===\nrank_0(6)   = 2\nrank_1(10)  = 5\nrank_2(3)   = 0\nselect_0(3) = 8\nselect_1(5) = 12\nselect_2(0) = 3\n=== Statistics ===\nnum trits: 20\nnum 0s:    7\nnum 1s:    10\nnum 2s:    3\n```\n\n## Benchmark\n\n- 3.5 GHz Intel Core i7\n- 16 GB 2133 MHz LPDDR3\n- OS X 10.14.6\n- Apple clang version 11.0.0\n\n```\n$ ./benchmark/benchmark \n=== Benchmark for 1000000 trits ===\n# access time: 19.3666 ns/op\n# rank time:   34.0611 ns/op\n# select time: 117.213 ns/op\n# trit_vector: 1.60006 bits/trit\n# rs_support:  0.321088 bits/trit\n=== Benchmark for 10000000 trits ===\n# access time: 27.337 ns/op\n# rank time:   43.6852 ns/op\n# select time: 143.572 ns/op\n# trit_vector: 1.60001 bits/trit\n# rs_support:  0.320986 bits/trit\n=== Benchmark for 100000000 trits ===\n# access time: 23.5833 ns/op\n# rank time:   76.2127 ns/op\n# select time: 241.136 ns/op\n# trit_vector: 1.6 bits/trit\n# rs_support:  0.320977 bits/trit\n```\n\n## References\n\n1. Mihai Patrascu. **Succincter**. In *FOCS*, pages 305–313, 2008.\n2. Rodrigo González, Szymon Grabowski, Veli Mäkinen, and Gonzalo Navarro. **Practical implementation of rank and select queries**. In *WEA*, pages 27–38, 2005.\n3. Johannes Fischer and Daniel Peters. **GLOUDS: Representing tree-like graphs**. *J. Discrete Algorithm.*, 36:39–49, 2016.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkampersanda%2Fsuccinctrits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkampersanda%2Fsuccinctrits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkampersanda%2Fsuccinctrits/lists"}