{"id":26059635,"url":"https://github.com/mnikander/cpp_algorithm","last_synced_at":"2025-06-25T09:04:14.787Z","repository":{"id":244261220,"uuid":"793108049","full_name":"mnikander/cpp_algorithm","owner":"mnikander","description":"A loose collection of algorithms inspired by C++ Ranges, Thrust, APL/BQN, Haskell, and others","archived":false,"fork":false,"pushed_at":"2025-05-12T09:59:46.000Z","size":154,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-12T10:27:17.899Z","etag":null,"topics":[],"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/mnikander.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,"zenodo":null}},"created_at":"2024-04-28T12:57:30.000Z","updated_at":"2025-05-12T09:59:49.000Z","dependencies_parsed_at":"2025-01-24T10:34:29.366Z","dependency_job_id":null,"html_url":"https://github.com/mnikander/cpp_algorithm","commit_stats":null,"previous_names":["manik7/cpp_algorithm","mnikander/cpp_algorithm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mnikander/cpp_algorithm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnikander","download_url":"https://codeload.github.com/mnikander/cpp_algorithm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnikander%2Fcpp_algorithm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261841935,"owners_count":23217911,"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":[],"created_at":"2025-03-08T13:26:50.689Z","updated_at":"2025-06-25T09:04:14.762Z","avatar_url":"https://github.com/mnikander.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cpp_algorithm\nA loose collection of algorithms inspired by C++ Ranges, Thrust, APL/BQN, Haskell, Lisp, and others.\n\n## Getting started\n\n1. Install dependencies\n```bash\nsudo apt get install libgtest-dev cmake g++\n```\n\n2. Clone the repo\n```bash\ngit clone #...\n```\n\n3. Build and run:\n```bash\n# out-of-source build\ncd cpp_algorithm \u0026\u0026 mkdir out \u0026\u0026 cd out \u0026\u0026 cmake .. \u0026\u0026 cd ..\ncmake --build out/ \u0026\u0026 ./out/unit_tests \u0026\u0026 ./out/main\n```\n\n## Directory structure\n- `src/simple/  ` contains the implementations of the algorithms as functions, they are simple and can be used on their own\n- `src/pipeline/` contains function objects which serve as pipeline adapters for each of the algorithms and allow creating bash-style pipelines with the `|` operator\n- `src/meta/    ` contains several meta functions, including the implementation of the `|` operator itself\n\n# Algorithms\n\nThese algorithm implementations are designed for ease-of-use, but are hard-coded to std::vector and do copy-by-value, which makes them slow.\nIt does allow playing around with the algorithms early on, and are a first step on the road to the faster implementations.\n\n## Creation and insertion\n- iota\n- repeat           (C++: fill)\n- catenate\n- zip\n\n## Element retrieval\n- use vector::operator[] as normal\n\n## Permutation and selection\n- reverse\n- rotate\n- rotate_last\n- take\n- take_last\n- drop\n- drop_last\n- gather           (APL: postfix-operator [])\n- scatter\n- filter           (C++: copy_if)\n- grade\n- shuffle\n\n## Computation\n- reduce\n- map              (C++: transform)\n\n## Comparison\n- any\n- all              (APL: match)\n- none\n\n## Properties\n- size             (APL: tally)\n- rank\n\n## Arithmetic and boolean functions\n\n### Unary functions\n- not (logical)\n- identity\n- negate\n\n### Binary functions\n- and (logical)\n- or  (logical)\n- plus\n- minus\n- multiply\n- divide\n- modulo (is actually 'remainder')\n- power\n- minimum\n- maximum\n- equal\n- not_equal\n- less\n- less_equal\n- greater\n- greater_equal\n- least_common_multiple\n- greatest_common_divisor\n\n# TODO\n- find\n- contains\n- scan\n- something to search for the largest/smallest etc element\n- front / back\n- at / get -- with and without bounds checking respectively (C++ convention 'at')\n- slice / stencil\n- inner_product / map_reduce\n- sort\n\n## Arithmetic and boolean functions\n\n### Nilary functions\n- e  -- a bit short for a function name, it could collide with all sorts of stuff, maybe `constant_e`?\n- pi -- less likely, but might collide with stuff as well, maybe `constant_pi`?\n\nOr make a namespace `math` which contains them as constexpr values, i.e. `math::pi` and `math::e`\n\n### Unary functions\n- sqrt: square root\n- crt: cube root\n- exp | exp_e: exponential e -- maybe with a default value of 1 so it's easy to get 'e'\n- exp_2:       exponential 2\n- exp_10:      exponential 10\n- log | log_e: logarithm e\n- log_2:       logarithm 2\n- log_10:      logarithm 10\n- deg: degree\n- rad: radian\n- sin:  sine\n- asin: arcus_sine\n- cos:  cosine\n- acos: arcus_cosine\n- tan:  tangent\n- atan: arcus_tangent\n- abs:  absolute\n- ceil: ceiling\n- floor: floor\n- round: round\n\n## Future work on sequences\n- take_while\n- drop_while\n- encode\n- decode\n- zip with next\n- alternating reduction for minus and division (or some way of doing this)\n- union (?) -- using DSU perhaps, or a hashmap\n- difference (?)\n- intersection (?)\n- group by (returns a map of lists)\n- chunk (returns list of lists)\n- refactor to fold (manually specify init) vs. reduce (init = first element)\n- fold_left, fold_right (see Haskell)\n- roll\n- deal\n- binomial\n- factorial\n\n## Future work on tensors with rank \u003e 1\n\n- implement a strided range / tensor datatype similar to mdspan or cv::mat\n- outer product\n- stencil\n- view to apply any algorithm around one specified axis (i.e. column-wise plus-reduce)\n- flatten\n- transpose\n- (re)shape (rename repeat to shape, and extend the 'count' to be an n-entry vector describing the desired n-dimensional shape)\n- ravel (flatten)\n\n## Future work on intervals (TBD if I will do this)\n- templated interval type with support for\n    - scalars, to reason about numbers\n    - iterators, to create and manipulate a 'view' on data\n- union\n- intersection\n- difference\n- overload other functions to take an interval as their [first, last) values\n    - iota\n    - stencil\n    - roll (generate a random number in the interval)\n\n## Copyright\n\nCopyright (c) 2024, Marco Nikander\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnikander%2Fcpp_algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnikander%2Fcpp_algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnikander%2Fcpp_algorithm/lists"}