Skip to content

Latest commit

 

History

History
76 lines (51 loc) · 1.93 KB

README.md

File metadata and controls

76 lines (51 loc) · 1.93 KB

Build Status

Digraphs Examples

As I am starting to get extremely interrested in Erlang, Elixir and Phoenix, i started to browse the web, and offcourse, since we are talking about Erlang which is pretty old , but soooo cool we have a bunch of code which has been battle-tested and hardened for many years.

This example show how to use an erlang module.

The example is basically taken from here.

And get this, it was written on: Sunday, November 18, 2007 with the title:

Digraph and your network, too easy

I started the module like this:

mix new digraph
cd digraph
mkdir src
--- copy content from link into servers.erl - See the "Now the code" section.
mix compile

After this you can start iex like this so you get the environment:

iex -S mix

Now we can start playing with the library. These are almost verbatim to what can be read in the blog-post from easyerl.

iex(1)> dag = :digraph.new()
{:digraph, 90132, 94227, 98328, true}

iex(2)> :servers.add(dag, [:karoten,:ultraten,:muloaten])
:ok

iex(3)> :servers.connect(dag, :karoten, [:ultraten, {:muloaten, :http}])
:ok

iex(4)> :servers.links(dag, :karoten)                                   
[{:karoten, :ultraten, []}, {:karoten, :muloaten, :http}]

iex(5)> :digraph.get_path(dag,:karoten, :muloaten)
[:karoten, :muloaten]

This shows how easy it is to use the library.

Installation

If available in Hex, the package can be installed as:

  1. Add digraphs to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:digraphs, "~> 0.1.0"}]
end
```
  1. Ensure digraphs is started before your application:
```elixir
def application do
  [applications: [:digraphs]]
end
```