{"id":19851860,"url":"https://github.com/stackoverflowexcept1on/simple-graph","last_synced_at":"2025-02-28T21:16:16.383Z","repository":{"id":63205211,"uuid":"566019534","full_name":"StackOverflowExcept1on/simple-graph","owner":"StackOverflowExcept1on","description":"Graph library with ability to serialize/deserialize Trivial Graph Format","archived":false,"fork":false,"pushed_at":"2023-10-10T20:15:58.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-17T23:57:32.054Z","etag":null,"topics":["bfs-algorithm","dfs-algorithm","graph-algorithms","rust","trivial-graph-format"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/StackOverflowExcept1on.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":"2022-11-14T20:03:55.000Z","updated_at":"2023-01-26T11:34:39.000Z","dependencies_parsed_at":"2024-11-15T00:31:51.832Z","dependency_job_id":null,"html_url":"https://github.com/StackOverflowExcept1on/simple-graph","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/StackOverflowExcept1on%2Fsimple-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackOverflowExcept1on%2Fsimple-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackOverflowExcept1on%2Fsimple-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackOverflowExcept1on%2Fsimple-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StackOverflowExcept1on","download_url":"https://codeload.github.com/StackOverflowExcept1on/simple-graph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241240718,"owners_count":19932606,"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":["bfs-algorithm","dfs-algorithm","graph-algorithms","rust","trivial-graph-format"],"created_at":"2024-11-12T13:33:02.246Z","updated_at":"2025-02-28T21:16:16.347Z","avatar_url":"https://github.com/StackOverflowExcept1on.png","language":"Rust","readme":"### simple-graph\n\n[![Build Status](https://github.com/StackOverflowExcept1on/simple-graph/workflows/CI/badge.svg)](https://github.com/StackOverflowExcept1on/simple-graph/actions)\n[![Latest Version](https://img.shields.io/crates/v/simple-graph.svg)](https://crates.io/crates/simple-graph)\n[![Documentation](https://docs.rs/simple-graph/badge.svg)](https://docs.rs/simple-graph/)\n\nGraph library with ability to serialize/deserialize Trivial Graph Format, see [simple-graph](simple-graph) directory\n\n### What is this?\n\nThis is my test task for `{some_company_name}`\n\nThe requirements are listed in the file [REQUIREMENTS-ru.md](REQUIREMENTS-ru.md)\n\n### Installing library from [crates.io](https://crates.io)\n\n```toml\n[dependencies]\nsimple-graph = \"0.1.0\"\n```\n\n### Examples\n\nGo to the [`Graph\u003cV, E\u003e` on docs.rs/simple-graph](https://docs.rs/simple-graph/latest/simple_graph/struct.Graph.html)\nfor online documentation\n\nI wrote a perfect documentation for all files in code using the `///` rust built-in feature\n\nYou can also read [`simple-graph/src/graph.rs`](simple-graph/src/graph.rs)\n\n### Implemented graph algorithms in the binary [app](app)\n\n![graphAlgorithms](simple-graph/assets/dfs-vs-bfs.gif)\n\n#### Breadth-first search algorithm (BFS)\n\n```bash\ncargo run -- simple-graph/test_input/moscow.tgf --algorithm bfs --start-vertex Moscow\n```\n\n```\nVertices traversal...\n- Moscow\n  (\"Vladimir\", \"180\")\n  (\"Yaroslavl\", \"250\")\n- Vladimir\n  (\"Novgorod\", \"225\")\n- Yaroslavl\n  (\"Vologda\", \"175\")\n- Novgorod\n- Vologda\nApplying \"BreadthFirstSearch\" algorithm to this graph...\n1. Moscow: [(\"Vladimir\", \"180\"), (\"Yaroslavl\", \"250\")]\n2. Vladimir: [(\"Novgorod\", \"225\")]\n3. Yaroslavl: [(\"Vologda\", \"175\")]\n4. Novgorod: []\n5. Vologda: []\n```\n\n#### Depth-first search algorithm (DFS)\n\n```bash\ncargo run -- simple-graph/test_input/moscow.tgf --algorithm dfs --start-vertex Moscow\n```\n\n```\nVertices traversal...\n- Moscow\n  (\"Vladimir\", \"180\")\n  (\"Yaroslavl\", \"250\")\n- Vladimir\n  (\"Novgorod\", \"225\")\n- Yaroslavl\n  (\"Vologda\", \"175\")\n- Novgorod\n- Vologda\nApplying \"DepthFirstSearch\" algorithm to this graph...\n1. Moscow: [(\"Vladimir\", \"180\"), (\"Yaroslavl\", \"250\")]\n2. Yaroslavl: [(\"Vologda\", \"175\")]\n3. Vologda: []\n4. Vladimir: [(\"Novgorod\", \"225\")]\n5. Novgorod: []\n```\n\n### Tests\n\nRust has 3 types of the test:\n\n- unit-tests\n  ```rust\n  #[cfg(test)]\n  mod tests { }\n  ```\n- integration tests stored in `crate_name/tests/*.rs`\n- **documentation tests** runs from comments near the function/method itself\n  ```rust\n  /// function foo\n  /// \n  /// ```\n  /// assert_eq!(foo(), true);\n  /// ```\n  fn foo() -\u003e bool { true }\n  ```\n\nI decided to use last type of the tests to verify code right in the comments to the methods\n\n```bash\ncargo test\n```\n\n```\n   Compiling simple-graph v0.1.0 (/mnt/tmpfs/simple-graph/simple-graph)\n   Compiling app v0.1.0 (/mnt/tmpfs/simple-graph/app)\n    Finished test [unoptimized + debuginfo] target(s) in 0.66s\n     Running unittests src/main.rs (target/debug/deps/app-bc92a2797886b115)\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n     Running unittests src/lib.rs (target/debug/deps/simple_graph-5c5fa28164719bd4)\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n   Doc-tests simple-graph\n\nrunning 19 tests\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::add_vertex (line 108) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::add_edge (line 186) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::edges (line 351) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::dfs (line 484) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::bfs (line 444) ... ok\ntest src/graph.rs - graph::Graph (line 29) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::get_vertex_id (line 84) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::get_edge (line 212) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::get_vertex_info (line 380) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::edges_count (line 298) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::get_edge_value (line 242) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::get_vertex (line 132) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::new (line 73) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::vertices_count (line 285) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::remove_edge (line 261) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::remove_vertex (line 150) ... ok\ntest src/tgf.rs - tgf::Graph\u003cV,E\u003e::fmt (line 16) ... ok\ntest src/graph.rs - graph::Graph\u003cV,E\u003e::vertices (line 319) ... ok\ntest src/tgf.rs - tgf::Graph\u003cV,E\u003e::from_str (line 81) ... ok\n\ntest result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.49s\n```\n\n### Clippy checks\n\n```bash\ncargo clippy --all-targets -- -D warnings\n```\n\n### Interaction with GitHub Actions\n\nThis repository also has a config [`.github/workflows/ci.yml`](.github/workflows/ci.yml) to check all\nthings that I described above automatically on GitHub servers\n\n### [`Cargo.toml`](Cargo.toml)\n\nI separated the packages into library and binary using\nthe [Cargo Workspaces](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html) feature in package manager\n\n### Cool Trivial Graph Format (TGF) serializer/deserializer\n\nI wrote really cool parser that can handle many errors and nicely print in for the user\n\n`test.tgf`\n```\n1 First node\n2 Second node\n2 Check error handler \u003c--- here is duplicated vertex, line 3\n#\n1 2 Edge between the two\n```\n\n```bash\ncargo run -- test.tgf --algorithm bfs --start-vertex \"First node\"\n```\n\nMy library can handle error and show problems user-friendly\n\n```\nError: graph parse error: vertex with index 2 already defined, check line 3\n```\n\nFor more details see [`simple-graph/src/error.rs`](simple-graph/src/error.rs)\n\n### Used technology stack\n\n- for [app](app) binary file\n    - [dtolnay/thiserror](https://github.com/dtolnay/thiserror) - used to handle complex error without using `Result\u003cT, Box\u003cdyn Error\u003e\u003e`\n    - [google/argh](https://github.com/google/argh) - library to process CLI arguments, it's also has small size after compilation\n    - [mackwic/colored](https://github.com/mackwic/colored) - BTW, colored output is also used in the binary file\n    - [`simple-graph = { path = \"../simple-graph\" }`](simple-graph)\n- for [simple-graph](simple-graph) library\n    - [dtolnay/thiserror](https://github.com/dtolnay/thiserror) - see \"Cool Trivial Graph Format (TGF) serializer/deserializer\" section about the parser\n    - [contain-rs/linked-hash-map](https://github.com/contain-rs/linked-hash-map) - mainly used to store vertices in the same order in that it was inserted\n    - [alexheretic/linked-hash-set](https://github.com/alexheretic/linked-hash-set) - to store edges in the inserted order\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackoverflowexcept1on%2Fsimple-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackoverflowexcept1on%2Fsimple-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackoverflowexcept1on%2Fsimple-graph/lists"}