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

Side by Side Diff: pkg/yaml/lib/src/utils.dart

Issue 302313007: Attach source range information to parsed YAML nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix tests Created 6 years, 6 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
« no previous file with comments | « pkg/yaml/lib/src/parser.dart ('k') | pkg/yaml/lib/src/visitor.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 yaml.utils; 5 library yaml.utils;
6 6
7 import 'package:collection/collection.dart'; 7 /// A pair of values.
8 class Pair<E, F> {
9 final E first;
10 final F last;
8 11
9 /// Returns a hash code for [obj] such that structurally equivalent objects 12 Pair(this.first, this.last);
10 /// will have the same hash code.
11 ///
12 /// This supports deep equality for maps and lists, including those with
13 /// self-referential structures.
14 int hashCodeFor(obj) {
15 var parents = [];
16 13
17 _hashCodeFor(value) { 14 String toString() => '($first, $last)';
18 if (parents.any((parent) => identical(parent, value))) return -1;
19
20 parents.add(value);
21 try {
22 if (value is Map) {
23 var equality = const UnorderedIterableEquality();
24 return equality.hash(value.keys.map(_hashCodeFor)) ^
25 equality.hash(value.values.map(_hashCodeFor));
26 } else if (value is Iterable) {
27 return const IterableEquality().hash(value.map(hashCodeFor));
28 }
29 return value.hashCode;
30 } finally {
31 parents.removeLast();
32 }
33 }
34
35 return _hashCodeFor(obj);
36 } 15 }
OLDNEW
« no previous file with comments | « pkg/yaml/lib/src/parser.dart ('k') | pkg/yaml/lib/src/visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698