-
-
Save rightfold/25dbf34cb276c21d0753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Queue::Geminiphobic; | |
use Modern::Perl; | |
use Set::Scalar; | |
sub new { | |
my ($class, @elements) = @_; | |
bless { elements => \@elements, had => Set::Scalar->new() }, $class; | |
} | |
sub enqueue { | |
my ($self, @values) = @_; | |
foreach my $value (@values) { | |
unless ($self->{had}->has($value)) { | |
$self->{had}->insert($value); | |
push @{$self->{elements}}, $value; | |
} | |
} | |
} | |
sub dequeue { | |
shift @{shift->{elements}}; | |
} | |
sub is_empty { | |
!@{shift->{elements}}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment