|
| 1 | +// Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +part of dart_ui; |
| 6 | + |
| 7 | +class _HashEnd { const _HashEnd(); } |
| 8 | +const _HashEnd _hashEnd = const _HashEnd(); |
| 9 | + |
| 10 | +/// Combine up to twenty values' hashCodes into one value. |
| 11 | +/// |
| 12 | +/// If you only need to handle one value's hashCode, then just refer to its |
| 13 | +/// [hashCode] getter directly. |
| 14 | +/// |
| 15 | +/// If you need to combine an arbitrary number of values from a List or other |
| 16 | +/// Iterable, use [hashList]. The output of hashList can be used as one of the |
| 17 | +/// arguments to this function. |
| 18 | +/// |
| 19 | +/// For example: |
| 20 | +/// |
| 21 | +/// int hashCode => hashValues(foo, bar, hashList(quux), baz); |
| 22 | +int hashValues( |
| 23 | + Object arg01, Object arg02, [ Object arg03 = _hashEnd, |
| 24 | + Object arg04 = _hashEnd, Object arg05 = _hashEnd, Object arg06 = _hashEnd, |
| 25 | + Object arg07 = _hashEnd, Object arg08 = _hashEnd, Object arg09 = _hashEnd, |
| 26 | + Object arg10 = _hashEnd, Object arg11 = _hashEnd, Object arg12 = _hashEnd, |
| 27 | + Object arg13 = _hashEnd, Object arg14 = _hashEnd, Object arg15 = _hashEnd, |
| 28 | + Object arg16 = _hashEnd, Object arg17 = _hashEnd, Object arg18 = _hashEnd, |
| 29 | + Object arg19 = _hashEnd, Object arg20 = _hashEnd ]) { |
| 30 | + int result = 373; |
| 31 | + assert(arg01 is! Iterable); |
| 32 | + result = 37 * result + arg01.hashCode; |
| 33 | + assert(arg02 is! Iterable); |
| 34 | + result = 37 * result + arg02.hashCode; |
| 35 | + if (arg03 != _hashEnd) { |
| 36 | + assert(arg03 is! Iterable); |
| 37 | + result = 37 * result + arg03.hashCode; |
| 38 | + if (arg04 != _hashEnd) { |
| 39 | + assert(arg04 is! Iterable); |
| 40 | + result = 37 * result + arg04.hashCode; |
| 41 | + if (arg05 != _hashEnd) { |
| 42 | + assert(arg05 is! Iterable); |
| 43 | + result = 37 * result + arg05.hashCode; |
| 44 | + if (arg06 != _hashEnd) { |
| 45 | + assert(arg06 is! Iterable); |
| 46 | + result = 37 * result + arg06.hashCode; |
| 47 | + if (arg07 != _hashEnd) { |
| 48 | + assert(arg07 is! Iterable); |
| 49 | + result = 37 * result + arg07.hashCode; |
| 50 | + if (arg08 != _hashEnd) { |
| 51 | + assert(arg08 is! Iterable); |
| 52 | + result = 37 * result + arg08.hashCode; |
| 53 | + if (arg09 != _hashEnd) { |
| 54 | + assert(arg09 is! Iterable); |
| 55 | + result = 37 * result + arg09.hashCode; |
| 56 | + if (arg10 != _hashEnd) { |
| 57 | + assert(arg10 is! Iterable); |
| 58 | + result = 37 * result + arg10.hashCode; |
| 59 | + if (arg11 != _hashEnd) { |
| 60 | + assert(arg11 is! Iterable); |
| 61 | + result = 37 * result + arg11.hashCode; |
| 62 | + if (arg12 != _hashEnd) { |
| 63 | + assert(arg12 is! Iterable); |
| 64 | + result = 37 * result + arg12.hashCode; |
| 65 | + if (arg13 != _hashEnd) { |
| 66 | + assert(arg13 is! Iterable); |
| 67 | + result = 37 * result + arg13.hashCode; |
| 68 | + if (arg14 != _hashEnd) { |
| 69 | + assert(arg14 is! Iterable); |
| 70 | + result = 37 * result + arg14.hashCode; |
| 71 | + if (arg15 != _hashEnd) { |
| 72 | + assert(arg15 is! Iterable); |
| 73 | + result = 37 * result + arg15.hashCode; |
| 74 | + if (arg16 != _hashEnd) { |
| 75 | + assert(arg16 is! Iterable); |
| 76 | + result = 37 * result + arg16.hashCode; |
| 77 | + if (arg17 != _hashEnd) { |
| 78 | + assert(arg17 is! Iterable); |
| 79 | + result = 37 * result + arg17.hashCode; |
| 80 | + if (arg18 != _hashEnd) { |
| 81 | + assert(arg18 is! Iterable); |
| 82 | + result = 37 * result + arg18.hashCode; |
| 83 | + if (arg19 != _hashEnd) { |
| 84 | + assert(arg19 is! Iterable); |
| 85 | + result = 37 * result + arg19.hashCode; |
| 86 | + if (arg20 != _hashEnd) { |
| 87 | + assert(arg20 is! Iterable); |
| 88 | + result = 37 * result + arg20.hashCode; |
| 89 | + // I can see my house from here! |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + return result; |
| 109 | +} |
| 110 | + |
| 111 | +/// Combine the hashCodes of an arbitrary number of values from an Iterable into |
| 112 | +/// one value. This function will return the same value if given "null" as if |
| 113 | +/// given an empty list. |
| 114 | +int hashList(Iterable<Object> args) { |
| 115 | + int result = 373; |
| 116 | + if (args != null) { |
| 117 | + for (Object arg in args) { |
| 118 | + assert(arg is! Iterable); |
| 119 | + result = 37 * result + arg.hashCode; |
| 120 | + } |
| 121 | + } |
| 122 | + return result; |
| 123 | +} |
0 commit comments