| 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 _MARKER = const _SetletMarker(); | 10 static const _MARKER = const _SetletMarker(); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 _extra = null; | 242 _extra = null; |
| 243 } | 243 } |
| 244 | 244 |
| 245 Set<E> union(Set<E> other) => new Set<E>.from(this)..addAll(other); | 245 Set<E> union(Set<E> other) => new Set<E>.from(this)..addAll(other); |
| 246 | 246 |
| 247 Setlet<E> intersection(Set<E> other) => | 247 Setlet<E> intersection(Set<E> other) => |
| 248 new Setlet<E>.from(this.where((e) => other.contains(e))); | 248 new Setlet<E>.from(this.where((e) => other.contains(e))); |
| 249 | 249 |
| 250 Setlet<E> difference(Set<E> other) => | 250 Setlet<E> difference(Set<E> other) => |
| 251 new Setlet<E>.from(this.where((e) => !other.contains(e))); | 251 new Setlet<E>.from(this.where((e) => !other.contains(e))); |
| 252 |
| 253 Setlet<E> toSet() { |
| 254 Setlet<E> result = new Setlet<E>(); |
| 255 if (_extra == null) { |
| 256 result._contents = _contents; |
| 257 } else if (_extra == MARKER) { |
| 258 result._extra = MARKER; |
| 259 result._contents = _contents.toSet(); |
| 260 } else { |
| 261 result._extra = _extra; |
| 262 result._contents = _contents.toList(); |
| 263 } |
| 264 return result; |
| 265 } |
| 252 } | 266 } |
| 253 | 267 |
| 254 class _SetletMarker { | 268 class _SetletMarker { |
| 255 const _SetletMarker(); | 269 const _SetletMarker(); |
| 256 toString() => "-"; | 270 toString() => "-"; |
| 257 } | 271 } |
| 258 | 272 |
| 259 class _SetletSingleIterator<E> implements Iterator<E> { | 273 class _SetletSingleIterator<E> implements Iterator<E> { |
| 260 var _element; | 274 var _element; |
| 261 E _current; | 275 E _current; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 289 if (Setlet._MARKER != candidate) { | 303 if (Setlet._MARKER != candidate) { |
| 290 _current = candidate; | 304 _current = candidate; |
| 291 _remaining--; | 305 _remaining--; |
| 292 return true; | 306 return true; |
| 293 } | 307 } |
| 294 } | 308 } |
| 295 _current = null; | 309 _current = null; |
| 296 return false; | 310 return false; |
| 297 } | 311 } |
| 298 } | 312 } |
| OLD | NEW |