@ 2016-01-15T00:42:43Z <?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));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught ArgumentCountError: Too few arguments to function RangesUtil::stepsUstatsAccumulate(), 2 passed in /in/g07M3 on line 112 and at least 3 expected in /in/g07M3:37
Stack trace:
#0 /in/g07M3(112): RangesUtil::stepsUstatsAccumulate(Array, Array)
#1 {main}
thrown in /in/g07M3 on line 37
Process exited with code 255 . Output for 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 Warning: Missing argument 3 for RangesUtil::stepsUstatsAccumulate(), called in /in/g07M3 on line 112 and defined in /in/g07M3 on line 37
Notice: Undefined variable: below in /in/g07M3 on line 40
array (
0 => 11112,
2 => 11110,
5 => 11100,
10 => 10000,
20 => 0,
) preferences:dark mode live preview
178.84 ms | 402 KiB | 183 Q