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