-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(JUD) :: {path, list(integer()), JUD}. -file("src/yog/pathfinding/utils.gleam", 12). -spec compare_frontier( {JUE, list(integer())}, {JUE, list(integer())}, fun((JUE, JUE) -> 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( {JUH, integer()}, {JUH, integer()}, fun((JUH, JUH) -> 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( {JUI, JUI, list(integer())}, {JUI, JUI, list(integer())}, fun((JUI, JUI) -> 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(JUL, JUM), JUL, JUM, fun((JUM, JUM) -> 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.