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 _SetletMarker _MARKER = const _SetletMarker(); |
11 static const CAPACITY = 8; | 11 static const int CAPACITY = 8; |
12 | 12 |
13 // The setlet can be in one of four states: | 13 // The setlet can be in one of four states: |
14 // | 14 // |
15 // * Empty (extra: null, contents: marker) | 15 // * Empty (extra: null, contents: marker) |
16 // * Single element (extra: null, contents: element) | 16 // * Single element (extra: null, contents: element) |
17 // * List-backed (extra: length, contents: list) | 17 // * List-backed (extra: length, contents: list) |
18 // * Set-backed (extra: marker, contents: set) | 18 // * Set-backed (extra: marker, contents: set) |
19 // | 19 // |
20 // When the setlet is list-backed, the list in the contents field | 20 // When the setlet is list-backed, the list in the contents field |
21 // may have empty slots filled with the marker value. | 21 // may have empty slots filled with the marker value. |
22 var _contents = _MARKER; | 22 dynamic _contents = _MARKER; |
23 var _extra; | 23 var _extra; |
24 | 24 |
25 Setlet(); | 25 Setlet(); |
26 Setlet.from(Iterable<E> elements) { | 26 Setlet.from(Iterable<E> elements) { |
27 addAll(elements); | 27 addAll(elements); |
28 } | 28 } |
29 | 29 |
30 Iterator<E> get iterator { | 30 Iterator<E> get iterator { |
31 if (_extra == null) { | 31 if (_extra == null) { |
32 return new _SetletSingleIterator<E>(_contents); | 32 return new _SetletSingleIterator<E>(_contents); |
(...skipping 273 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 |