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

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

Issue 375693002: Move index/search to services. (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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library engine.src.index.store_memory_node_manager;
6
7 import 'dart:async';
8 import 'dart:collection';
9
10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/index/store/codec.dart';
12 import 'package:analyzer/src/index/store/split_store.dart';
13
14
15 class MemoryNodeManager implements NodeManager {
16 StringCodec _stringCodec = new StringCodec();
17 ContextCodec _contextCodec = new ContextCodec();
18 ElementCodec _elementCodec;
19 RelationshipCodec _relationshipCodec;
20
21 int _locationCount = 0;
22 final Map<String, int> _nodeLocationCounts = new HashMap<String, int>();
23 final Map<String, IndexNode> _nodes = new HashMap<String, IndexNode>();
24
25 MemoryNodeManager() {
26 _elementCodec = new ElementCodec(_stringCodec);
27 _relationshipCodec = new RelationshipCodec(_stringCodec);
28 }
29
30 @override
31 ContextCodec get contextCodec {
32 return _contextCodec;
33 }
34
35 @override
36 ElementCodec get elementCodec {
37 return _elementCodec;
38 }
39
40 @override
41 int get locationCount {
42 return _locationCount;
43 }
44
45 @override
46 StringCodec get stringCodec {
47 return _stringCodec;
48 }
49
50 @override
51 void clear() {
52 _nodes.clear();
53 }
54
55 int getLocationCount(String name) {
56 int locationCount = _nodeLocationCounts[name];
57 return locationCount != null ? locationCount : 0;
58 }
59
60 @override
61 Future<IndexNode> getNode(String name) {
62 return new Future.value(_nodes[name]);
63 }
64
65 bool isEmpty() {
66 for (IndexNode node in _nodes.values) {
67 Map<RelationKeyData, List<LocationData>> relations = node.relations;
68 if (!relations.isEmpty) {
69 return false;
70 }
71 }
72 return true;
73 }
74
75 @override
76 IndexNode newNode(AnalysisContext context) {
77 return new IndexNode(context, elementCodec, _relationshipCodec);
78 }
79
80 @override
81 void putNode(String name, IndexNode node) {
82 // update location count
83 {
84 _locationCount -= getLocationCount(name);
85 int nodeLocationCount = node.locationCount;
86 _nodeLocationCounts[name] = nodeLocationCount;
87 _locationCount += nodeLocationCount;
88 }
89 // remember the node
90 _nodes[name] = node;
91 }
92
93 @override
94 void removeNode(String name) {
95 _nodes.remove(name);
96 }
97 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/index/store/collection.dart ('k') | pkg/analyzer/lib/src/index/store/separate_file_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698