OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 import os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
8 BASE_PATH = os.path.dirname(os.path.abspath(__file__)) | 8 _BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
9 BINTREES_PATH = os.path.join( | 9 _BINTREES_PATH = os.path.join( |
10 BASE_PATH, os.pardir, os.pardir, 'third_party', 'bintrees') | 10 _BASE_PATH, os.pardir, os.pardir, 'third_party', 'bintrees') |
11 sys.path.insert(0, BINTREES_PATH) | 11 sys.path.insert(0, _BINTREES_PATH) |
12 | 12 |
13 from bintrees import FastRBTree # pylint: disable=F0401 | 13 from bintrees import FastRBTree # pylint: disable=F0401 |
14 | 14 |
15 | 15 |
16 class ExclusiveRangeDict(object): | 16 class ExclusiveRangeDict(object): |
17 """A class like dict whose key is a range [begin, end) of integers. | 17 """A class like dict whose key is a range [begin, end) of integers. |
18 | 18 |
19 It has an attribute for each range of integers, for example: | 19 It has an attribute for each range of integers, for example: |
20 [10, 20) => Attribute(0), | 20 [10, 20) => Attribute(0), |
21 [20, 40) => Attribute(1), | 21 [20, 40) => Attribute(1), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 prev_end = range_end | 135 prev_end = range_end |
136 | 136 |
137 for missing_begin, missing_end in missing_ranges: | 137 for missing_begin, missing_end in missing_ranges: |
138 self._tree[missing_begin] = (missing_end, self._attr()) | 138 self._tree[missing_begin] = (missing_end, self._attr()) |
139 | 139 |
140 for range_begin, range_value in self._tree.itemslice(begin, end): | 140 for range_begin, range_value in self._tree.itemslice(begin, end): |
141 yield range_begin, range_value[0], range_value[1] | 141 yield range_begin, range_value[0], range_value[1] |
142 | 142 |
143 def __str__(self): | 143 def __str__(self): |
144 return str(self._tree) | 144 return str(self._tree) |
OLD | NEW |