Annotation of loncom/types/Queue.pm, revision 1.2

1.2     ! albertel    1: #  Implement a simple queue in terms of a list.
        !             2: #
        !             3: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
        !             4: #
        !             5: # Copyright Michigan State University Board of Trustees
        !             6: #
        !             7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             8: #
        !             9: # LON-CAPA is free software; you can redistribute it and/or modify
        !            10: # it under the terms of the GNU General Public License as published by
        !            11: # the Free Software Foundation; either version 2 of the License, or
        !            12: # (at your option) any later version.
1.1       foxr       13: #
1.2     ! albertel   14: # LON-CAPA is distributed in the hope that it will be useful,
        !            15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            17: # GNU General Public License for more details.
        !            18: #
        !            19: # You should have received a copy of the GNU General Public License
        !            20: # along with LON-CAPA; if not, write to the Free Software
        !            21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            22: #
        !            23: # /home/httpd/html/adm/gpl.txt
        !            24: #
        !            25: # http://www.lon-capa.org/
1.1       foxr       26: #
                     27: 
                     28: =pod
                     29: 
                     30: =head1 Queue
                     31: 
                     32: An object oriented implementation of a queue data structure.  queues
                     33: are first in last out data structures.
                     34: 
                     35: =head1 Member functions:
                     36: 
                     37: =cut
                     38: 
                     39: package Queue;
                     40: 
                     41: 
                     42: =pod
                     43: 
                     44: =head2 new 
                     45: 
                     46:   Construct a new queue.
                     47: 
                     48: =cut
                     49: 
                     50: sub new {
                     51:     my $class = shift;		# Class name to bless into.
                     52:     my $self  = [];		# Our data is a reference to an anon. array.
                     53: 
                     54:     bless($self, $class);	# Type this as an object.
                     55: 
                     56:     return $self;
                     57: }
                     58: 
                     59: =pod
                     60: 
                     61: =head2 enqueue
                     62: 
                     63:    Add an element to the tail of the queue.
                     64: 
                     65: =cut
                     66: 
                     67: sub enqueue {
                     68:     my $self = shift;		# Get object reference.
                     69:     my $item = shift;		# Get the item to enqueue...
                     70:     push(@$self, $item);		# Push the item to the back of the array.
                     71: 
                     72: 
                     73: }
                     74: 
                     75: =pod
                     76: 
                     77: =head2 dequeue
                     78: 
                     79:    Remove an element from the front of the queue.
                     80: 
                     81: =cut
                     82: 
                     83: sub dequeue {
                     84:     my $self = shift;		# Get object reference....
                     85:     return shift @$self;		# Remove from the front of the queue.
                     86: }
                     87: 
                     88: 
                     89: 1;
                     90: 
                     91: =pod
                     92: 
                     93: =head1 Theory
                     94: 
                     95: The queue is implemented as an array... enqueue is a thinly disguised
                     96: push, and dequeue is a thinly disguised shift.  This is probably quite
                     97: in efficient for large queues, but should be fine for reasonably sized
                     98: queues.
                     99: 
                    100: Note that since Perl is a dynamically typed language, queues can
                    101: contain objects of any data type and can even be heterogenously typed.
                    102: 
                    103: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>