=head1 NAME

CFX5::ListManip - Functions for @list sorting and verification

=head1 SYNOPSIS

This module provides a set of functions for sorting and incrementing through @lists

=cut

package CFX5::ListManip;

use strict;

use vars qw($CVSVersion);
$CVSVersion='$Id$ ';

use CFX5::Output qw(:all);

use Exporter;
use vars qw(@ISA @EXPORT_OK);
@ISA=qw(Exporter);
@EXPORT_OK=qw(check_unique_list check_unique_numeric_list);

=head2 check_unique_list

  check_unique_list($description,@checklist);

Checks the array (@checklist) to ensure all stored values are unique. 
Throws error if any identical values are found.
$description of what is held in the array (being checked) e.g filenames.

=cut

sub check_unique_list{
  my $description = shift;
  my @checklist = @_;
  my %seenlist;

  for my $currentval (@checklist){
      if($seenlist{$currentval}){	  
	  _error("Re-use of $description $currentval not permitted");
	  return 0;
      }
      $seenlist{$currentval}++;
   }
  return 1;
}


=head2 check_unique_numeric_list

  check_unique_numeric_list(@checklist);

Checks the array (@checklist) to ensure all stored values are unique. 
Throws error if any identical values are found.

=cut

sub check_unique_numeric_list{
  my @checklist = @_;
 
  while(@checklist){
      my $checkvalue1 = shift @checklist; 
      for my $checkvalue2 (@checklist){
	  if($checkvalue1 == $checkvalue2){
	      _error("Values $checkvalue1 and $checkvalue2 are the same, this is not permitted");
	      return 0;
	  }
      }
   }
  return 1;
}

1;
