| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {number} begin | 7 * @param {number} begin |
| 8 * @param {number} end | 8 * @param {number} end |
| 9 * @param {*} data | 9 * @param {*} data |
| 10 */ | 10 */ |
| 11 WebInspector.Segment = function(begin, end, data) | 11 WebInspector.Segment = function(begin, end, data) |
| 12 { | 12 { |
| 13 if (begin > end) | 13 if (begin > end) |
| 14 console.assert(false, "Invalid segment"); | 14 console.assert(false, "Invalid segment"); |
| 15 this.begin = begin; | 15 this.begin = begin; |
| 16 this.end = end; | 16 this.end = end; |
| 17 this.data = data; | 17 this.data = data; |
| 18 } | 18 }; |
| 19 | 19 |
| 20 WebInspector.Segment.prototype = { | 20 WebInspector.Segment.prototype = { |
| 21 /** | 21 /** |
| 22 * @param {!WebInspector.Segment} that | 22 * @param {!WebInspector.Segment} that |
| 23 * @return {boolean} | 23 * @return {boolean} |
| 24 */ | 24 */ |
| 25 intersects: function(that) | 25 intersects: function(that) |
| 26 { | 26 { |
| 27 return this.begin < that.end && that.begin < this.end; | 27 return this.begin < that.end && that.begin < this.end; |
| 28 } | 28 } |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @param {(function(!WebInspector.Segment, !WebInspector.Segment): ?WebInspecto
r.Segment)=} mergeCallback | 33 * @param {(function(!WebInspector.Segment, !WebInspector.Segment): ?WebInspecto
r.Segment)=} mergeCallback |
| 34 */ | 34 */ |
| 35 WebInspector.SegmentedRange = function(mergeCallback) | 35 WebInspector.SegmentedRange = function(mergeCallback) |
| 36 { | 36 { |
| 37 /** @type {!Array<!WebInspector.Segment>} */ | 37 /** @type {!Array<!WebInspector.Segment>} */ |
| 38 this._segments = []; | 38 this._segments = []; |
| 39 this._mergeCallback = mergeCallback; | 39 this._mergeCallback = mergeCallback; |
| 40 } | 40 }; |
| 41 | 41 |
| 42 WebInspector.SegmentedRange.prototype = { | 42 WebInspector.SegmentedRange.prototype = { |
| 43 /** | 43 /** |
| 44 * @param {!WebInspector.Segment} newSegment | 44 * @param {!WebInspector.Segment} newSegment |
| 45 */ | 45 */ |
| 46 append: function(newSegment) | 46 append: function(newSegment) |
| 47 { | 47 { |
| 48 // 1. Find the proper insertion point for new segment | 48 // 1. Find the proper insertion point for new segment |
| 49 var startIndex = this._segments.lowerBound(newSegment, (a, b) => a.begin
- b.begin); | 49 var startIndex = this._segments.lowerBound(newSegment, (a, b) => a.begin
- b.begin); |
| 50 var endIndex = startIndex; | 50 var endIndex = startIndex; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 */ | 102 */ |
| 103 _tryMerge: function(first, second) | 103 _tryMerge: function(first, second) |
| 104 { | 104 { |
| 105 var merged = this._mergeCallback && this._mergeCallback(first, second); | 105 var merged = this._mergeCallback && this._mergeCallback(first, second); |
| 106 if (!merged) | 106 if (!merged) |
| 107 return null; | 107 return null; |
| 108 merged.begin = first.begin; | 108 merged.begin = first.begin; |
| 109 merged.end = Math.max(first.end, second.end); | 109 merged.end = Math.max(first.end, second.end); |
| 110 return merged; | 110 return merged; |
| 111 } | 111 } |
| 112 } | 112 }; |
| OLD | NEW |