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

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

Issue 14103026: Restructure the yaml package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library utils;
6
7 /// Returns the hash code for [obj]. This includes null, true, false, maps, and
8 /// lists. Also handles self-referential structures.
9 int hashCodeFor(obj, [List parents]) {
10 if (parents == null) {
11 parents = [];
12 } else if (parents.any((p) => identical(p, obj))) {
13 return -1;
14 }
15
16 parents.add(obj);
17 try {
18 if (obj == null) return 0;
19 if (obj == true) return 1;
20 if (obj == false) return 2;
21 if (obj is Map) {
22 return hashCodeFor(obj.keys, parents) ^
23 hashCodeFor(obj.values, parents);
24 }
25 if (obj is Iterable) {
26 // This is probably a really bad hash function, but presumably we'll get
27 // this in the standard library before it actually matters.
28 int hash = 0;
29 for (var e in obj) {
30 hash ^= hashCodeFor(e, parents);
31 }
32 return hash;
33 }
34 return obj.hashCode;
35 } finally {
36 parents.removeLast();
37 }
38 }
39
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