diff options
Diffstat (limited to '')
-rw-r--r-- | mysql-test/suite/innodb/include/crc32.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/include/crc32.pl b/mysql-test/suite/innodb/include/crc32.pl new file mode 100644 index 00000000..c2bce09d --- /dev/null +++ b/mysql-test/suite/innodb/include/crc32.pl @@ -0,0 +1,33 @@ +# The following is Public Domain / Creative Commons CC0 from +# http://billauer.co.il/blog/2011/05/perl-crc32-crc-xs-module/ + +sub mycrc32 { + my ($input, $init_value, $polynomial) = @_; + + $init_value = 0 unless (defined $init_value); + $polynomial = 0xedb88320 unless (defined $polynomial); + + my @lookup_table; + + for (my $i=0; $i<256; $i++) { + my $x = $i; + for (my $j=0; $j<8; $j++) { + if ($x & 1) { + $x = ($x >> 1) ^ $polynomial; + } else { + $x = $x >> 1; + } + } + push @lookup_table, $x; + } + + my $crc = $init_value ^ 0xffffffff; + + foreach my $x (unpack ('C*', $input)) { + $crc = (($crc >> 8) & 0xffffff) ^ $lookup_table[ ($crc ^ $x) & 0xff ]; + } + + $crc = $crc ^ 0xffffffff; + + return $crc; +} |