Skip to content

Commit

Permalink
Emulate exact behaviour on lists with IntStr/NumStr
Browse files Browse the repository at this point in the history
First check numerically, if they're the same, then compare as strings.
  • Loading branch information
lizmat committed Aug 17, 2020
1 parent 410a428 commit 3f60d0a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core.c/Rakudo/Sorting.pm6
Expand Up @@ -30,11 +30,15 @@ my class Rakudo::Sorting {
for => "as a value when sorting",
).throw
}
multi sub compare(IntStr:D $a, IntStr:D $b) is raw { nqp::cmp_I($a,$b) }
multi sub compare( Int:D $a, Int:D $b) is raw { nqp::cmp_I($a,$b) }
multi sub compare( Str:D $a, Str:D $b) is raw { nqp::cmp_s($a,$b) }
multi sub compare(NumStr:D $a, NumStr:D $b) is raw { nqp::cmp_n($a,$b) }
multi sub compare( Num:D $a, Num:D $b) is raw { nqp::cmp_n($a,$b) }
multi sub compare(IntStr:D $a, IntStr:D $b) is raw {
nqp::cmp_I($a,$b) || nqp::cmp_s($a,$b)
}
multi sub compare(NumStr:D $a, NumStr:D $b) is raw {
nqp::cmp_n($a,$b) || nqp::cmp_s($a,$b)
}
multi sub compare(Int:D $a, Int:D $b) is raw { nqp::cmp_I($a,$b) }
multi sub compare(Str:D $a, Str:D $b) is raw { nqp::cmp_s($a,$b) }
multi sub compare(Num:D $a, Num:D $b) is raw { nqp::cmp_n($a,$b) }
multi sub compare(\a, \b) { a cmp b }

# https://en.wikipedia.org/wiki/Merge_sort#Bottom-up_implementation
Expand Down

0 comments on commit 3f60d0a

Please sign in to comment.