Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['24.2', '25.0']
elixir: ['1.12.3', '1.13.3', '1.14.0']
exclude:
- otp: '25.0'
elixir: '1.12.3'
include:
- elixir: 1.14.5
otp: 24.3

- elixir: 1.15.4
otp: 25.3

- elixir: 1.16.3
otp: 26.2

- otp: 27.2
elixir: 1.18.1
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ erl_crash.dump
# QuickCheck files
/.eqc-info
/*.eqc
.elixir_ls/
24 changes: 16 additions & 8 deletions lib/edge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ defmodule Graph.Edge do
defstruct v1: nil,
v2: nil,
weight: 1,
label: nil
label: nil,
properties: %{}

@type t :: %__MODULE__{
v1: Graph.vertex(),
v2: Graph.vertex(),
weight: integer | float,
label: term
label: term,
properties: map
}
@type edge_opt ::
{:weight, integer | float}
| {:label, term}
| {:properties, map}
@type edge_opts :: [edge_opt]

@doc """
Expand All @@ -36,24 +39,29 @@ defmodule Graph.Edge do
@spec new(Graph.vertex(), Graph.vertex()) :: t
@spec new(Graph.vertex(), Graph.vertex(), [edge_opt]) :: t | no_return
def new(v1, v2, opts \\ []) when is_list(opts) do
{weight, opts} = Keyword.pop(opts, :weight, 1)
{label, opts} = Keyword.pop(opts, :label)

%__MODULE__{
v1: v1,
v2: v2,
weight: Keyword.get(opts, :weight, 1),
label: Keyword.get(opts, :label)
weight: weight,
label: label,
properties: Keyword.get(opts, :properties, %{})
}
end

@doc false
def options_to_meta(opts) when is_list(opts) do
label = Keyword.get(opts, :label)
weight = Keyword.get(opts, :weight, 1)
properties = Keyword.get(opts, :properties, %{})

case {label, weight} do
{_, w} = meta when is_number(w) ->
meta
case {label, %{weight: weight, properties: properties}} do
{label, %{weight: w} = meta} when is_number(w) ->
{label, meta}

{_, _} ->
_other ->
raise ArgumentError, message: "invalid value for :weight, must be an integer"
end
end
Expand Down
Loading
Loading