"Sputnik" help  
Sputnik Help
Language Reference - Classes - Class Magic Functions - Hash64

Class Magic Functions - Hash64

Called when the VarHash64 function is called.

// define a class
class test
{
    my $x;
    my $y;
    Function __Construct($x, $y)
    {
        @this->$x = $x;
        @this->$y = $y;
    }
    Function __Hash64()
    {
        return VarHash64($x, $y);
    }
}

// create new instance
my $a = new test(10, 20);
my $b = new test(10, 20);
my $c = new test(10, 21);
my $d = new test(11, 20);

// show hashes
say "Hash A = " . VarHash64($a);
say "Hash B = " . VarHash64($b);
say "Hash C = " . VarHash64($c);
say "Hash D = " . VarHash64($d);

// test hashes
say "A == B result " . (VarHash64($a) == VarHash64($b));
say "A == C result " . (VarHash64($a) == VarHash64($c));
say "A == D result " . (VarHash64($a) == VarHash64($d));

// PRINTS
// Hash A = 18225461169253160524
// Hash B = 18225461169253160524
// Hash C = 18225461167687076583
// Hash D = 18225461169253160523
// A == B result true
// A == C result false
// A == D result false
Using Whirlpool to generate more entropy:
// define a class
class test
{
    my $x;
    my $y;
    Function __Construct($x, $y)
    {
        @this->$x = $x;
        @this->$y = $y;
    }
    Function __Hash64()
    {
        return BinaryHash64Xx(Hash("whirlpool", [$x, $y], true));
    }
}

// create new instance
my $a = new test(10, 20);
my $b = new test(10, 20);
my $c = new test(10, 21);
my $d = new test(11, 20);

// show hashes
say "Hash A = " . VarHash64($a);
say "Hash B = " . VarHash64($b);
say "Hash C = " . VarHash64($c);
say "Hash D = " . VarHash64($d);

// test hashes
say "A == B result " . (VarHash64($a) == VarHash64($b));
say "A == C result " . (VarHash64($a) == VarHash64($c));
say "A == D result " . (VarHash64($a) == VarHash64($d));

// PRINTS
// Hash A = 11574915013387932509
// Hash B = 11574915013387932509
// Hash C = 12831832706973414057
// Hash D = 14938236433252005922
// A == B result true
// A == C result false
// A == D result false

A full list of all possible magic functions can be found here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org