2024/23 remove process dictionary use
This commit is contained in:
parent
460ffafdc5
commit
4f8926266e
1 changed files with 10 additions and 22 deletions
|
@ -52,32 +52,22 @@ defmodule LANGraph do
|
|||
|
||||
@empty MapSet.new([])
|
||||
def bron_kerbosch(g) do
|
||||
Process.delete(:maximal)
|
||||
neighbor_set = fn v ->
|
||||
n = neighbors(g, v) |> MapSet.new()
|
||||
n
|
||||
neighbors(g, v) |> MapSet.new()
|
||||
end
|
||||
bron_kerbosch(MapSet.new, g.nodes, MapSet.new, neighbor_set)
|
||||
bron_kerbosch(MapSet.new, g.nodes, MapSet.new, neighbor_set, [])
|
||||
end
|
||||
|
||||
def bron_kerbosch(r,o,o,_) when o == @empty do
|
||||
Process.put(
|
||||
:maximal,
|
||||
case Process.get(:maximal) do
|
||||
nil -> [r]
|
||||
l -> [r | l]
|
||||
end
|
||||
)
|
||||
end
|
||||
def bron_kerbosch(_,o,_,_) when o == @empty, do: @empty
|
||||
def bron_kerbosch(r,p,x,n) do
|
||||
def bron_kerbosch(r,o,o,_,acc) when o == @empty, do: [r | acc]
|
||||
def bron_kerbosch(_,o,_,_,acc) when o == @empty, do: acc
|
||||
def bron_kerbosch(r,p,x,n,acc) do
|
||||
for v <- p,
|
||||
n_v = n.(v),
|
||||
reduce: {p, x} do
|
||||
{p, x} ->
|
||||
bron_kerbosch(MapSet.put(r, v), MapSet.intersection(p, n_v), MapSet.intersection(x, n_v), n)
|
||||
{p |> MapSet.delete(v), x |> MapSet.put(v)}
|
||||
end
|
||||
reduce: {p, x, acc} do
|
||||
{p, x, acc} ->
|
||||
acc = bron_kerbosch(MapSet.put(r, v), MapSet.intersection(p, n_v), MapSet.intersection(x, n_v), n, acc)
|
||||
{p |> MapSet.delete(v), x |> MapSet.put(v), acc}
|
||||
end |> elem(2)
|
||||
end
|
||||
|
||||
def parse(input), do: input
|
||||
|
@ -104,8 +94,6 @@ defmodule LANGraph do
|
|||
input
|
||||
|> parse()
|
||||
|> bron_kerbosch()
|
||||
|
||||
Process.get(:maximal)
|
||||
|> Enum.max_by(&MapSet.size/1)
|
||||
|> Stream.map(&Atom.to_string/1)
|
||||
|> Enum.sort
|
||||
|
|
Loading…
Add table
Reference in a new issue