PriorityQueue: add `update_priority()`

This commit is contained in:
Pragmatic Software 2021-07-18 20:49:11 -07:00
parent fcb726d42e
commit 354f278cb2
1 changed files with 8 additions and 0 deletions

View File

@ -13,6 +13,7 @@ use PBot::Imports;
sub initialize {
my ($self, %conf) = @_;
# list of entrie; each entry is expected to have a `priority` and an `id` field
$self->{queue} = [];
}
@ -100,4 +101,11 @@ sub add {
return $position;
}
sub update_priority {
my ($self, $id, $priority) = @_;
my @entries = grep { $_->{id} eq $id } @{$self->{queue}};
map { $_->{priority} = $priority } @entries;
$self->{queue} = [ sort { $a->{priority} <=> $b->{priority} } @{$self->{queue}} ];
}
1;