{"id":17594908,"url":"https://github.com/dstein64/revdoor","last_synced_at":"2025-03-20T15:32:48.472Z","repository":{"id":145214227,"uuid":"239385610","full_name":"dstein64/revdoor","owner":"dstein64","description":"A single-file C++ library for visiting revolving door combinations.","archived":false,"fork":false,"pushed_at":"2024-04-30T23:03:10.000Z","size":27,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T17:21:27.992Z","etag":null,"topics":["combinatorics","cpp","revolving-door","taocp"],"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/dstein64.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-09T22:42:16.000Z","updated_at":"2024-04-30T23:03:13.000Z","dependencies_parsed_at":"2024-04-30T23:28:21.212Z","dependency_job_id":null,"html_url":"https://github.com/dstein64/revdoor","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dstein64%2Frevdoor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dstein64%2Frevdoor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dstein64%2Frevdoor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dstein64%2Frevdoor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dstein64","download_url":"https://codeload.github.com/dstein64/revdoor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244640304,"owners_count":20486018,"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":["combinatorics","cpp","revolving-door","taocp"],"created_at":"2024-10-22T07:21:35.968Z","updated_at":"2025-03-20T15:32:48.160Z","avatar_url":"https://github.com/dstein64.png","language":"C++","readme":"[![Build Status](https://github.com/dstein64/revdoor/workflows/build/badge.svg)](https://github.com/dstein64/revdoor/actions)\n\n# revdoor\n\n`revdoor` is a single-file C++ library for visiting *revolving door*\ncombinations.\n\nThe *combinations without replacement* generator implements Algorithm R from\nTAOCP 7.2.1.3 [[1]](#references). The *combinations with replacement* generator\nimplements the same algorithm, modified to support replacement.\n\nThe algorithms visit combinations by indicating `in` and `out` swap values for\none or two items on each iteration.\n\n## Quick Start\n \n1. Include the `revdoor.hpp` header.\n2. For combinations without replacement, initialize a generator object with\n   `revdoor::combinations`. For combinations with replacement, initialize a\n   generator object with `revdoor::combinations_with_replacement`.\n3. Use the `state()` method to get the initial state of the generator.\n4. Call the `step()` method to proceed to the next combination.\n   - For combinations without replacement, this takes two `int` pointers:\n     `out`'s dereference is set to the element that is removed, and `in`'s\n     dereference is set to the element that is added.\n   - For combinations without replacement, this takes four `int` pointers:\n     `out1`'s and `out2`'s dereferences are set to elements that are removed;\n     `in1`'s and `in2`'s dereferences are set to elements that are added.\n     In cases where only a single item is swapped out, `*out1 == *in1`.\n\n### Example 1: combinations without replacement\n\n```c++\n#include \u003crevdoor.hpp\u003e\n#include \u003cvector\u003e\n\nvoid process_init_state(const std::vector\u003cint\u003e init_state) { /* ... */ }\nvoid process_change(int out, int in) { /* ... */ }\n\nint main(int argc, char* argv[]) {\n  int n = 5;\n  int t = 3;\n  revdoor::combinations combs(n, t);\n  std::vector\u003cint\u003e init_state = combs.state();\n  process_init_state(init_state);\n  int out, in;\n  while (combs.step(\u0026out, \u0026in)) {\n    process_change(out, in);\n  }\n  return 0;\n}\n```\n\n### Example 2: combinations with replacement\n\n```c++\n#include \u003crevdoor.hpp\u003e\n#include \u003cvector\u003e\n\nvoid process_init_state(const std::vector\u003cint\u003e init_state) { /* ... */ }\nvoid process_change(int out, int in) { /* ... */ }\n\nint main(int argc, char* argv[]) {\n  int n = 5;\n  int t = 3;\n  revdoor::combinations_with_replacement combs_rep(n, t);\n  std::vector\u003cint\u003e init_state = combs_rep.state();\n  process_init_state(init_state);\n  int out1, in1, out2, in2;\n  while (combs_rep.step(\u0026out1, \u0026in1, \u0026out2, \u0026in2)) {\n    if (out1 != in1)\n      process_change(out1, in1);\n    process_change(out2, in2);\n  }\n  return 0;\n}\n```\n\n## Documentation\n\nRefer to the comments in [revdoor.hpp](revdoor.hpp) for detailed information.\n\n## License\n\nThe source code has an [MIT License](https://en.wikipedia.org/wiki/MIT_License).\n\nSee [revdoor.hpp](revdoor.hpp).\n\n## References\n\n[1] Donald Knuth, The Art of Computer Programming, Volume 4, Fascicle 3: Generating\nAll Combinations and Partitions (Addison-Wesley Professional, 2005).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdstein64%2Frevdoor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdstein64%2Frevdoor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdstein64%2Frevdoor/lists"}