Skip to content

Commit

Permalink
Use built-in UInt instead of manual signature constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbkr committed May 7, 2024
1 parent 32412f4 commit 1bb807e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TinyID",
"version": "1.0.5",
"version": "1.0.6",
"description": "Shorten and obfuscate IDs.",
"authors" : [ "Paweł bbkr Pabian" ],
"auth": "zef:bbkr",
Expand Down
8 changes: 4 additions & 4 deletions lib/TinyID.rakumod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
unit class TinyID;

has $!length;
has UInt $!length;
has %!chars_to_positions;
has @!positions_to_chars;

Expand All @@ -10,7 +10,7 @@ submethod BUILD ( Str:D :$key where { .chars >= 2 and not /(.).*$0/ } ){
%!chars_to_positions = @!positions_to_chars.kv.reverse;
}

method encode ( Int:D $in where $in >= 0 ) returns Str:D {
method encode ( UInt:D $in ) returns Str:D {
my $tmp = $in;
my Str:D $out = '';

Expand All @@ -22,8 +22,8 @@ method encode ( Int:D $in where $in >= 0 ) returns Str:D {
return $out.flip;
}

method decode ( Str:D $in where $in.comb (<=) @!positions_to_chars ) returns Int:D {
my Int:D $out = 0;
method decode ( Str:D $in where $in.comb (<=) @!positions_to_chars ) returns UInt:D {
my UInt:D $out = 0;

for $in.comb.reverse.kv -> $pos, $tmp {
$out += %!chars_to_positions{ $tmp } * $!length ** $pos;
Expand Down

0 comments on commit 1bb807e

Please sign in to comment.