3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class RangesUtil { final private function __construct() {} /** * @param array $element * * @return int[] * Format: $[$value] = $count */ static function elementExtractUnsortedStats(array $element) { $rawStats = array(); foreach ($element as $value => $item) { if (isset($item['#count']) && is_int($item['#count'])) { $rawStats[$value] = $item['#count']; } } return $rawStats; } /** * @param float[]|int[] $steps * Format: $[] = $stepValue * @param int[] $ustats * (unsorted) stats. * Format: $[$value] = $count * @param bool $below * TRUE to accumulate below, FALSE to accumulate above. * @param bool $dedupe * * @return int[] * Format: $[$value] = $countAccum */ static function stepsUstatsAccumulate(array $steps, array $ustats, $below, $dedupe = FALSE) { $statsCombined = $ustats + array_fill_keys($steps, 0); ksort($statsCombined, SORT_NUMERIC); $statsCombinedAccum = self::statsAccumulate($statsCombined, $below); $stepsAccum = array(); foreach ($steps as $step) { $stepsAccum[$step] = $statsCombinedAccum[$step]; } if ($dedupe) { $stepsAccum = self::statsAccumDedupe($stepsAccum, $below); } return $stepsAccum; } /** * @param int[] $statsAccum * Format: $[$value] = $countAccum * @param bool $below * * @return int[] * Format: $[$value] = $countAccum */ static function statsAccumDedupe(array $statsAccum, $below) { $countPrev = NULL; foreach ($below ? $statsAccum : array_reverse($statsAccum, TRUE) as $value => $countAccum) { if ($countPrev === $countAccum) { unset($statsAccum[$value]); } } return $statsAccum; } /** * @param array $rawStats * * @return int[] * Format: $[$value] = $count */ static function unsortedStatsGetStats(array $rawStats) { ksort($rawStats, SORT_NUMERIC); return $rawStats; } /** * @param int[] $stats * (sorted) stats. * Format: $[$value] = $count * @param bool $below * TRUE to accumulate below, FALSE to accumulate above. * * @return int[] * Format: $[$value] = $countAccum */ static function statsAccumulate(array $stats, $below) { $total = 0; foreach ($below ? $stats : array_reverse($stats, TRUE) as $value => $count) { $total += $count; $stats[$value] = $total; } return $stats; } } $ustats = array( 0 => 2, 3 => 10, 7 => 100, 8 => 1000, 19 => 10000, ); $steps = array(0, 2, 5, 10, 20); var_export(RangesUtil::stepsUstatsAccumulate($steps, $ustats));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g07M3
function name:  (null)
number of ops:  10
compiled vars:  !0 = $ustats, !1 = $steps
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  102     0  E >   ASSIGN                                                   !0, <array>
  110     1        ASSIGN                                                   !1, <array>
  112     2        INIT_FCALL                                               'var_export'
          3        INIT_STATIC_METHOD_CALL                                  'RangesUtil', 'stepsUstatsAccumulate'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Class RangesUtil:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g07M3
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E > > RETURN                                                   null

End of function __construct

Function elementextractunsortedstats:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 10
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/g07M3
function name:  elementExtractUnsortedStats
number of ops:  18
compiled vars:  !0 = $element, !1 = $rawStats, !2 = $item, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, <array>
   16     2      > FE_RESET_R                                       $5      !0, ->15
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->15
          4    >   ASSIGN                                                   !3, ~6
   17     5        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !2, '%23count'
          6      > JMPZ_EX                                          ~8      ~8, ->10
          7    >   FETCH_DIM_R                                      ~9      !2, '%23count'
          8        TYPE_CHECK                                   16  ~10     ~9
          9        BOOL                                             ~8      ~10
         10    > > JMPZ                                                     ~8, ->14
   18    11    >   FETCH_DIM_R                                      ~12     !2, '%23count'
         12        ASSIGN_DIM                                               !1, !3
         13        OP_DATA                                                  ~12
   16    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $5
   21    16      > RETURN                                                   !1
   22    17*     > RETURN                                                   null

End of function elementextractunsortedstats

Function stepsustatsaccumulate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 26
filename:       /in/g07M3
function name:  stepsUstatsAccumulate
number of ops:  35
compiled vars:  !0 = $steps, !1 = $ustats, !2 = $below, !3 = $dedupe, !4 = $statsCombined, !5 = $statsCombinedAccum, !6 = $stepsAccum, !7 = $step
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      <false>
   38     4        INIT_FCALL                                               'array_fill_keys'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 0
          7        DO_ICALL                                         $8      
          8        ADD                                              ~9      !1, $8
          9        ASSIGN                                                   !4, ~9
   39    10        INIT_FCALL                                               'ksort'
         11        SEND_REF                                                 !4
         12        SEND_VAL                                                 1
         13        DO_ICALL                                                 
   40    14        INIT_STATIC_METHOD_CALL                                  'statsAccumulate'
         15        SEND_VAR_EX                                              !4
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0  $12     
         18        ASSIGN                                                   !5, $12
   41    19        ASSIGN                                                   !6, <array>
   42    20      > FE_RESET_R                                       $15     !0, ->26
         21    > > FE_FETCH_R                                               $15, !7, ->26
   43    22    >   FETCH_DIM_R                                      ~17     !5, !7
         23        ASSIGN_DIM                                               !6, !7
         24        OP_DATA                                                  ~17
   42    25      > JMP                                                      ->21
         26    >   FE_FREE                                                  $15
   45    27      > JMPZ                                                     !3, ->33
   46    28    >   INIT_STATIC_METHOD_CALL                                  'statsAccumDedupe'
         29        SEND_VAR_EX                                              !6
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0  $18     
         32        ASSIGN                                                   !6, $18
   48    33    > > RETURN                                                   !6
   49    34*     > RETURN                                                   null

End of function stepsustatsaccumulate

Function statsaccumdedupe:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 17
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
Branch analysis from position: 18
filename:       /in/g07M3
function name:  statsAccumDedupe
number of ops:  21
compiled vars:  !0 = $statsAccum, !1 = $below, !2 = $countPrev, !3 = $countAccum, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   60     2        ASSIGN                                                   !2, null
   61     3      > JMPZ                                                     !1, ->6
          4    >   QM_ASSIGN                                        ~6      !0
          5      > JMP                                                      ->11
          6    >   INIT_FCALL                                               'array_reverse'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $7      
         10        QM_ASSIGN                                        ~6      $7
         11    > > FE_RESET_R                                       $8      ~6, ->18
         12    > > FE_FETCH_R                                       ~9      $8, !3, ->18
         13    >   ASSIGN                                                   !4, ~9
   62    14        IS_IDENTICAL                                             !2, !3
         15      > JMPZ                                                     ~11, ->17
   63    16    >   UNSET_DIM                                                !0, !4
   61    17    > > JMP                                                      ->12
         18    >   FE_FREE                                                  $8
   66    19      > RETURN                                                   !0
   67    20*     > RETURN                                                   null

End of function statsaccumdedupe

Function unsortedstatsgetstats:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g07M3
function name:  unsortedStatsGetStats
number of ops:  7
compiled vars:  !0 = $rawStats
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   RECV                                             !0      
   76     1        INIT_FCALL                                               'ksort'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 1
          4        DO_ICALL                                                 
   77     5      > RETURN                                                   !0
   78     6*     > RETURN                                                   null

End of function unsortedstatsgetstats

Function statsaccumulate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
Branch analysis from position: 18
filename:       /in/g07M3
function name:  statsAccumulate
number of ops:  21
compiled vars:  !0 = $stats, !1 = $below, !2 = $total, !3 = $count, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   91     2        ASSIGN                                                   !2, 0
   92     3      > JMPZ                                                     !1, ->6
          4    >   QM_ASSIGN                                        ~6      !0
          5      > JMP                                                      ->11
          6    >   INIT_FCALL                                               'array_reverse'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $7      
         10        QM_ASSIGN                                        ~6      $7
         11    > > FE_RESET_R                                       $8      ~6, ->18
         12    > > FE_FETCH_R                                       ~9      $8, !3, ->18
         13    >   ASSIGN                                                   !4, ~9
   93    14        ASSIGN_OP                                     1          !2, !3
   94    15        ASSIGN_DIM                                               !0, !4
         16        OP_DATA                                                  !2
   92    17      > JMP                                                      ->12
         18    >   FE_FREE                                                  $8
   96    19      > RETURN                                                   !0
   97    20*     > RETURN                                                   null

End of function statsaccumulate

End of class RangesUtil.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.65 ms | 1408 KiB | 21 Q