line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bijection; |
2
|
3
|
|
|
3
|
|
204600
|
use 5.006; use strict; use warnings; our $VERSION = '0.03'; |
|
3
|
|
|
3
|
|
31
|
|
|
3
|
|
|
3
|
|
15
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
61
|
|
|
3
|
|
|
|
|
27
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
154
|
|
3
|
3
|
|
|
3
|
|
1437
|
use Import::Export; use base qw/Import::Export/; |
|
3
|
|
|
3
|
|
51995
|
|
|
3
|
|
|
|
|
21
|
|
|
3
|
|
|
|
|
121
|
|
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
259
|
|
4
|
3
|
|
|
3
|
|
18
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
459
|
|
5
|
|
|
|
|
|
|
our %EX = (biject => [qw/all/], inverse => [qw/all/], bijection_set => [qw/all/]); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our (@ALPHA, $COUNT, %INDEX); |
8
|
|
|
|
|
|
|
BEGIN { |
9
|
|
|
|
|
|
|
sub bijection_set { |
10
|
5
|
|
|
5
|
1
|
1126
|
@ALPHA = @_; |
11
|
5
|
|
|
|
|
13
|
$COUNT = @ALPHA; |
12
|
5
|
|
|
|
|
16
|
my $index = -1; |
13
|
5
|
|
|
|
|
1074
|
%INDEX = map +( $_ => ++$index ), @ALPHA; |
14
|
|
|
|
|
|
|
} |
15
|
3
|
|
|
3
|
|
18
|
bijection_set(qw/b c d f g h j k l m n p q r s t v w x y z B C D F G H J K L M N P Q R S T V W X Y Z 0 1 2 3 4 5 6 7 8 9/); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub biject { |
19
|
5031
|
|
|
5031
|
1
|
2528837
|
my ($id, $out) = @_; |
20
|
5031
|
50
|
33
|
|
|
38949
|
croak "id to encode must be an integer and non-negative" unless (($id =~ m/^\d+$/ || $id > 0) and $id += $COUNT); |
|
|
|
33
|
|
|
|
|
21
|
5031
|
|
33
|
|
|
11939
|
do { $out .= $ALPHA[($id % $COUNT)]; 1} and $id = int($id/$COUNT) while ($id > 0); |
|
12411
|
|
|
|
|
21295
|
|
|
12411
|
|
|
|
|
33174
|
|
22
|
5031
|
|
33
|
|
|
17454
|
reverse ($out || $ALPHA[0]); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub inverse { |
26
|
5031
|
|
|
5031
|
1
|
29583
|
my ($out, $id) = (@_, 0); |
27
|
5031
|
|
33
|
|
|
19047
|
defined $INDEX{$_} && do { $id = $id * $COUNT + $INDEX{$_}; 1; } or croak "invalid character $_ in $out" for (split //, $out); |
|
12411
|
|
33
|
|
|
18117
|
|
|
12411
|
|
|
|
|
35458
|
|
28
|
5031
|
|
|
|
|
16813
|
$id - $COUNT; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |