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

Class Magic Functions - Hash32

Called when the VarHash32 function is called.

// define a class
class test
{
    my $x;
    my $y;
    Function __Construct($x, $y)
    {
        @this->$x = $x;
        @this->$y = $y;
    }
    Function __Hash32()
    {
        return VarHash32($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 = " . VarHash32($a);
say "Hash B = " . VarHash32($b);
say "Hash C = " . VarHash32($c);
say "Hash D = " . VarHash32($d);

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

// PRINTS
// Hash A = 3976369740
// Hash B = 3976369740
// Hash C = 2410285799
// Hash D = 3976369739
// 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 __Hash32()
    {
        return BinaryHash32Xx(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 = " . VarHash32($a);
say "Hash B = " . VarHash32($b);
say "Hash C = " . VarHash32($c);
say "Hash D = " . VarHash32($d);

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

// PRINTS
// Hash A = 3665279957
// Hash B = 3665279957
// Hash C = 1232333097
// Hash D = 1283036854
// 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