Current section
Files
Jump to
Current section
Files
src/yog@internal@priority_queue.erl
-module(yog@internal@priority_queue).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yog/internal/priority_queue.gleam").
-export([new/1, pop/1, peek/1, push/2, is_empty/1, count/1, reorder/2, from_list/2, to_list/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(false).
-file("src/yog/internal/priority_queue.gleam", 18).
?DOC(false).
-spec new(fun((FNA, FNA) -> gleam@order:order())) -> yog@internal@pairing_heap:heap(FNA).
new(Compare) ->
yog@internal@pairing_heap:new(Compare).
-file("src/yog/internal/priority_queue.gleam", 24).
?DOC(false).
-spec pop(yog@internal@pairing_heap:heap(FNC)) -> {ok,
{FNC, yog@internal@pairing_heap:heap(FNC)}} |
{error, nil}.
pop(Queue) ->
yog@internal@pairing_heap:delete_min(Queue).
-file("src/yog/internal/priority_queue.gleam", 29).
?DOC(false).
-spec peek(yog@internal@pairing_heap:heap(FNH)) -> {ok, FNH} | {error, nil}.
peek(Queue) ->
yog@internal@pairing_heap:find_min(Queue).
-file("src/yog/internal/priority_queue.gleam", 34).
?DOC(false).
-spec push(yog@internal@pairing_heap:heap(FNL), FNL) -> yog@internal@pairing_heap:heap(FNL).
push(Queue, Item) ->
yog@internal@pairing_heap:insert(Queue, Item).
-file("src/yog/internal/priority_queue.gleam", 39).
?DOC(false).
-spec is_empty(yog@internal@pairing_heap:heap(any())) -> boolean().
is_empty(Queue) ->
case yog@internal@pairing_heap:find_min(Queue) of
{ok, _} ->
false;
{error, _} ->
true
end.
-file("src/yog/internal/priority_queue.gleam", 48).
?DOC(false).
-spec count(yog@internal@pairing_heap:heap(any())) -> integer().
count(Queue) ->
case yog@internal@pairing_heap:delete_min(Queue) of
{ok, {_, Q}} ->
count(Q) + 1;
{error, _} ->
0
end.
-file("src/yog/internal/priority_queue.gleam", 56).
?DOC(false).
-spec reorder(
yog@internal@pairing_heap:heap(FNS),
fun((FNS, FNS) -> gleam@order:order())
) -> yog@internal@pairing_heap:heap(FNS).
reorder(Queue, Compare) ->
case yog@internal@pairing_heap:delete_min(Queue) of
{ok, {X, Q}} ->
yog@internal@pairing_heap:insert(reorder(Q, Compare), X);
{error, _} ->
yog@internal@pairing_heap:new(Compare)
end.
-file("src/yog/internal/priority_queue.gleam", 64).
?DOC(false).
-spec from_list(list(FNV), fun((FNV, FNV) -> gleam@order:order())) -> yog@internal@pairing_heap:heap(FNV).
from_list(List, Compare) ->
gleam@list:fold(List, new(Compare), fun yog@internal@pairing_heap:insert/2).
-file("src/yog/internal/priority_queue.gleam", 69).
?DOC(false).
-spec to_list(yog@internal@pairing_heap:heap(FNY)) -> list(FNY).
to_list(Queue) ->
case yog@internal@pairing_heap:delete_min(Queue) of
{ok, {X, Q}} ->
[X | to_list(Q)];
{error, _} ->
[]
end.