use lib ".";
use SparseVector;

tie my @x, SparseVector;
tie my @y, SparseVector;
tie my @z, SparseVector;

$x[1]=17;
$x[17]=1;

print "x=", join(",", @x), "\n";

$y[2]=3;
$y[3]=7;
$y[7]=1;

print "y[2]=", $y[2], "\n";

print "y=", join(",", @y), "\n";

sub max($$) {
    my ($a, $b)=@_;
    if ($a>$b) { $a } else { $b };
}

## Addition.  This cannot be overloaded to work like: @z = @x + @y
## because @x in scalar context means the length of the array.
for($i = 0; $i < &max(@x,@y); $i++) {
    $z[$i] = $x[$i] + $y[$i];
}

print "x + y is ", join(",", @z), "\n";

untie @x;
untie @y;
