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([])
|
@empty MapSet.new([])
|
||||||
def bron_kerbosch(g) do
|
def bron_kerbosch(g) do
|
||||||
Process.delete(:maximal)
|
|
||||||
neighbor_set = fn v ->
|
neighbor_set = fn v ->
|
||||||
n = neighbors(g, v) |> MapSet.new()
|
neighbors(g, v) |> MapSet.new()
|
||||||
n
|
|
||||||
end
|
end
|
||||||
bron_kerbosch(MapSet.new, g.nodes, MapSet.new, neighbor_set)
|
bron_kerbosch(MapSet.new, g.nodes, MapSet.new, neighbor_set, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def bron_kerbosch(r,o,o,_) when o == @empty do
|
def bron_kerbosch(r,o,o,_,acc) when o == @empty, do: [r | acc]
|
||||||
Process.put(
|
def bron_kerbosch(_,o,_,_,acc) when o == @empty, do: acc
|
||||||
:maximal,
|
def bron_kerbosch(r,p,x,n,acc) do
|
||||||
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
|
|
||||||
for v <- p,
|
for v <- p,
|
||||||
n_v = n.(v),
|
n_v = n.(v),
|
||||||
reduce: {p, x} do
|
reduce: {p, x, acc} do
|
||||||
{p, x} ->
|
{p, x, acc} ->
|
||||||
bron_kerbosch(MapSet.put(r, v), MapSet.intersection(p, n_v), MapSet.intersection(x, n_v), n)
|
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)}
|
{p |> MapSet.delete(v), x |> MapSet.put(v), acc}
|
||||||
end
|
end |> elem(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(input), do: input
|
def parse(input), do: input
|
||||||
|
@ -104,8 +94,6 @@ defmodule LANGraph do
|
||||||
input
|
input
|
||||||
|> parse()
|
|> parse()
|
||||||
|> bron_kerbosch()
|
|> bron_kerbosch()
|
||||||
|
|
||||||
Process.get(:maximal)
|
|
||||||
|> Enum.max_by(&MapSet.size/1)
|
|> Enum.max_by(&MapSet.size/1)
|
||||||
|> Stream.map(&Atom.to_string/1)
|
|> Stream.map(&Atom.to_string/1)
|
||||||
|> Enum.sort
|
|> Enum.sort
|
||||||
|
|
Loading…
Add table
Reference in a new issue