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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/yaml/lib/src/parser.dart ('k') | pkg/yaml/lib/src/visitor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/yaml/lib/src/utils.dart
diff --git a/pkg/yaml/lib/src/utils.dart b/pkg/yaml/lib/src/utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a87555d625871d0ed8389563279172bbabcb5814
--- /dev/null
+++ b/pkg/yaml/lib/src/utils.dart
@@ -0,0 +1,39 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library utils;
+
+/// Returns the hash code for [obj]. This includes null, true, false, maps, and
+/// lists. Also handles self-referential structures.
+int hashCodeFor(obj, [List parents]) {
+ if (parents == null) {
+ parents = [];
+ } else if (parents.any((p) => identical(p, obj))) {
+ return -1;
+ }
+
+ parents.add(obj);
+ try {
+ if (obj == null) return 0;
+ if (obj == true) return 1;
+ if (obj == false) return 2;
+ if (obj is Map) {
+ return hashCodeFor(obj.keys, parents) ^
+ hashCodeFor(obj.values, parents);
+ }
+ if (obj is Iterable) {
+ // This is probably a really bad hash function, but presumably we'll get
+ // this in the standard library before it actually matters.
+ int hash = 0;
+ for (var e in obj) {
+ hash ^= hashCodeFor(e, parents);
+ }
+ return hash;
+ }
+ return obj.hashCode;
+ } finally {
+ parents.removeLast();
+ }
+}
+
« 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