1 <!DOCTYPE html> 2 <!-- 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 <link rel="import" href="/tracing/base/iteration_helpers.html"> 8 9 <script> 10 'use strict'; 11 12 tr.exportTo('pi.m', function() { 13 function StreamingReducer(reducingTargetConstructor) { 14 this.reducingTargetConstructor = reducingTargetConstructor; 15 this.reducingTargetsByKey_ = {}; 16 } 17 18 StreamingReducer.prototype = { 19 push: function(key, value) { 20 var reducingTarget = this.reducingTargetsByKey_[key]; 21 if (reducingTarget === undefined) { 22 reducingTarget = new this.reducingTargetConstructor(key, value); 23 this.reducingTargetsByKey_[key] = reducingTarget; 24 } 25 reducingTarget.push(key, value); 26 }, 27 28 finalizeAndIterResults: function(outputFunc, opt_this) { 29 for (var key in this.reducingTargetsByKey_) { 30 var reducingTarget = this.reducingTargetsByKey_[key]; 31 var resultValue = reducingTarget.finalizeAndGetResult(key); 32 outputFunc.call(opt_this, key, resultValue); 33 } 34 }, 35 36 finalizeAndGetResults: function() { 37 var res = []; 38 this.finalizeAndIterResults(function(key, value) { 39 res.push({key: key, value: value}); 40 }); 41 return res; 42 } 43 }; 44 45 return { 46 StreamingReducer: StreamingReducer 47 }; 48 }); 49 </script> 50 51