3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function edit_distance_ond($str1 ,$str2){ $array = array(); $x = 0; $y = 0; $offset = count($str1); $array[$offset + 1] = 0; for($D = 0; $D <= count($str1) + count($str2); $D++){ for($k = -$D; $k <= $D; $k += 2){ if($k == -$D || $k != $D && $array[$k-1+$offset] < $array[$k+1+$offset]) $x = $array[$k+1+$offset]; else $x = $array[$k-1+$offset] + 1; $y = $x - $k; while($x < count($str1) && $y < count($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } $array[$k+$offset] = $x; if($x >= count($str1) && $y >= count($str2)) return $D; } } return -1; } $a = array(); $a[0] = "aaa"; $a[1] = "bbb"; $a[2] = "ccc"; $b = array(); $b[0] = "www"; $b[1] = "bbb"; $b[2] = "qqq"; echo edit_distance_ond($a,$b); ?>
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/02T5i
function name:  (null)
number of ops:  21
compiled vars:  !0 = $a, !1 = $b
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
  26     1        ASSIGN                                                   !0, <array>
  27     2        ASSIGN_DIM                                               !0, 0
         3        OP_DATA                                                  'aaa'
  28     4        ASSIGN_DIM                                               !0, 1
         5        OP_DATA                                                  'bbb'
  29     6        ASSIGN_DIM                                               !0, 2
         7        OP_DATA                                                  'ccc'
  30     8        ASSIGN                                                   !1, <array>
  31     9        ASSIGN_DIM                                               !1, 0
        10        OP_DATA                                                  'www'
  32    11        ASSIGN_DIM                                               !1, 1
        12        OP_DATA                                                  'bbb'
  33    13        ASSIGN_DIM                                               !1, 2
        14        OP_DATA                                                  'qqq'
  34    15        INIT_FCALL                                               'edit_distance_ond'
        16        SEND_VAR                                                 !0
        17        SEND_VAR                                                 !1
        18        DO_FCALL                                      0  $10     
        19        ECHO                                                     $10
        20      > RETURN                                                   1

Function edit_distance_ond:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 85
Branch analysis from position: 85
Jump found. Position 1 = 94, Position 2 = 14
Branch analysis from position: 94
Jump found. Position 1 = -2
Branch analysis from position: 14
Jump found. Position 1 = 81
Branch analysis from position: 81
Jump found. Position 1 = 83, Position 2 = 17
Branch analysis from position: 83
Jump found. Position 1 = 94, Position 2 = 14
Branch analysis from position: 94
Branch analysis from position: 14
Branch analysis from position: 17
Jump found. Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
Jump found. Position 1 = 22, Position 2 = 30
Branch analysis from position: 22
Jump found. Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
Jump found. Position 1 = 42
Branch analysis from position: 42
Jump found. Position 1 = 49
Branch analysis from position: 49
Jump found. Position 1 = 54, Position 2 = 59
Branch analysis from position: 54
Jump found. Position 1 = 60, Position 2 = 64
Branch analysis from position: 60
Jump found. Position 1 = 65, Position 2 = 45
Branch analysis from position: 65
Jump found. Position 1 = 73, Position 2 = 78
Branch analysis from position: 73
Jump found. Position 1 = 79, Position 2 = 80
Branch analysis from position: 79
Jump found. Position 1 = -2
Branch analysis from position: 80
Jump found. Position 1 = 83, Position 2 = 17
Branch analysis from position: 83
Branch analysis from position: 17
Branch analysis from position: 78
Branch analysis from position: 45
Jump found. Position 1 = 54, Position 2 = 59
Branch analysis from position: 54
Branch analysis from position: 59
Branch analysis from position: 64
Branch analysis from position: 59
Branch analysis from position: 37
Jump found. Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 30
Branch analysis from position: 31
filename:       /in/02T5i
function name:  edit_distance_ond
number of ops:  96
compiled vars:  !0 = $str1, !1 = $str2, !2 = $array, !3 = $x, !4 = $y, !5 = $offset, !6 = $D, !7 = $k
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   RECV                                             !0      
         1        RECV                                             !1      
   3     2        ASSIGN                                                   !2, <array>
   4     3        ASSIGN                                                   !3, 0
   5     4        ASSIGN                                                   !4, 0
   6     5        INIT_FCALL                                               'count'
         6        SEND_VAR                                                 !0
         7        DO_ICALL                                         $11     
         8        ASSIGN                                                   !5, $11
   7     9        ADD                                              ~13     !5, 1
        10        ASSIGN_DIM                                               !2, ~13
        11        OP_DATA                                                  0
   8    12        ASSIGN                                                   !6, 0
        13      > JMP                                                      ->85
   9    14    >   SUB                                              ~16     0, !6
        15        ASSIGN                                                   !7, ~16
        16      > JMP                                                      ->81
  10    17    >   SUB                                              ~18     0, !6
        18        IS_EQUAL                                         ~19     !7, ~18
        19      > JMPNZ_EX                                         ~19     ~19, ->31
        20    >   IS_NOT_EQUAL                                     ~20     !7, !6
        21      > JMPZ_EX                                          ~20     ~20, ->30
        22    >   SUB                                              ~21     !7, 1
        23        ADD                                              ~22     ~21, !5
        24        FETCH_DIM_R                                      $23     !2, ~22
        25        ADD                                              ~24     !7, 1
        26        ADD                                              ~25     ~24, !5
        27        FETCH_DIM_R                                      $26     !2, ~25
        28        IS_SMALLER                                       ~27     $23, $26
        29        BOOL                                             ~20     ~27
        30    >   BOOL                                             ~19     ~20
        31    > > JMPZ                                                     ~19, ->37
  11    32    >   ADD                                              ~28     !7, 1
        33        ADD                                              ~29     ~28, !5
        34        FETCH_DIM_R                                      $30     !2, ~29
        35        ASSIGN                                                   !3, $30
        36      > JMP                                                      ->42
  13    37    >   SUB                                              ~32     !7, 1
        38        ADD                                              ~33     ~32, !5
        39        FETCH_DIM_R                                      $34     !2, ~33
        40        ADD                                              ~35     $34, 1
        41        ASSIGN                                                   !3, ~35
  14    42    >   SUB                                              ~37     !3, !7
        43        ASSIGN                                                   !4, ~37
  15    44      > JMP                                                      ->49
  16    45    >   POST_INC                                         ~39     !3
        46        FREE                                                     ~39
  17    47        POST_INC                                         ~40     !4
        48        FREE                                                     ~40
  15    49    >   INIT_FCALL                                               'count'
        50        SEND_VAR                                                 !0
        51        DO_ICALL                                         $41     
        52        IS_SMALLER                                       ~42     !3, $41
        53      > JMPZ_EX                                          ~42     ~42, ->59
        54    >   INIT_FCALL                                               'count'
        55        SEND_VAR                                                 !1
        56        DO_ICALL                                         $43     
        57        IS_SMALLER                                       ~44     !4, $43
        58        BOOL                                             ~42     ~44
        59    > > JMPZ_EX                                          ~42     ~42, ->64
        60    >   FETCH_DIM_R                                      $45     !0, !3
        61        FETCH_DIM_R                                      $46     !1, !4
        62        IS_EQUAL                                         ~47     $45, $46
        63        BOOL                                             ~42     ~47
        64    > > JMPNZ                                                    ~42, ->45
  19    65    >   ADD                                              ~48     !7, !5
        66        ASSIGN_DIM                                               !2, ~48
        67        OP_DATA                                                  !3
  20    68        INIT_FCALL                                               'count'
        69        SEND_VAR                                                 !0
        70        DO_ICALL                                         $50     
        71        IS_SMALLER_OR_EQUAL                              ~51     $50, !3
        72      > JMPZ_EX                                          ~51     ~51, ->78
        73    >   INIT_FCALL                                               'count'
        74        SEND_VAR                                                 !1
        75        DO_ICALL                                         $52     
        76        IS_SMALLER_OR_EQUAL                              ~53     $52, !4
        77        BOOL                                             ~51     ~53
        78    > > JMPZ                                                     ~51, ->80
  21    79    > > RETURN                                                   !6
   9    80    >   ASSIGN_ADD                                    0          !7, 2
        81    >   IS_SMALLER_OR_EQUAL                              ~55     !7, !6
        82      > JMPNZ                                                    ~55, ->17
   8    83    >   POST_INC                                         ~56     !6
        84        FREE                                                     ~56
        85    >   INIT_FCALL                                               'count'
        86        SEND_VAR                                                 !0
        87        DO_ICALL                                         $57     
        88        INIT_FCALL                                               'count'
        89        SEND_VAR                                                 !1
        90        DO_ICALL                                         $58     
        91        ADD                                              ~59     $57, $58
        92        IS_SMALLER_OR_EQUAL                              ~60     !6, ~59
        93      > JMPNZ                                                    ~60, ->14
  24    94    > > RETURN                                                   -1
  25    95*     > RETURN                                                   null

End of function edit_distance_ond

Generated using Vulcan Logic Dumper, using php 7.3.0