3v4l.org

run code in 300+ PHP versions simultaneously
<?php function snake($k,$y,$str1,$str2){ $x = $y - $k; while($x < count($str1) && $y < count($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } return $y; } function edit_distance_onp($str1, $str2){ $s1 = count($str1) > count($str2) ? $str2 : $str1; $s2 = count($str1) > count($str2) ? $str1 : $str2; $fp = array(); $x = 0; $y = 0; $k = 0; $p = 0; $offset = count($s1) + 1; $delta = count($s2) - count($s1); for ($i = 0; $i < 15; $i++) $fp[$i] = -1; for ($p = 0; $fp[$delta + $offset] != count($s2); $p++) { for($k = -$p; $k < $delta; $k++) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); for($k = $delta + $p; $k > $delta; $k--) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); $fp[$delta + $offset] = snake($delta, max($fp[$delta-1+$offset] + 1, $fp[$delta+1+$offset]), $s1, $s2); } return $delta + ($p - 1) * 2; } $cha1[0] = "aaa"; $cha1[1] = "bbb"; $cha1[2] = "ccc"; $cha2[0] = "ddd"; $cha2[1] = "bbb"; $cha2[2] = "fff"; echo edit_distance_onp($cha1,$cha2); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/59MWs
function name:  (null)
number of ops:  18
compiled vars:  !0 = $cha1, !1 = $cha2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN_DIM                                               !0, 0
          1        OP_DATA                                                  'aaa'
   32     2        ASSIGN_DIM                                               !0, 1
          3        OP_DATA                                                  'bbb'
   33     4        ASSIGN_DIM                                               !0, 2
          5        OP_DATA                                                  'ccc'
   34     6        ASSIGN_DIM                                               !1, 0
          7        OP_DATA                                                  'ddd'
   35     8        ASSIGN_DIM                                               !1, 1
          9        OP_DATA                                                  'bbb'
   36    10        ASSIGN_DIM                                               !1, 2
         11        OP_DATA                                                  'fff'
   37    12        INIT_FCALL                                               'edit_distance_onp'
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !1
         15        DO_FCALL                                      0  $8      
         16        ECHO                                                     $8
   38    17      > RETURN                                                   1

Function snake:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
Branch analysis from position: 15
Branch analysis from position: 20
Branch analysis from position: 15
filename:       /in/59MWs
function name:  snake
number of ops:  23
compiled vars:  !0 = $k, !1 = $y, !2 = $str1, !3 = $str2, !4 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    3     4        SUB                                              ~5      !1, !0
          5        ASSIGN                                                   !4, ~5
    4     6      > JMP                                                      ->9
    5     7    >   PRE_INC                                                  !4
    6     8        PRE_INC                                                  !1
    4     9    >   COUNT                                            ~9      !2
         10        IS_SMALLER                                       ~10     !4, ~9
         11      > JMPZ_EX                                          ~10     ~10, ->15
         12    >   COUNT                                            ~11     !3
         13        IS_SMALLER                                       ~12     !1, ~11
         14        BOOL                                             ~10     ~12
         15    > > JMPZ_EX                                          ~10     ~10, ->20
         16    >   FETCH_DIM_R                                      ~13     !2, !4
         17        FETCH_DIM_R                                      ~14     !3, !1
         18        IS_EQUAL                                         ~15     ~13, ~14
         19        BOOL                                             ~10     ~15
         20    > > JMPNZ                                                    ~10, ->7
    8    21    > > RETURN                                                   !1
    9    22*     > RETURN                                                   null

End of function snake

Function edit_distance_onp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 39
Branch analysis from position: 117
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 42
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 68
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 39
Branch analysis from position: 117
Branch analysis from position: 39
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 68
Branch analysis from position: 91
Branch analysis from position: 68
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 42
Branch analysis from position: 65
Branch analysis from position: 42
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
Branch analysis from position: 32
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
Branch analysis from position: 16
filename:       /in/59MWs
function name:  edit_distance_onp
number of ops:  122
compiled vars:  !0 = $str1, !1 = $str2, !2 = $s1, !3 = $s2, !4 = $fp, !5 = $x, !6 = $y, !7 = $k, !8 = $p, !9 = $offset, !10 = $delta, !11 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        COUNT                                            ~12     !0
          3        COUNT                                            ~13     !1
          4        IS_SMALLER                                               ~13, ~12
          5      > JMPZ                                                     ~14, ->8
          6    >   QM_ASSIGN                                        ~15     !1
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~15     !0
          9    >   ASSIGN                                                   !2, ~15
   12    10        COUNT                                            ~17     !0
         11        COUNT                                            ~18     !1
         12        IS_SMALLER                                               ~18, ~17
         13      > JMPZ                                                     ~19, ->16
         14    >   QM_ASSIGN                                        ~20     !0
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~20     !1
         17    >   ASSIGN                                                   !3, ~20
   13    18        ASSIGN                                                   !4, <array>
   14    19        ASSIGN                                                   !5, 0
   15    20        ASSIGN                                                   !6, 0
   16    21        ASSIGN                                                   !7, 0
   17    22        ASSIGN                                                   !8, 0
   18    23        COUNT                                            ~27     !2
         24        ADD                                              ~28     ~27, 1
         25        ASSIGN                                                   !9, ~28
   19    26        COUNT                                            ~30     !3
         27        COUNT                                            ~31     !2
         28        SUB                                              ~32     ~30, ~31
         29        ASSIGN                                                   !10, ~32
   20    30        ASSIGN                                                   !11, 0
         31      > JMP                                                      ->35
   21    32    >   ASSIGN_DIM                                               !4, !11
         33        OP_DATA                                                  -1
   20    34        PRE_INC                                                  !11
         35    >   IS_SMALLER                                               !11, 15
         36      > JMPNZ                                                    ~37, ->32
   22    37    >   ASSIGN                                                   !8, 0
         38      > JMP                                                      ->112
   23    39    >   MUL                                              ~39     !8, -1
         40        ASSIGN                                                   !7, ~39
         41      > JMP                                                      ->63
   24    42    >   ADD                                              ~41     !7, !9
         43        INIT_FCALL                                               'snake'
         44        SEND_VAR                                                 !7
         45        INIT_FCALL                                               'max'
         46        SUB                                              ~43     !7, 1
         47        ADD                                              ~44     ~43, !9
         48        FETCH_DIM_R                                      ~45     !4, ~44
         49        ADD                                              ~46     ~45, 1
         50        SEND_VAL                                                 ~46
         51        ADD                                              ~47     !7, 1
         52        ADD                                              ~48     ~47, !9
         53        FETCH_DIM_R                                      ~49     !4, ~48
         54        SEND_VAL                                                 ~49
         55        DO_ICALL                                         $50     
         56        SEND_VAR                                                 $50
         57        SEND_VAR                                                 !2
         58        SEND_VAR                                                 !3
         59        DO_FCALL                                      0  $51     
         60        ASSIGN_DIM                                               !4, ~41
         61        OP_DATA                                                  $51
   23    62        PRE_INC                                                  !7
         63    >   IS_SMALLER                                               !7, !10
         64      > JMPNZ                                                    ~53, ->42
   25    65    >   ADD                                              ~54     !10, !8
         66        ASSIGN                                                   !7, ~54
         67      > JMP                                                      ->89
   26    68    >   ADD                                              ~56     !7, !9
         69        INIT_FCALL                                               'snake'
         70        SEND_VAR                                                 !7
         71        INIT_FCALL                                               'max'
         72        SUB                                              ~58     !7, 1
         73        ADD                                              ~59     ~58, !9
         74        FETCH_DIM_R                                      ~60     !4, ~59
         75        ADD                                              ~61     ~60, 1
         76        SEND_VAL                                                 ~61
         77        ADD                                              ~62     !7, 1
         78        ADD                                              ~63     ~62, !9
         79        FETCH_DIM_R                                      ~64     !4, ~63
         80        SEND_VAL                                                 ~64
         81        DO_ICALL                                         $65     
         82        SEND_VAR                                                 $65
         83        SEND_VAR                                                 !2
         84        SEND_VAR                                                 !3
         85        DO_FCALL                                      0  $66     
         86        ASSIGN_DIM                                               !4, ~56
         87        OP_DATA                                                  $66
   25    88        PRE_DEC                                                  !7
         89    >   IS_SMALLER                                               !10, !7
         90      > JMPNZ                                                    ~68, ->68
   27    91    >   ADD                                              ~69     !10, !9
         92        INIT_FCALL                                               'snake'
         93        SEND_VAR                                                 !10
         94        INIT_FCALL                                               'max'
         95        SUB                                              ~71     !10, 1
         96        ADD                                              ~72     ~71, !9
         97        FETCH_DIM_R                                      ~73     !4, ~72
         98        ADD                                              ~74     ~73, 1
         99        SEND_VAL                                                 ~74
        100        ADD                                              ~75     !10, 1
        101        ADD                                              ~76     ~75, !9
        102        FETCH_DIM_R                                      ~77     !4, ~76
        103        SEND_VAL                                                 ~77
        104        DO_ICALL                                         $78     
        105        SEND_VAR                                                 $78
        106        SEND_VAR                                                 !2
        107        SEND_VAR                                                 !3
        108        DO_FCALL                                      0  $79     
        109        ASSIGN_DIM                                               !4, ~69
        110        OP_DATA                                                  $79
   22   111        PRE_INC                                                  !8
        112    >   ADD                                              ~81     !10, !9
        113        FETCH_DIM_R                                      ~82     !4, ~81
        114        COUNT                                            ~83     !3
        115        IS_NOT_EQUAL                                             ~82, ~83
        116      > JMPNZ                                                    ~84, ->39
   29   117    >   SUB                                              ~85     !8, 1
        118        MUL                                              ~86     ~85, 2
        119        ADD                                              ~87     !10, ~86
        120      > RETURN                                                   ~87
   30   121*     > RETURN                                                   null

End of function edit_distance_onp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.93 ms | 1415 KiB | 19 Q