| 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 /** | 5 /** |
| 6 * This class is the public interface of a set. A set is a collection | 6 * This class is the public interface of a set. A set is a collection |
| 7 * without duplicates. | 7 * without duplicates. |
| 8 */ | 8 */ |
| 9 abstract class Set<E> extends Collection<E> { | 9 interface Set<E> extends Collection<E> |
| 10 factory Set() => new HashSetImplementation<E>(); | 10 default HashSetImplementation<E extends Hashable> { |
| 11 Set(); |
| 11 | 12 |
| 12 /** | 13 /** |
| 13 * Creates a [Set] that contains all elements of [other]. | 14 * Creates a [Set] that contains all elements of [other]. |
| 14 */ | 15 */ |
| 15 factory Set.from(Iterable<E> other) { | 16 Set.from(Iterable<E> other); |
| 16 return new HashSetImplementation<E>.from(other); | |
| 17 } | |
| 18 | 17 |
| 19 /** | 18 /** |
| 20 * Returns true if [value] is in the set. | 19 * Returns true if [value] is in the set. |
| 21 */ | 20 */ |
| 22 bool contains(E value); | 21 bool contains(E value); |
| 23 | 22 |
| 24 /** | 23 /** |
| 25 * Adds [value] into the set. The method has no effect if | 24 * Adds [value] into the set. The method has no effect if |
| 26 * [value] was already in the set. | 25 * [value] was already in the set. |
| 27 */ | 26 */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 */ | 61 */ |
| 63 Set<E> intersection(Collection<E> other); | 62 Set<E> intersection(Collection<E> other); |
| 64 | 63 |
| 65 /** | 64 /** |
| 66 * Removes all elements in the set. | 65 * Removes all elements in the set. |
| 67 */ | 66 */ |
| 68 void clear(); | 67 void clear(); |
| 69 | 68 |
| 70 } | 69 } |
| 71 | 70 |
| 72 abstract class HashSet<E extends Hashable> extends Set<E> { | 71 interface HashSet<E extends Hashable> extends Set<E> |
| 73 factory HashSet() => new HashSetImplementation<E>(); | 72 default HashSetImplementation<E extends Hashable> { |
| 73 HashSet(); |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Creates a [Set] that contains all elements of [other]. | 76 * Creates a [Set] that contains all elements of [other]. |
| 77 */ | 77 */ |
| 78 factory HashSet.from(Iterable<E> other) => | 78 HashSet.from(Iterable<E> other); |
| 79 new HashSetImplementation<E>.from(other); | |
| 80 } | 79 } |
| OLD | NEW |