mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-27 05:02:34 +01:00
PriorityQueue: add update_priority()
This commit is contained in:
parent
fcb726d42e
commit
354f278cb2
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user