OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of protobuf; | 5 part of protobuf; |
6 | 6 |
7 class UnknownFieldSet { | 7 class UnknownFieldSet { |
8 | 8 |
9 final Map<int, UnknownFieldSetField> _fields = | 9 final Map<int, UnknownFieldSetField> _fields = |
10 new Map<int, UnknownFieldSetField>(); | 10 new Map<int, UnknownFieldSetField>(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 return _fields.putIfAbsent(number, () => new UnknownFieldSetField()); | 113 return _fields.putIfAbsent(number, () => new UnknownFieldSetField()); |
114 } | 114 } |
115 | 115 |
116 bool operator ==(other) { | 116 bool operator ==(other) { |
117 if (other is! UnknownFieldSet) return false; | 117 if (other is! UnknownFieldSet) return false; |
118 | 118 |
119 UnknownFieldSet o = other; | 119 UnknownFieldSet o = other; |
120 return _areMapsEqual(o._fields, _fields); | 120 return _areMapsEqual(o._fields, _fields); |
121 } | 121 } |
122 | 122 |
123 int get hashCode => _fields.hashCode; | 123 int get hashCode { |
| 124 int hash = 0; |
| 125 _fields.forEach((number, value) { |
| 126 hash = ((37 * hash) + number) & 0x3fffffff; |
| 127 hash = ((53 * hash) + value.hashCode) & 0x3fffffff; |
| 128 }); |
| 129 return hash; |
| 130 } |
124 | 131 |
125 String toString() => _toString(''); | 132 String toString() => _toString(''); |
126 | 133 |
127 String _toString(String indent) { | 134 String _toString(String indent) { |
128 var stringBuffer = new StringBuffer(); | 135 var stringBuffer = new StringBuffer(); |
129 | 136 |
130 for (int tag in sorted(_fields.keys)) { | 137 for (int tag in sorted(_fields.keys)) { |
131 var field = _fields[tag]; | 138 var field = _fields[tag]; |
132 for (var value in field.values) { | 139 for (var value in field.values) { |
133 if (value is UnknownFieldSet) { | 140 if (value is UnknownFieldSet) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 181 } |
175 } | 182 } |
176 if (!_areListsEqual(o.varints, varints)) return false; | 183 if (!_areListsEqual(o.varints, varints)) return false; |
177 if (!_areListsEqual(o.fixed32s, fixed32s)) return false; | 184 if (!_areListsEqual(o.fixed32s, fixed32s)) return false; |
178 if (!_areListsEqual(o.fixed64s, fixed64s)) return false; | 185 if (!_areListsEqual(o.fixed64s, fixed64s)) return false; |
179 if (!_areListsEqual(o.groups, groups)) return false; | 186 if (!_areListsEqual(o.groups, groups)) return false; |
180 | 187 |
181 return true; | 188 return true; |
182 } | 189 } |
183 | 190 |
184 int get hashCode => lengthDelimited.hashCode; | 191 int get hashCode { |
| 192 int hash = 0; |
| 193 lengthDelimited.forEach((value) { |
| 194 for (int i = 0; i < value.length; i++) { |
| 195 hash = (hash + value[i]) & 0x3fffffff; |
| 196 hash = (hash + hash << 10) & 0x3fffffff; |
| 197 hash = (hash ^ hash >> 6) & 0x3fffffff; |
| 198 } |
| 199 hash = (hash + hash << 3) & 0x3fffffff; |
| 200 hash = (hash ^ hash >> 11) & 0x3fffffff; |
| 201 hash = (hash + hash << 15) & 0x3fffffff; |
| 202 }); |
| 203 varints.forEach( |
| 204 (value) => hash = (hash + 7 * value.hashCode) & 0x3fffffff); |
| 205 fixed32s.forEach( |
| 206 (value) => hash = (hash + 37 * value.hashCode) & 0x3fffffff); |
| 207 fixed64s.forEach( |
| 208 (value) => hash = (hash + 53 * value.hashCode) & 0x3fffffff); |
| 209 groups.forEach( |
| 210 (value) => hash = (hash + value.hashCode) & 0x3fffffff); |
| 211 return hash; |
| 212 } |
185 | 213 |
186 List get values => [] | 214 List get values => [] |
187 ..addAll(lengthDelimited) | 215 ..addAll(lengthDelimited) |
188 ..addAll(varints) | 216 ..addAll(varints) |
189 ..addAll(fixed32s) | 217 ..addAll(fixed32s) |
190 ..addAll(fixed64s) | 218 ..addAll(fixed64s) |
191 ..addAll(groups); | 219 ..addAll(groups); |
192 | 220 |
193 void writeTo(int fieldNumber, CodedBufferWriter output) { | 221 void writeTo(int fieldNumber, CodedBufferWriter output) { |
194 write(type, value) { | 222 write(type, value) { |
(...skipping 26 matching lines...) Expand all Loading... |
221 void addVarint(Int64 value) { | 249 void addVarint(Int64 value) { |
222 varints.add(value); | 250 varints.add(value); |
223 } | 251 } |
224 | 252 |
225 bool hasRequiredFields() => false; | 253 bool hasRequiredFields() => false; |
226 | 254 |
227 bool isInitialized() => true; | 255 bool isInitialized() => true; |
228 | 256 |
229 int get length => values.length; | 257 int get length => values.length; |
230 } | 258 } |
OLD | NEW |