3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

PriorityQueue: rename get_entry to get

This commit is contained in:
Pragmatic Software 2021-07-18 18:14:28 -07:00
parent a6b2536663
commit d380422d14
2 changed files with 6 additions and 4 deletions

View File

@ -152,7 +152,7 @@ sub do_events {
# we call time for a fresh time, instead of using a stale $now that # we call time for a fresh time, instead of using a stale $now that
# could be in the past depending on a previous event's duration # could be in the past depending on a previous event's duration
if (time >= $self->{event_queue}->get_priority($i)) { if (time >= $self->{event_queue}->get_priority($i)) {
my $event = $self->{event_queue}->get_entry($i); my $event = $self->{event_queue}->get($i);
$self->{pbot}->{logger}->log("Processing event $i: $event->{id}\n") if $debug > 1; $self->{pbot}->{logger}->log("Processing event $i: $event->{id}\n") if $debug > 1;
@ -167,7 +167,7 @@ sub do_events {
} else { } else {
# no more events ready at this time # no more events ready at this time
if ($debug > 2) { if ($debug > 2) {
my $event = $self->{event_queue}->get_entry($i); my $event = $self->{event_queue}->get($i);
$self->{pbot}->{logger}->log("Event not ready yet: $event->{id} (timeout=$event->{priority})\n"); $self->{pbot}->{logger}->log("Event not ready yet: $event->{id} (timeout=$event->{priority})\n");
} }
@ -349,7 +349,7 @@ sub update_interval {
my ($self, $id, $interval, $dont_enqueue) = @_; my ($self, $id, $interval, $dont_enqueue) = @_;
for (my $i = 0; $i < $self->{event_queue}->count; $i++) { for (my $i = 0; $i < $self->{event_queue}->count; $i++) {
my $event = $self->{event_queue}->get_entry($i); my $event = $self->{event_queue}->get($i);
if ($event->{id} eq $id) { if ($event->{id} eq $id) {
if ($dont_enqueue) { if ($dont_enqueue) {

View File

@ -31,7 +31,7 @@ sub count {
return scalar @{$self->{queue}}; return scalar @{$self->{queue}};
} }
sub get_entry { sub get {
my ($self, $position) = @_; my ($self, $position) = @_;
return $self->{queue}->[$position]; return $self->{queue}->[$position];
} }
@ -51,6 +51,8 @@ sub remove {
sub find_enqueue_position { sub find_enqueue_position {
my ($self, $priority) = @_; my ($self, $priority) = @_;
$priority //= 0;
# no entries in queue yet, early-return first position # no entries in queue yet, early-return first position
return 0 if not @{$self->{queue}}; return 0 if not @{$self->{queue}};