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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/lib/math/jenkins_smi_hash.dart

Issue 2698353003: unfork DDC's copy of most SDK libraries (Closed)
Patch Set: revert core_patch Created 3 years, 9 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
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 part of dart.math;
5
6 /**
7 * This is the [Jenkins hash function][1] but using masking to keep
8 * values in SMI range.
9 *
10 * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function
11 *
12 * Use:
13 * Hash each value with the hash of the previous value, then get the final
14 * hash by calling finish.
15 *
16 * var hash = 0;
17 * for (var value in values) {
18 * hash = JenkinsSmiHash.combine(hash, value.hashCode);
19 * }
20 * hash = JenkinsSmiHash.finish(hash);
21 */
22 class _JenkinsSmiHash {
23 // TODO(11617): This class should be optimized and standardized elsewhere.
24
25 static int combine(int hash, int value) {
26 hash = 0x1fffffff & (hash + value);
27 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
28 return hash ^ (hash >> 6);
29 }
30
31 static int finish(int hash) {
32 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
33 hash = hash ^ (hash >> 11);
34 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
35 }
36
37 static int hash2(a, b) => finish(combine(combine(0, a), b));
38
39 static int hash4(a, b, c, d) =>
40 finish(combine(combine(combine(combine(0, a), b), c), d));
41 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/lib/isolate/isolate.dart ('k') | pkg/dev_compiler/tool/input_sdk/lib/math/math.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698