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

Side by Side Diff: pkg/analyzer/lib/src/index/store/codec.dart

Issue 365193004: Move Index and IndexStore implementations into Engine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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 index.store.codec; 5 library engine.src.index.store.codec;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/src/index/store/collection.dart'; 9 import 'package:analyzer/index/index.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/engine.dart'; 11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/index.dart'; 12 import 'package:analyzer/src/index/store/collection.dart';
13 13
14 14
15 /** 15 /**
16 * A helper that encodes/decodes [AnalysisContext]s from/to integers. 16 * A helper that encodes/decodes [AnalysisContext]s from/to integers.
17 */ 17 */
18 class ContextCodec { 18 class ContextCodec {
19 /** 19 /**
20 * A table mapping contexts to their unique indices. 20 * A table mapping contexts to their unique indices.
21 */ 21 */
22 Map<AnalysisContext, int> _contextToIndex = new HashMap<AnalysisContext, int>( 22 Map<AnalysisContext, int> _contextToIndex = new HashMap<AnalysisContext, int>(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 _indexToContext.remove(id); 60 _indexToContext.remove(id);
61 } 61 }
62 } 62 }
63 } 63 }
64 64
65 65
66 /** 66 /**
67 * A helper that encodes/decodes [Element]s to/from integers. 67 * A helper that encodes/decodes [Element]s to/from integers.
68 */ 68 */
69 class ElementCodec { 69 class ElementCodec {
70 /** 70 final StringCodec _stringCodec;
71 * A list that works as a mapping of integers to element encodings (in form of integer arrays).
72 */
73 List<List<int>> _indexToPath = [];
74 71
75 /** 72 /**
76 * A table mapping element locations (in form of integer arrays) into a single integer. 73 * A table mapping element encodings to a single integer.
77 */ 74 */
78 IntArrayToIntMap _pathToIndex = new IntArrayToIntMap(); 75 final IntArrayToIntMap _pathToIndex = new IntArrayToIntMap();
79 76
80 final StringCodec _stringCodec; 77 /**
78 * A list that works as a mapping of integers to element encodings.
79 */
80 final List<List<int>> _indexToPath = <List<int>>[];
81 81
82 ElementCodec(this._stringCodec); 82 ElementCodec(this._stringCodec);
83 83
84 /** 84 /**
85 * Returns an [Element] that corresponds to the given location. 85 * Returns an [Element] that corresponds to the given location.
86 * 86 *
87 * @param context the [AnalysisContext] to find [Element] in 87 * @param context the [AnalysisContext] to find [Element] in
88 * @param index an integer corresponding to the [Element] 88 * @param index an integer corresponding to the [Element]
89 * @return the [Element] or `null` 89 * @return the [Element] or `null`
90 */ 90 */
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 183
184 184
185 /** 185 /**
186 * A helper that encodes/decodes [String]s from/to integers. 186 * A helper that encodes/decodes [String]s from/to integers.
187 */ 187 */
188 class StringCodec { 188 class StringCodec {
189 /** 189 /**
190 * A table mapping names to their unique indices. 190 * A table mapping names to their unique indices.
191 */ 191 */
192 final Map<String, int> nameToIndex = {}; 192 final Map<String, int> nameToIndex = new HashMap<String, int>();
193 193
194 /** 194 /**
195 * A table mapping indices to the corresponding strings. 195 * A table mapping indices to the corresponding strings.
196 */ 196 */
197 List<String> _indexToName = []; 197 final List<String> _indexToName = <String>[];
198 198
199 /** 199 /**
200 * Returns the [String] that corresponds to the given index. 200 * Returns the [String] that corresponds to the given index.
201 */ 201 */
202 String decode(int index) => _indexToName[index]; 202 String decode(int index) => _indexToName[index];
203 203
204 /** 204 /**
205 * Returns an unique index for the given [String]. 205 * Returns an unique index for the given [String].
206 */ 206 */
207 int encode(String name) { 207 int encode(String name) {
208 int index = nameToIndex[name]; 208 int index = nameToIndex[name];
209 if (index == null) { 209 if (index == null) {
210 index = _indexToName.length; 210 index = _indexToName.length;
211 nameToIndex[name] = index; 211 nameToIndex[name] = index;
212 _indexToName.add(name); 212 _indexToName.add(name);
213 } 213 }
214 return index; 214 return index;
215 } 215 }
216 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698