{"id":15062795,"url":"https://github.com/7bridges-eu/corallo","last_synced_at":"2025-04-10T10:11:20.068Z","repository":{"id":62432606,"uuid":"181000585","full_name":"7bridges-eu/corallo","owner":"7bridges-eu","description":"A tiny graph library in Clojure.","archived":false,"fork":false,"pushed_at":"2019-05-13T11:10:27.000Z","size":118,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T09:03:33.586Z","etag":null,"topics":["clojure","graph"],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/7bridges-eu.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}},"created_at":"2019-04-12T12:09:11.000Z","updated_at":"2023-05-03T13:34:17.000Z","dependencies_parsed_at":"2022-11-01T20:45:44.332Z","dependency_job_id":null,"html_url":"https://github.com/7bridges-eu/corallo","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7bridges-eu%2Fcorallo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7bridges-eu%2Fcorallo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7bridges-eu%2Fcorallo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/7bridges-eu%2Fcorallo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/7bridges-eu","download_url":"https://codeload.github.com/7bridges-eu/corallo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198885,"owners_count":21063628,"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":["clojure","graph"],"created_at":"2024-09-24T23:46:44.522Z","updated_at":"2025-04-10T10:11:20.010Z","avatar_url":"https://github.com/7bridges-eu.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/7bridges-eu/corallo/blob/master/resources/logo.png\" alt=\"7bridges clj-odbp\"\n        width=\"500px\" height=\"122px\"/\u003e\n\u003c/p\u003e\n\n# corallo\n\nA tiny graph library that can be used both from Clojure and ClojureScript.\n\n[![Clojars Project](https://img.shields.io/clojars/v/eu.7bridges/corallo.svg)](https://clojars.org/eu.7bridges/corallo)\n\n## Rationale\n\n`corallo` was born out of our need to handle and check dependencies in graphs\nwhich describe processes containing tasks to be executed. It was deemed helpful\nand independent enough to be extracted into and released as a library of its\nown.\n\n## Usage\n\nA graph in `corallo` is a Clojure map. For instance:\n\n``` clojure\n(def g {:vertexes {:a {:value \"1\" :in #{} :out #{:b}}\n                   :b {:value \"2\" :in #{:a} :out #{:c}}\n                   :c {:value \"3\" :in #{:b} :out #{:d}}\n                   :d {:value \"4\" :in #{:c} :out #{}}}\n        :edges {[:a :b] {}\n                [:b :c] {}\n                [:c :d] {}}})\n```\n\nYou can manipulate the graph by adding vertexes:\n\n``` clojure\nuser\u003e (require '[corallo.graph :as graph])\nuser\u003e (graph/add-vertex g :e \"5\")\n{:vertexes {:a {:value \"1\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{:d}},\n            :d {:value \"4\", :in #{:c}, :out #{}},\n            :e {:value \"5\", :in #{}, :out #{}}},\n :edges {[:a :b] {}, [:b :c] {}, [:c :d] {}}}\n```\n\nOr you can add an edge between two vertexes:\n\n``` clojure\nuser\u003e (-\u003e (graph/add-vertex g :e \"5\")\n          (graph/add-edge :d :e))\n{:vertexes {:a {:value \"1\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{:d}},\n            :d {:value \"4\", :in #{:c}, :out #{:e}},\n            :e {:value \"5\", :in #{:d}, :out #{}}},\n :edges {[:a :b] {}, [:b :c] {}, [:c :d] {}, [:d :e] {}}}\n```\n\nYou can set the value of a vertex after the graph has been created:\n\n``` clojure\nuser\u003e (graph/set-vertex-value g :a \"0\")\n{:vertexes {:a {:value \"0\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{:d}},\n            :d {:value \"4\", :in #{:c}, :out #{}}},\n :edges {[:a :b] {}, [:b :c] {}, [:c :d] {}}}\n```\n\nOr you can remove a vertex:\n\n``` clojure\nuser\u003e (graph/remove-vertex g :d)\n{:vertexes {:a {:value \"1\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{}}},\n :edges {[:a :b] {}, [:b :c] {}}}\n```\n\nThe operations in `corallo.graph` leverage Clojure immutability, so they return\na new graph instead of modifying the original one.\n\nEdges can have properties:\n\n``` clojure\nuser\u003e (-\u003e (graph/add-vertex g :e \"5\")\n          (graph/add-edge :d :e {:p1 \"a property\"}))\n{:vertexes {:a {:value \"1\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{:d}},\n            :d {:value \"4\", :in #{:c}, :out #{:e}},\n            :e {:value \"5\", :in #{:d}, :out #{}}},\n :edges {[:a :b] {}, [:b :c] {}, [:c :d] {}, [:d :e] {:p1 \"a property\"}}}\n\nuser\u003e (-\u003e (graph/add-vertex g :e \"5\")\n          (graph/add-edge :d :e)\n          (graph/set-edge-properties :a :b {:p1 \"a property\"}))\n{:vertexes {:a {:value \"1\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{:d}},\n            :d {:value \"4\", :in #{:c}, :out #{:e}},\n            :e {:value \"5\", :in #{:d}, :out #{}}},\n :edges {[:a :b] {:p1 \"a property\"}, [:b :c] {}, [:c :d] {}, [:d :e] {}}}\n```\n\nLike vertexes, edges can be removed from the graph:\n\n``` clojure\nuser\u003e (graph/remove-edge g :c :d)\n{:vertexes {:a {:value \"1\", :in #{}, :out #{:b}},\n            :b {:value \"2\", :in #{:a}, :out #{:c}},\n            :c {:value \"3\", :in #{:b}, :out #{}},\n            :d {:value \"4\", :in #{}, :out #{}}},\n :edges {[:a :b] {}, [:b :c] {}}}\n```\n\nYou can query the graph for information:\n\n``` clojure\nuser\u003e (graph/neighbors g :b)\n#{:c :a}\n\nuser\u003e (graph/adjacent? g :a :c)\nfalse\nuser\u003e (graph/adjacent? g :b :c)\ntrue\n```\n\nThe graph can be topologically sorted:\n\n``` clojure\nuser\u003e (require '[corallo.operations :as operations])\nuser\u003e (operations/topo-sort g)\n(:a :b :c :d)\n```\n\nAnd you can verify if the graph is acyclic and complete:\n\n``` clojure\nuser\u003e (operations/acyclic-graph? g)\ntrue\nuser\u003e (-\u003e (graph/add-edge g :d :a)\n          operations/acyclic-graph?)\nfalse\n\nuser\u003e (operations/complete-graph? g)\ntrue\nuser\u003e (-\u003e (graph/remove-edge g :b :c)\n          operations/complete-graph?)\nfalse\n```\n\nFinally, in a Clojure namespace the graph can be rendered as a PNG file thanks\nto [tangle](https://github.com/Macroz/tangle):\n\n``` clojure\nuser\u003e (require '[corallo.render :as render])\nuser\u003e (render/graph-\u003epng g \"/tmp/graph.png\")\nnil\n```\n\nAnd this is the resulting image for the graph `g`:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/7bridges-eu/corallo/blob/master/resources/graph.png\"/\u003e\n\u003c/p\u003e\n\nNote that you can also get the byte array representing the graph image:\n\n``` clojure\nuser\u003e (render/graph-\u003ebyte-array g)\n[-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 86, 0,\n 0, 1, 105, 8, 2, 0, 0, 0, -119, 111, 72, 108, 0, 0, 0, 6, 98, 75, 71, 68, 0,\n -1, 0, -1, 0, -1, -96, -67, -89, ...]\n```\n\n## License\nCopyright © 2019 7bridges s.r.l.\n\nDistributed under the Apache License 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F7bridges-eu%2Fcorallo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F7bridges-eu%2Fcorallo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F7bridges-eu%2Fcorallo/lists"}