| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library services.src.index.store.codec; | 5 library services.src.index.store.codec; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analysis_server/src/services/index/store/collection.dart'; | 10 import 'package:analysis_server/src/services/index/store/collection.dart'; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * Returns an integer that corresponds to an approximated location of [element
]. | 140 * Returns an integer that corresponds to an approximated location of [element
]. |
| 141 */ | 141 */ |
| 142 int encodeHash(Element element) { | 142 int encodeHash(Element element) { |
| 143 List<int> path = _getLocationPathLimited(element); | 143 List<int> path = _getLocationPathLimited(element); |
| 144 int index = _encodePath(path); | 144 int index = _encodePath(path); |
| 145 return index; | 145 return index; |
| 146 } | 146 } |
| 147 | 147 |
| 148 /** |
| 149 * Returns a list with the location components of the element with the |
| 150 * given encoded ID. |
| 151 */ |
| 152 List<String> inspect_decodePath(int id) { |
| 153 List<int> path = _indexToPath[id]; |
| 154 return _getLocationComponents(path); |
| 155 } |
| 156 |
| 157 /** |
| 158 * Returns a map of element IDs to their locations for elements with |
| 159 * the [requiredName]. |
| 160 */ |
| 161 Map<int, List<String>> inspect_getElements(String requiredName) { |
| 162 Map<int, List<String>> result = <int, List<String>>{}; |
| 163 for (int i = 0; i < _indexToPath.length; i++) { |
| 164 List<int> path = _indexToPath[i]; |
| 165 int nameIndex = path[path.length - 1]; |
| 166 if (nameIndex >= 0) { |
| 167 String name = _stringCodec.decode(nameIndex); |
| 168 if (name == requiredName) { |
| 169 result[i] = path.map(_stringCodec.decode).toList(); |
| 170 } |
| 171 } |
| 172 } |
| 173 return result; |
| 174 } |
| 175 |
| 148 int _encodePath(List<int> path) { | 176 int _encodePath(List<int> path) { |
| 149 int index = _pathToIndex[path]; | 177 int index = _pathToIndex[path]; |
| 150 if (index == null) { | 178 if (index == null) { |
| 151 index = _indexToPath.length; | 179 index = _indexToPath.length; |
| 152 _pathToIndex[path] = index; | 180 _pathToIndex[path] = index; |
| 153 _indexToPath.add(path); | 181 _indexToPath.add(path); |
| 154 } | 182 } |
| 155 return index; | 183 return index; |
| 156 } | 184 } |
| 157 | 185 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 int encode(String name) { | 319 int encode(String name) { |
| 292 int index = nameToIndex[name]; | 320 int index = nameToIndex[name]; |
| 293 if (index == null) { | 321 if (index == null) { |
| 294 index = _indexToName.length; | 322 index = _indexToName.length; |
| 295 nameToIndex[name] = index; | 323 nameToIndex[name] = index; |
| 296 _indexToName.add(name); | 324 _indexToName.add(name); |
| 297 } | 325 } |
| 298 return index; | 326 return index; |
| 299 } | 327 } |
| 300 } | 328 } |
| OLD | NEW |