| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library dart2js.util.setlet; | 5 library dart2js.util.setlet; |
| 6 | 6 |
| 7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
| 8 | 8 |
| 9 class Setlet<E> extends IterableBase<E> implements Set<E> { | 9 class Setlet<E> extends IterableBase<E> implements Set<E> { |
| 10 static const _SetletMarker _MARKER = const _SetletMarker(); | 10 static const _SetletMarker _MARKER = const _SetletMarker(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 bool get isEmpty { | 50 bool get isEmpty { |
| 51 if (_extra == null) { | 51 if (_extra == null) { |
| 52 return _MARKER == _contents; | 52 return _MARKER == _contents; |
| 53 } else if (_MARKER == _extra) { | 53 } else if (_MARKER == _extra) { |
| 54 return _contents.isEmpty; | 54 return _contents.isEmpty; |
| 55 } else { | 55 } else { |
| 56 return _extra == 0; | 56 return _extra == 0; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool contains(E element) { | 60 bool contains(Object element) { |
| 61 if (_extra == null) { | 61 if (_extra == null) { |
| 62 return _contents == element; | 62 return _contents == element; |
| 63 } else if (_MARKER == _extra) { | 63 } else if (_MARKER == _extra) { |
| 64 return _contents.contains(element); | 64 return _contents.contains(element); |
| 65 } else { | 65 } else { |
| 66 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { | 66 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { |
| 67 var candidate = _contents[i]; | 67 var candidate = _contents[i]; |
| 68 if (_MARKER == candidate) continue; | 68 if (_MARKER == candidate) continue; |
| 69 if (candidate == element) return true; | 69 if (candidate == element) return true; |
| 70 remaining--; | 70 remaining--; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } else { | 225 } else { |
| 226 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { | 226 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { |
| 227 var element = _contents[i]; | 227 var element = _contents[i]; |
| 228 if (_MARKER == element) continue; | 228 if (_MARKER == element) continue; |
| 229 action(element); | 229 action(element); |
| 230 remaining--; | 230 remaining--; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 bool containsAll(Iterable<E> other) { | 235 bool containsAll(Iterable<Object> other) { |
| 236 for (E e in other) { | 236 for (E e in other) { |
| 237 if (!this.contains(e)) return false; | 237 if (!this.contains(e)) return false; |
| 238 } | 238 } |
| 239 ; | 239 ; |
| 240 return true; | 240 return true; |
| 241 } | 241 } |
| 242 | 242 |
| 243 clear() { | 243 clear() { |
| 244 _contents = _MARKER; | 244 _contents = _MARKER; |
| 245 _extra = null; | 245 _extra = null; |
| 246 } | 246 } |
| 247 | 247 |
| 248 Set<E> union(Set<E> other) => new Set<E>.from(this)..addAll(other); | 248 Set<E> union(Set<E> other) => new Set<E>.from(this)..addAll(other); |
| 249 | 249 |
| 250 Setlet<E> intersection(Set<E> other) => | 250 Setlet<E> intersection(Set<Object> other) => |
| 251 new Setlet<E>.from(this.where((e) => other.contains(e))); | 251 new Setlet<E>.from(this.where((e) => other.contains(e))); |
| 252 | 252 |
| 253 Setlet<E> difference(Set<Object> other) => | 253 Setlet<E> difference(Set<Object> other) => |
| 254 new Setlet<E>.from(this.where((e) => !other.contains(e))); | 254 new Setlet<E>.from(this.where((e) => !other.contains(e))); |
| 255 | 255 |
| 256 Setlet<E> toSet() { | 256 Setlet<E> toSet() { |
| 257 Setlet<E> result = new Setlet<E>(); | 257 Setlet<E> result = new Setlet<E>(); |
| 258 if (_extra == null) { | 258 if (_extra == null) { |
| 259 result._contents = _contents; | 259 result._contents = _contents; |
| 260 } else if (_extra == _MARKER) { | 260 } else if (_extra == _MARKER) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (Setlet._MARKER != candidate) { | 306 if (Setlet._MARKER != candidate) { |
| 307 _current = candidate; | 307 _current = candidate; |
| 308 _remaining--; | 308 _remaining--; |
| 309 return true; | 309 return true; |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 _current = null; | 312 _current = null; |
| 313 return false; | 313 return false; |
| 314 } | 314 } |
| 315 } | 315 } |
| OLD | NEW |