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

Side by Side Diff: tracing/tracing/base/sorted_array_utils.html

Issue 2390373003: Change all == to === and != to !== in trace viewer. (Closed)
Patch Set: more changes from code review Created 4 years, 2 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
« no previous file with comments | « tracing/tracing/base/settings.html ('k') | tracing/tracing/base/statistics.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <link rel="import" href="/tracing/base/base.html"> 7 <link rel="import" href="/tracing/base/base.html">
8 <script> 8 <script>
9 'use strict'; 9 'use strict';
10 10
(...skipping 12 matching lines...) Expand all
23 * 23 *
24 * @param {Array} ary An array of arbitrary objects. 24 * @param {Array} ary An array of arbitrary objects.
25 * @param {function():*} mapFn Callback that produces a key value 25 * @param {function():*} mapFn Callback that produces a key value
26 * from an element in ary. 26 * from an element in ary.
27 * @param {number} loVal Value for which to search. 27 * @param {number} loVal Value for which to search.
28 * @return {Number} Offset o into ary where all ary[i] for i <= o 28 * @return {Number} Offset o into ary where all ary[i] for i <= o
29 * are < loVal, or ary.length if loVal is greater than all elements in 29 * are < loVal, or ary.length if loVal is greater than all elements in
30 * the array. 30 * the array.
31 */ 31 */
32 function findLowIndexInSortedArray(ary, mapFn, loVal) { 32 function findLowIndexInSortedArray(ary, mapFn, loVal) {
33 if (ary.length == 0) 33 if (ary.length === 0)
34 return 1; 34 return 1;
35 35
36 var low = 0; 36 var low = 0;
37 var high = ary.length - 1; 37 var high = ary.length - 1;
38 var i, comparison; 38 var i, comparison;
39 var hitPos = -1; 39 var hitPos = -1;
40 while (low <= high) { 40 while (low <= high) {
41 i = Math.floor((low + high) / 2); 41 i = Math.floor((low + high) / 2);
42 comparison = mapFn(ary[i]) - loVal; 42 comparison = mapFn(ary[i]) - loVal;
43 if (comparison < 0) { 43 if (comparison < 0) {
44 low = i + 1; continue; 44 low = i + 1; continue;
45 } else if (comparison > 0) { 45 } else if (comparison > 0) {
46 high = i - 1; continue; 46 high = i - 1; continue;
47 } else { 47 } else {
48 hitPos = i; 48 hitPos = i;
49 high = i - 1; 49 high = i - 1;
50 } 50 }
51 } 51 }
52 // return where we hit, or failing that the low pos 52 // return where we hit, or failing that the low pos
53 return hitPos != -1 ? hitPos : low; 53 return hitPos !== -1 ? hitPos : low;
54 } 54 }
55 55
56 // From devtools/front_end/platform/utilities.js upperBound 56 // From devtools/front_end/platform/utilities.js upperBound
57 function findHighIndexInSortedArray(ary, mapFn, loVal, hiVal) { 57 function findHighIndexInSortedArray(ary, mapFn, loVal, hiVal) {
58 var lo = loVal || 0; 58 var lo = loVal || 0;
59 var hi = hiVal !== undefined ? hiVal : ary.length; 59 var hi = hiVal !== undefined ? hiVal : ary.length;
60 while (lo < hi) { 60 while (lo < hi) {
61 var mid = (lo + hi) >> 1; 61 var mid = (lo + hi) >> 1;
62 if (mapFn(ary[mid]) >= 0) 62 if (mapFn(ary[mid]) >= 0)
63 lo = mid + 1; 63 lo = mid + 1;
(...skipping 20 matching lines...) Expand all
84 * interval represented by an element in the array. 84 * interval represented by an element in the array.
85 * @param {function():*} mapWidthFn Callback that produces the width for the 85 * @param {function():*} mapWidthFn Callback that produces the width for the
86 * interval represented by an element in the array. 86 * interval represented by an element in the array.
87 * @param {number} loVal The low value for the search. 87 * @param {number} loVal The low value for the search.
88 * @return {Number} An index in the array that intersects or is first-above 88 * @return {Number} An index in the array that intersects or is first-above
89 * loVal, -1 if none found and loVal is below than all the intervals, 89 * loVal, -1 if none found and loVal is below than all the intervals,
90 * ary.length if loVal is greater than all the intervals. 90 * ary.length if loVal is greater than all the intervals.
91 */ 91 */
92 function findIndexInSortedIntervals(ary, mapLoFn, mapWidthFn, loVal) { 92 function findIndexInSortedIntervals(ary, mapLoFn, mapWidthFn, loVal) {
93 var first = findLowIndexInSortedArray(ary, mapLoFn, loVal); 93 var first = findLowIndexInSortedArray(ary, mapLoFn, loVal);
94 if (first == 0) { 94 if (first === 0) {
95 if (loVal >= mapLoFn(ary[0]) && 95 if (loVal >= mapLoFn(ary[0]) &&
96 loVal < mapLoFn(ary[0]) + mapWidthFn(ary[0], 0)) { 96 loVal < mapLoFn(ary[0]) + mapWidthFn(ary[0], 0)) {
97 return 0; 97 return 0;
98 } else { 98 } else {
99 return -1; 99 return -1;
100 } 100 }
101 } else if (first < ary.length) { 101 } else if (first < ary.length) {
102 if (loVal >= mapLoFn(ary[first]) && 102 if (loVal >= mapLoFn(ary[first]) &&
103 loVal < mapLoFn(ary[first]) + mapWidthFn(ary[first], first)) { 103 loVal < mapLoFn(ary[first]) + mapWidthFn(ary[first], first)) {
104 return first; 104 return first;
105 } else if (loVal >= mapLoFn(ary[first - 1]) && 105 } else if (loVal >= mapLoFn(ary[first - 1]) &&
106 loVal < mapLoFn(ary[first - 1]) + 106 loVal < mapLoFn(ary[first - 1]) +
107 mapWidthFn(ary[first - 1], first - 1)) { 107 mapWidthFn(ary[first - 1], first - 1)) {
108 return first - 1; 108 return first - 1;
109 } else { 109 } else {
110 return ary.length; 110 return ary.length;
111 } 111 }
112 } else if (first == ary.length) { 112 } else if (first === ary.length) {
113 if (loVal >= mapLoFn(ary[first - 1]) && 113 if (loVal >= mapLoFn(ary[first - 1]) &&
114 loVal < mapLoFn(ary[first - 1]) + 114 loVal < mapLoFn(ary[first - 1]) +
115 mapWidthFn(ary[first - 1], first - 1)) { 115 mapWidthFn(ary[first - 1], first - 1)) {
116 return first - 1; 116 return first - 1;
117 } else { 117 } else {
118 return ary.length; 118 return ary.length;
119 } 119 }
120 } else { 120 } else {
121 return ary.length; 121 return ary.length;
122 } 122 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } else if (i < ary.length) { 158 } else if (i < ary.length) {
159 if (val >= mapLoFn(ary[i - 1], i - 1) && 159 if (val >= mapLoFn(ary[i - 1], i - 1) &&
160 val <= mapHiFn(ary[i - 1], i - 1)) { 160 val <= mapHiFn(ary[i - 1], i - 1)) {
161 return i - 1; 161 return i - 1;
162 } else if (val >= mapLoFn(ary[i], i) && 162 } else if (val >= mapLoFn(ary[i], i) &&
163 val <= mapHiFn(ary[i], i)) { 163 val <= mapHiFn(ary[i], i)) {
164 return i; 164 return i;
165 } else { 165 } else {
166 return ary.length; 166 return ary.length;
167 } 167 }
168 } else if (i == ary.length) { 168 } else if (i === ary.length) {
169 if (val >= mapLoFn(ary[i - 1], i - 1) && 169 if (val >= mapLoFn(ary[i - 1], i - 1) &&
170 val <= mapHiFn(ary[i - 1], i - 1)) { 170 val <= mapHiFn(ary[i - 1], i - 1)) {
171 return i - 1; 171 return i - 1;
172 } else { 172 } else {
173 return ary.length; 173 return ary.length;
174 } 174 }
175 } else { 175 } else {
176 return ary.length; 176 return ary.length;
177 } 177 }
178 } 178 }
(...skipping 12 matching lines...) Expand all
191 * @param {function():*} mapLoFn Callback that produces the low value for the 191 * @param {function():*} mapLoFn Callback that produces the low value for the
192 * interval represented by an element in the array. 192 * interval represented by an element in the array.
193 * @param {function():*} mapWidthFn Callback that produces the width for the 193 * @param {function():*} mapWidthFn Callback that produces the width for the
194 * interval represented by an element in the array. 194 * interval represented by an element in the array.
195 * @param {number} loVal The low value for the search, inclusive. 195 * @param {number} loVal The low value for the search, inclusive.
196 * @param {number} hiVal The high value for the search, non inclusive. 196 * @param {number} hiVal The high value for the search, non inclusive.
197 * @param {function():*} cb The function to run for intersecting intervals. 197 * @param {function():*} cb The function to run for intersecting intervals.
198 */ 198 */
199 function iterateOverIntersectingIntervals(ary, mapLoFn, mapWidthFn, loVal, 199 function iterateOverIntersectingIntervals(ary, mapLoFn, mapWidthFn, loVal,
200 hiVal, cb) { 200 hiVal, cb) {
201 if (ary.length == 0) 201 if (ary.length === 0)
202 return; 202 return;
203 203
204 if (loVal > hiVal) return; 204 if (loVal > hiVal) return;
205 205
206 var i = findLowIndexInSortedArray(ary, mapLoFn, loVal); 206 var i = findLowIndexInSortedArray(ary, mapLoFn, loVal);
207 if (i == -1) { 207 if (i === -1) {
208 return; 208 return;
209 } 209 }
210 if (i > 0) { 210 if (i > 0) {
211 var hi = mapLoFn(ary[i - 1]) + mapWidthFn(ary[i - 1], i - 1); 211 var hi = mapLoFn(ary[i - 1]) + mapWidthFn(ary[i - 1], i - 1);
212 if (hi >= loVal) { 212 if (hi >= loVal) {
213 cb(ary[i - 1], i - 1); 213 cb(ary[i - 1], i - 1);
214 } 214 }
215 } 215 }
216 if (i == ary.length) { 216 if (i === ary.length) {
217 return; 217 return;
218 } 218 }
219 219
220 for (var n = ary.length; i < n; i++) { 220 for (var n = ary.length; i < n; i++) {
221 var lo = mapLoFn(ary[i]); 221 var lo = mapLoFn(ary[i]);
222 if (lo >= hiVal) 222 if (lo >= hiVal)
223 break; 223 break;
224 cb(ary[i], i); 224 cb(ary[i], i);
225 } 225 }
226 } 226 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 findHighIndexInSortedArray: findHighIndexInSortedArray, 325 findHighIndexInSortedArray: findHighIndexInSortedArray,
326 findIndexInSortedIntervals: findIndexInSortedIntervals, 326 findIndexInSortedIntervals: findIndexInSortedIntervals,
327 findIndexInSortedClosedIntervals: findIndexInSortedClosedIntervals, 327 findIndexInSortedClosedIntervals: findIndexInSortedClosedIntervals,
328 iterateOverIntersectingIntervals: iterateOverIntersectingIntervals, 328 iterateOverIntersectingIntervals: iterateOverIntersectingIntervals,
329 getIntersectingIntervals: getIntersectingIntervals, 329 getIntersectingIntervals: getIntersectingIntervals,
330 findClosestElementInSortedArray: findClosestElementInSortedArray, 330 findClosestElementInSortedArray: findClosestElementInSortedArray,
331 findClosestIntervalInSortedIntervals: findClosestIntervalInSortedIntervals 331 findClosestIntervalInSortedIntervals: findClosestIntervalInSortedIntervals
332 }; 332 };
333 }); 333 });
334 </script> 334 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/base/settings.html ('k') | tracing/tracing/base/statistics.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698