Michael Shipper
and 1 contributors

NAME

Data::Range::Compare::Stream::Iterator::Array - simple array iterator

SYNOPSIS

  use Data::Range::Compare::Stream;
  use Data::Range::Compare::Stream::Iterator::Array;

  my $iterator=Data::Range::Compare::Stream::Iterator::Array->new(
    new_from=>'Data::Range::Compare::Stream',
  );

  # create a new range and add it to the iterator
  $iterator->create_range(0,0);

  my $range=Data::Range::Compare::Stream->new(0,1);

  # add a new range from the existing one
  $iterator->add_range($range);

  $iterator->prepare_for_consolidate_asc;

  while($iterator->has_next) {
    my $next_range=$iterator->get_next;
  }

DESCRIPTION

This module implements Data::Range::Compare::Stream::Iterator::Base and provides an array iterator.

OO Methods

  • my $iterator=new Data::Range::Compare::Stream::Iterator::Array;

    Instance Constructor, all arguments are optional:

          new_from   =>  'Data::Range::Compare::Stream'
            
            # Defines what class to call new against for $iterator->create_range(x,x,x)
    
          range_list =>  []
            
            # Defines the array reference used internally
    
          sorted     =>  0
    
            # Sets the sorted state
    
           autosort  =>  'prepare_for_consolidate_asc' or 'prepare_for_consolidate_desc'
             
             # Allows for dynamic sort support when has_next is called
  • $iterator->add_range($obj)

    Adds $obj to the internal array. This function returns false once $iterator has been sorted

  • $iterator->create_range(0,0);

    Creates a new range object and adds it to the internal array. This function returns false once $iterator has been sorted.

  • $iterator->prepare_for_consolidate_asc;

    Sorts the internal array and sets the sorted flag $iterator->has_next returns false until the internal array has been sorted.

  • $iterator->prepare_for_consolidate_desc;

    Sorts the internal array and sets the sorted flag: $iterator->has_next returns false until the internal array has been sorted.

  • $iterator->set_sorted(0|1);

    Used to set the internal array sorted flag

  • if($iterator->sorted) { ... }

    Returns the sorted state

  • while($iterator->has_next) { ... }

    Returns true when the internal array has been sorted and still contains data. If autosrot has been set, then it will return true if the array contains data.

  • my $range=$iterator->get_next;

    If $iterator->has_next returns true, then the next value from the internal array is returned

  • my $string=$iterator->to_string;

    Returns the instance name of $iterator

  • $iterator->insert_range($range);

    Inserts a range into a the iterator regardless of the "sorted" state. Use with caution!

  • if($iterator->prepared) { ... }

    Returns the prepared state

  • $iterator->prepare

    Prepares the object to be used for iteration.

SEE ALSO

Data::Range::Compare::Stream::Cookbook

AUTHOR

Michael Shipper

Source-Forge Project

As of version 0.001 the Project has been moved to Source-Forge.net

Data Range Compare https://sourceforge.net/projects/data-range-comp/

COPYRIGHT

Copyright 2011 Michael Shipper. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.