Current section

Files

Jump to
yog src yog@pathfinding@utils.erl
Raw

src/yog@pathfinding@utils.erl

-module(yog@pathfinding@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yog/pathfinding/utils.gleam").
-export([compare_frontier/3, compare_distance_frontier/3, compare_a_star_frontier/3, should_explore_node/4]).
-export_type([path/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Shared types and utilities for pathfinding algorithms.\n").
-type path(KHJ) :: {path, list(integer()), KHJ}.
-file("src/yog/pathfinding/utils.gleam", 12).
-spec compare_frontier(
{KHK, list(integer())},
{KHK, list(integer())},
fun((KHK, KHK) -> gleam@order:order())
) -> gleam@order:order().
compare_frontier(A, B, Cmp) ->
Cmp(erlang:element(1, A), erlang:element(1, B)).
-file("src/yog/pathfinding/utils.gleam", 20).
-spec compare_distance_frontier(
{KHN, integer()},
{KHN, integer()},
fun((KHN, KHN) -> gleam@order:order())
) -> gleam@order:order().
compare_distance_frontier(A, B, Cmp) ->
Cmp(erlang:element(1, A), erlang:element(1, B)).
-file("src/yog/pathfinding/utils.gleam", 28).
-spec compare_a_star_frontier(
{KHO, KHO, list(integer())},
{KHO, KHO, list(integer())},
fun((KHO, KHO) -> gleam@order:order())
) -> gleam@order:order().
compare_a_star_frontier(A, B, Cmp) ->
Cmp(erlang:element(1, A), erlang:element(1, B)).
-file("src/yog/pathfinding/utils.gleam", 38).
?DOC(
" Helper to determine if a node should be explored based on distance comparison.\n"
" Returns True if the node hasn't been visited or if the new distance is shorter.\n"
).
-spec should_explore_node(
gleam@dict:dict(KHR, KHS),
KHR,
KHS,
fun((KHS, KHS) -> gleam@order:order())
) -> boolean().
should_explore_node(Visited, Node, New_dist, Compare) ->
case gleam_stdlib:map_get(Visited, Node) of
{ok, Prev_dist} ->
case Compare(New_dist, Prev_dist) of
lt ->
true;
_ ->
false
end;
{error, nil} ->
true
end.