{"id":18046595,"url":"https://github.com/ltla/raiigraph","last_synced_at":"2025-04-05T04:24:45.301Z","repository":{"id":247659965,"uuid":"826487749","full_name":"LTLA/raiigraph","owner":"LTLA","description":"C++ RAII for igraph data structures","archived":false,"fork":false,"pushed_at":"2024-10-06T06:37:17.000Z","size":522,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T12:28:19.992Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ltla.github.io/raiigraph/","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/LTLA.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-07-09T19:57:42.000Z","updated_at":"2024-10-06T06:34:31.000Z","dependencies_parsed_at":"2024-07-10T00:35:39.560Z","dependency_job_id":"5a8d59f4-db50-4909-8a16-2862b66117d4","html_url":"https://github.com/LTLA/raiigraph","commit_stats":null,"previous_names":["ltla/raiigraph"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LTLA%2Fraiigraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LTLA%2Fraiigraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LTLA%2Fraiigraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LTLA%2Fraiigraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LTLA","download_url":"https://codeload.github.com/LTLA/raiigraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247288007,"owners_count":20914280,"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":"2024-10-30T19:08:04.429Z","updated_at":"2025-04-05T04:24:45.276Z","avatar_url":"https://github.com/LTLA.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ RAII for igraph data structures\n\n![Unit tests](https://github.com/LTLA/raiigraph/actions/workflows/run-tests.yaml/badge.svg)\n![Documentation](https://github.com/LTLA/raiigraph/actions/workflows/doxygenate.yaml/badge.svg)\n[![Codecov](https://codecov.io/gh/LTLA/raiigraph/graph/badge.svg?token=qiFzL0PTBw)](https://codecov.io/gh/LTLA/raiigraph)\n\n## Overview \n\nThis library provides some RAII wrappers around the data structures used by the [**igraph** C library](https://igraph.org).\nThe aim is to make **igraph** a little bit more ergonomic for use in existing C++ codebases.\nThe code here was originally developed as part of the [**libscran**](https://github.com/LTLA/libscran) library,\nbut has been factored out for potential re-use.\n\nCurrently, we implement wrappers for the following **igraph** structures:\n\n| **igraph** structure | **raiigraph** wrapper |\n|----------------------|-----------------------|\n| `igraph_vector_t`    | `raiigraph::RealVector` |\n| `igraph_vector_int_t` | `raiigraph::IntVector` |\n| `igraph_vector_bool_t` | `raiigraph::BoolVector` |\n| `igraph_matrix_t` | `raiigraph::RealMatrix` |\n| `igraph_matrix_int_t` | `raiigraph::IntMatrix` |\n| `igraph_matrix_bool_t` | `raiigraph::BoolMatrix` |\n| `igraph_t` | `raiigraph::Graph` |\n\nPlease make a PR if your favorite structure is missing.\n\n## Quick start\n\nAll wrappers provide the usual RAII behavior, greatly simplifying memory management when used in existing code.\n\n```cpp\n{\n    raiigraph::IntVector thing(50);\n    igraph_vector_int_size(thing); // can directly use the object with igraph.\n} // thing's memory is released when 'thing' goes out of scope.\n``` \n\nWe also follow the rule of 5 convention, so copy/move assignment works as expected:\n\n```cpp\nraiigraph::Graph outside;\n\n{\n    raiigraph::Graph inside(20, IGRAPH_UNDIRECTED);\n    igraph_graph_ecount(inside); // can directly use the object with igraph.\n    outside = std::move(inside);\n}\n```\n\nSome of the wrappers also provide convenience methods to query the underlying data structure without having to extract the raw pointer:\n\n```cpp\nraiigraph::Graph example(20, IGRAPH_UNDIRECTED);\nexample.ecount(); // number of edges\nexample.vcount(); // number of vertices\n```\n\nCheck out the [reference documentation](https://ltla.github.io/raiigraph) for more details.\n\n## STL compatibility\n\nThe `Vector` classes provide the same methods as `std::vector` and can be used as a drop-in replacement in various standard library functions:\n\n```cpp\n// Vector provides std::vector-like behavior.\nraiigraph::RealVector vec(10);\nthing[0] = 1;\nthing.push_back(5);\nstd::fill(thing.begin() + 2, thing.begin() + 5, 10);\nstd::sort(thing.begin(), thing.end());\nauto\u0026 last = thing.back();\n```\n\nThe `Matrix` classes provide views into the rows and columns that have STL-like behavior.\n\n```cpp\nraiigraph::IntMatrix mat(10, 20);\nauto row_view = mat.row(5); // i.e., 5th row.\nrow_view.size();\nrow_view[2] = 5; // modifies the underlying matrix.\nrow_view.back() = 10;\nstd::sort(row_view.begin(), row_view.end());\n```\n\n## Controlling the RNG\n\nThe `RNGScope` class allows users to easily set the **igraph** RNG for reproducible execution.\nThis uses RAII to restore the previous RNG when the instance goes out of scope:\n\n```cpp\n{\n    RNGScope scope(10); // sets the RNG with seed of 10.\n    // use igraph functions that need the RNG.\n} // restores the previous RNG.\n```\n\nThis class can be used in a nested manner for easy composition:\n\n```cpp\nvoid foo() {\n    RNGScope scope(20); // sets the RNG with seed of 20.\n    // use igraph functions that need the RNG.\n} // restores the previous RNG.\n\n{\n    RNGScope scope(10); // sets the RNG with seed of 10.\n\n    if (maybe_run) {\n        foo();\n    }\n\n    // use igraph functions that need the RNG, getting the same results\n    // regardless of whether foo() was called.\n} // restores the previous RNG.\n```\n\n## Building projects\n\n### CMake with `FetchContent`\n\nIf you're using CMake, you just need to add something like this to your `CMakeLists.txt`:\n\n```cmake\ninclude(FetchContent)\n\nFetchContent_Declare(\n  raiigraph\n  GIT_REPOSITORY https://github.com/LTLA/raiigraph\n  GIT_TAG master # or any version of interest\n)\n\nFetchContent_MakeAvailable(raiigraph)\n```\n\nThen you can link to **raiigraph** to make the headers available during compilation:\n\n```cmake\n# For executables:\ntarget_link_libraries(myexe raiigraph::raiigraph)\n\n# For libaries\ntarget_link_libraries(mylib INTERFACE raiigraph::raiigraph)\n```\n\nThis assumes that **igraph** has already been installed and can be found by `find_package()`. \nUsers can use the `RAIIGRAPH_FIND_IGRAPH` option to disable **igraph** discovery (e.g., to supply a custom **igraph** installation),\nin which case they will need to link to **igraph** manually in their `target_link_libraries()` call.\n\n### CMake with `find_package()`\n\n```cmake\nfind_package(raiigraph_raiigraph CONFIG REQUIRED)\ntarget_link_libraries(mylib INTERFACE ltla::raiigraph)\n```\n\nTo install the library, use:\n\n```sh\nmkdir build \u0026\u0026 cd build\ncmake .. -DKNNCOLLE_TESTS=OFF\ncmake --build . --target install\n```\n\nAgain, this assumes that **igraph** has already been installed and can be found by `find_package()`, unless otherwise specified via `RAIIGRAPH_FIND_IGRAPH`.\n\n### Manual\n\nIf you're not using CMake, the simple approach is to just copy the files in `include/` - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's `-I`.\nThis means that you are responsible for manually linking to **igraph**. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fltla%2Fraiigraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fltla%2Fraiigraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fltla%2Fraiigraph/lists"}