# -*-Perl-*- 
# 
# 
#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################

package KeyTable;
use strict qw(vars);


my %keys=();
my $lastkey='null';

sub new {bless{}}


sub appendKey {

    my($pkg_ref, $thiskey)=@_;

    return if defined($keys{$thiskey});

    $keys{$thiskey}->[0]=$lastkey;
    $keys{$thiskey}->[1]='null';

    if ($lastkey ne 'null') {
	$keys{$lastkey}->[1]=$thiskey;
    }

    $lastkey=$thiskey;

}


sub prevKey {

    my($pkg_ref, $key)=@_;

     if ($keys{$key}->[0] ne 'null') {
	return $keys{$key}->[0];
     } 
 
     return undef;
}


sub nextKey {

    my($pkg_ref, $key)=@_;

     if ($keys{$key}->[1] ne 'null') {
	return $keys{$key}->[1];
     } 

     return undef;
}


sub dumpKeys {

    my $key;
    foreach $key (sort keys(%keys)) {
	print "KEY: $key: ", $keys{$key}->[0], " ", $keys{$key}->[1], "\n";
    }

}


1;

