Pure graph algorithms for dependency graphs.
All functions operate on a deps map: %{name => [deps]} where each key
is a derived field and the value is the list of fields it depends on.
Used by:
Rx.Graph— runtime reactive graphColocatedTransformer— compile-time JS metadata generationGraphMacro— defgraph compile-time JS generation- JS hook (
lavash_optimistic.js) — consumes the serialized output client-side
Summary
Functions
Reverse dependency index.
Topological sort via Kahn's algorithm.
BFS to find all fields transitively affected by changed_fields.
Functions
Reverse dependency index.
Returns %{field => [derived fields that depend on it]}.
iex> Lavash.Graph.build_dependents(%{doubled: [:count], quad: [:doubled]})
%{count: [:doubled], doubled: [:quad]}
Topological sort via Kahn's algorithm.
Returns derived field names in dependency order (leaves first). State fields (names not in the deps map keys) are ignored.
iex> Lavash.Graph.topo_sort(%{doubled: [:count], quad: [:doubled]})
[:doubled, :quad]
BFS to find all fields transitively affected by changed_fields.
Uses the dependents map (output of build_dependents/1).
iex> dependents = %{count: [:doubled], doubled: [:quad]}
iex> Lavash.Graph.transitive_dependents(dependents, [:count])
MapSet.new([:doubled, :quad])