Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: tracing/tracing/base/math/range_utils.html

Issue 2771723003: [tracing] Move math utilities from base into their own subdirectory (attempt 2) (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/tracing/base/base.html"> 8 <link rel="import" href="/tracing/base/base.html">
9 <link rel="import" href="/tracing/base/iteration_helpers.html"> 9 <link rel="import" href="/tracing/base/iteration_helpers.html">
10 10
11 <script> 11 <script>
12 'use strict'; 12 'use strict';
13 13
14 /** 14 /**
15 * @fileoverview Provides event merging functionality for grouping/analysis. 15 * @fileoverview Provides event merging functionality for grouping/analysis.
16 */ 16 */
17 tr.exportTo('tr.b', function() { 17 tr.exportTo('tr.b.math', function() {
18 function convertEventsToRanges(events) { 18 function convertEventsToRanges(events) {
19 return events.map(function(event) { 19 return events.map(function(event) {
20 return tr.b.Range.fromExplicitRange(event.start, event.end); 20 return tr.b.math.Range.fromExplicitRange(event.start, event.end);
21 }); 21 });
22 } 22 }
23 23
24 function mergeRanges(inRanges, mergeThreshold, mergeFunction) { 24 function mergeRanges(inRanges, mergeThreshold, mergeFunction) {
25 var remainingEvents = inRanges.slice(); 25 var remainingEvents = inRanges.slice();
26 remainingEvents.sort(function(x, y) { 26 remainingEvents.sort(function(x, y) {
27 return x.min - y.min; 27 return x.min - y.min;
28 }); 28 });
29 29
30 if (remainingEvents.length <= 1) { 30 if (remainingEvents.length <= 1) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 emptyRanges.push(opt_totalRange); 90 emptyRanges.push(opt_totalRange);
91 return emptyRanges; 91 return emptyRanges;
92 } 92 }
93 93
94 inRanges = inRanges.slice(); 94 inRanges = inRanges.slice();
95 inRanges.sort(function(x, y) { 95 inRanges.sort(function(x, y) {
96 return x.min - y.min; 96 return x.min - y.min;
97 }); 97 });
98 if (opt_totalRange && 98 if (opt_totalRange &&
99 (opt_totalRange.min < inRanges[0].min)) { 99 (opt_totalRange.min < inRanges[0].min)) {
100 emptyRanges.push(tr.b.Range.fromExplicitRange( 100 emptyRanges.push(tr.b.math.Range.fromExplicitRange(
101 opt_totalRange.min, inRanges[0].min)); 101 opt_totalRange.min, inRanges[0].min));
102 } 102 }
103 103
104 inRanges.forEach(function(range, index) { 104 inRanges.forEach(function(range, index) {
105 for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) { 105 for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) {
106 if (index === otherIndex) 106 if (index === otherIndex)
107 continue; 107 continue;
108 var other = inRanges[otherIndex]; 108 var other = inRanges[otherIndex];
109 109
110 if (other.min > range.max) { 110 if (other.min > range.max) {
111 // |inRanges| is sorted, so |other| is the first range after |range|, 111 // |inRanges| is sorted, so |other| is the first range after |range|,
112 // and there is an empty range between them. 112 // and there is an empty range between them.
113 emptyRanges.push(tr.b.Range.fromExplicitRange( 113 emptyRanges.push(tr.b.math.Range.fromExplicitRange(
114 range.max, other.min)); 114 range.max, other.min));
115 return; 115 return;
116 } 116 }
117 // Otherwise, |other| starts before |range| ends, so |other| might 117 // Otherwise, |other| starts before |range| ends, so |other| might
118 // possibly contain the end of |range|. 118 // possibly contain the end of |range|.
119 119
120 if (other.max > range.max) { 120 if (other.max > range.max) {
121 // |other| does contain the end of |range|, so no empty range starts 121 // |other| does contain the end of |range|, so no empty range starts
122 // at the end of this |range|. 122 // at the end of this |range|.
123 return; 123 return;
124 } 124 }
125 } 125 }
126 if (opt_totalRange && (range.max < opt_totalRange.max)) { 126 if (opt_totalRange && (range.max < opt_totalRange.max)) {
127 emptyRanges.push(tr.b.Range.fromExplicitRange( 127 emptyRanges.push(tr.b.math.Range.fromExplicitRange(
128 range.max, opt_totalRange.max)); 128 range.max, opt_totalRange.max));
129 } 129 }
130 }); 130 });
131 return emptyRanges; 131 return emptyRanges;
132 } 132 }
133 133
134 return { 134 return {
135 convertEventsToRanges, 135 convertEventsToRanges,
136 findEmptyRangesBetweenRanges, 136 findEmptyRangesBetweenRanges,
137 mergeRanges, 137 mergeRanges,
138 }; 138 };
139 }); 139 });
140 </script> 140 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/base/math/range_test.html ('k') | tracing/tracing/base/math/range_utils_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698