| 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 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 class HashSet<E> extends Collection<E> implements Set<E> { | 7 class HashSet<E> extends Collection<E> implements Set<E> { |
| 8 static const int _INITIAL_CAPACITY = 8; | 8 static const int _INITIAL_CAPACITY = 8; |
| 9 final _HashTable<E> _table; | 9 final _HashTable<E> _table; |
| 10 | 10 |
| 11 HashSet() : _table = new _HashTable(_INITIAL_CAPACITY) { | 11 HashSet() : _table = new _HashTable(_INITIAL_CAPACITY) { |
| 12 _table._container = this; | 12 _table._container = this; |
| 13 } | 13 } |
| 14 | 14 |
| 15 factory HashSet.from(Iterable<E> iterable) { | 15 factory HashSet.from(Iterable<E> iterable) { |
| 16 return new HashSet<E>()..addAll(iterable); | 16 return new HashSet<E>()..addAll(iterable); |
| 17 } | 17 } |
| 18 | 18 |
| 19 // Iterable. | 19 // Iterable. |
| 20 Iterator<E> get iterator => new _HashTableKeyIterator<E>(_table); | 20 Iterator<E> get iterator => new _HashTableKeyIterator<E>(_table); |
| 21 | 21 |
| 22 int get length => _table._elementCount; |
| 23 |
| 22 bool get isEmpty => _table._elementCount == 0; | 24 bool get isEmpty => _table._elementCount == 0; |
| 23 | 25 |
| 24 bool contains(Object object) => _table._get(object) >= 0; | 26 bool contains(Object object) => _table._get(object) >= 0; |
| 25 | 27 |
| 26 // Collection. | 28 // Collection. |
| 27 void add(E element) { | 29 void add(E element) { |
| 28 _table._put(element); | 30 _table._put(element); |
| 29 _table._checkCapacity(); | 31 _table._checkCapacity(); |
| 30 } | 32 } |
| 31 | 33 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 for (E element in other) { | 108 for (E element in other) { |
| 107 if (this.contains(element)) { | 109 if (this.contains(element)) { |
| 108 result.add(element); | 110 result.add(element); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 return result; | 113 return result; |
| 112 } | 114 } |
| 113 | 115 |
| 114 String toString() => Collections.collectionToString(this); | 116 String toString() => Collections.collectionToString(this); |
| 115 } | 117 } |
| OLD | NEW |