Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: runtime/lib/collection_patch.dart

Issue 15263004: Adding isNotEmpty property to collection and string. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix template generation Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/array.dart ('k') | runtime/lib/growable_array.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 patch class HashMap<K, V> { 5 patch class HashMap<K, V> {
6 final _HashMapTable<K, V> _hashTable = new _HashMapTable<K, V>(); 6 final _HashMapTable<K, V> _hashTable = new _HashMapTable<K, V>();
7 7
8 /* patch */ HashMap() { 8 /* patch */ HashMap() {
9 _hashTable._container = this; 9 _hashTable._container = this;
10 } 10 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 } 103 }
104 104
105 /* patch */ Iterable<K> get keys => new _HashTableKeyIterable<K>(_hashTable); 105 /* patch */ Iterable<K> get keys => new _HashTableKeyIterable<K>(_hashTable);
106 /* patch */ Iterable<V> get values => 106 /* patch */ Iterable<V> get values =>
107 new _HashTableValueIterable<V>(_hashTable, _HashMapTable._VALUE_INDEX); 107 new _HashTableValueIterable<V>(_hashTable, _HashMapTable._VALUE_INDEX);
108 108
109 /* patch */ int get length => _hashTable._elementCount; 109 /* patch */ int get length => _hashTable._elementCount;
110 110
111 /* patch */ bool get isEmpty => _hashTable._elementCount == 0; 111 /* patch */ bool get isEmpty => _hashTable._elementCount == 0;
112
113 /* patch */ bool get isNotEmpty => !isEmpty;
112 } 114 }
113 115
114 patch class HashSet<E> { 116 patch class HashSet<E> {
115 static const int _INITIAL_CAPACITY = 8; 117 static const int _INITIAL_CAPACITY = 8;
116 final _HashTable<E> _table; 118 final _HashTable<E> _table;
117 119
118 /* patch */ HashSet() : _table = new _HashTable(_INITIAL_CAPACITY) { 120 /* patch */ HashSet() : _table = new _HashTable(_INITIAL_CAPACITY) {
119 _table._container = this; 121 _table._container = this;
120 } 122 }
121 123
122 factory HashSet.from(Iterable<E> iterable) { 124 factory HashSet.from(Iterable<E> iterable) {
123 return new HashSet<E>()..addAll(iterable); 125 return new HashSet<E>()..addAll(iterable);
124 } 126 }
125 127
126 // Iterable. 128 // Iterable.
127 /* patch */ Iterator<E> get iterator => new _HashTableKeyIterator<E>(_table); 129 /* patch */ Iterator<E> get iterator => new _HashTableKeyIterator<E>(_table);
128 130
129 /* patch */ int get length => _table._elementCount; 131 /* patch */ int get length => _table._elementCount;
130 132
131 /* patch */ bool get isEmpty => _table._elementCount == 0; 133 /* patch */ bool get isEmpty => _table._elementCount == 0;
132 134
135 /* patch */ bool get isNotEmpty => !isEmpty;
136
133 /* patch */ bool contains(Object object) => _table._get(object) >= 0; 137 /* patch */ bool contains(Object object) => _table._get(object) >= 0;
134 138
135 // Collection. 139 // Collection.
136 /* patch */ void add(E element) { 140 /* patch */ void add(E element) {
137 _table._put(element); 141 _table._put(element);
138 _table._checkCapacity(); 142 _table._checkCapacity();
139 } 143 }
140 144
141 /* patch */ void addAll(Iterable<E> objects) { 145 /* patch */ void addAll(Iterable<E> objects) {
142 for (E object in objects) { 146 for (E object in objects) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 /* patch */ Iterable<K> get keys => 297 /* patch */ Iterable<K> get keys =>
294 new _LinkedHashTableKeyIterable<K>(_hashTable); 298 new _LinkedHashTableKeyIterable<K>(_hashTable);
295 299
296 /* patch */ Iterable<V> get values => 300 /* patch */ Iterable<V> get values =>
297 new _LinkedHashTableValueIterable<V>(_hashTable, 301 new _LinkedHashTableValueIterable<V>(_hashTable,
298 _LinkedHashMapTable._VALUE_INDEX); 302 _LinkedHashMapTable._VALUE_INDEX);
299 303
300 /* patch */ int get length => _hashTable._elementCount; 304 /* patch */ int get length => _hashTable._elementCount;
301 305
302 /* patch */ bool get isEmpty => _hashTable._elementCount == 0; 306 /* patch */ bool get isEmpty => _hashTable._elementCount == 0;
307
308 /* patch */ bool get isNotEmpty => !isEmpty;
303 } 309 }
304 310
305 patch class LinkedHashSet<E> extends _HashSetBase<E> { 311 patch class LinkedHashSet<E> extends _HashSetBase<E> {
306 static const int _INITIAL_CAPACITY = 8; 312 static const int _INITIAL_CAPACITY = 8;
307 _LinkedHashTable<E> _table; 313 _LinkedHashTable<E> _table;
308 314
309 /* patch */ LinkedHashSet() { 315 /* patch */ LinkedHashSet() {
310 _table = new _LinkedHashTable(_INITIAL_CAPACITY); 316 _table = new _LinkedHashTable(_INITIAL_CAPACITY);
311 _table._container = this; 317 _table._container = this;
312 } 318 }
313 319
314 // Iterable. 320 // Iterable.
315 /* patch */ Iterator<E> get iterator { 321 /* patch */ Iterator<E> get iterator {
316 return new _LinkedHashTableKeyIterator<E>(_table); 322 return new _LinkedHashTableKeyIterator<E>(_table);
317 } 323 }
318 324
319 /* patch */ int get length => _table._elementCount; 325 /* patch */ int get length => _table._elementCount;
320 326
321 /* patch */ bool get isEmpty => _table._elementCount == 0; 327 /* patch */ bool get isEmpty => _table._elementCount == 0;
322 328
329 /* patch */ bool get isNotEmpty => !isEmpty;
330
323 /* patch */ bool contains(Object object) => _table._get(object) >= 0; 331 /* patch */ bool contains(Object object) => _table._get(object) >= 0;
324 332
325 /* patch */ void forEach(void action(E element)) { 333 /* patch */ void forEach(void action(E element)) {
326 int offset = _table._next(_LinkedHashTable._HEAD_OFFSET); 334 int offset = _table._next(_LinkedHashTable._HEAD_OFFSET);
327 int modificationCount = _table._modificationCount; 335 int modificationCount = _table._modificationCount;
328 while (offset != _LinkedHashTable._HEAD_OFFSET) { 336 while (offset != _LinkedHashTable._HEAD_OFFSET) {
329 E key = _table._key(offset); 337 E key = _table._key(offset);
330 action(key); 338 action(key);
331 _table._checkModification(modificationCount); 339 _table._checkModification(modificationCount);
332 offset = _table._next(offset); 340 offset = _table._next(offset);
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 1001
994 _LinkedHashMapTable() : super(_INITIAL_CAPACITY); 1002 _LinkedHashMapTable() : super(_INITIAL_CAPACITY);
995 1003
996 V _value(int offset) => _table[offset + _VALUE_INDEX]; 1004 V _value(int offset) => _table[offset + _VALUE_INDEX];
997 void _setValue(int offset, V value) { _table[offset + _VALUE_INDEX] = value; } 1005 void _setValue(int offset, V value) { _table[offset + _VALUE_INDEX] = value; }
998 1006
999 _copyEntry(List oldTable, int fromOffset, int toOffset) { 1007 _copyEntry(List oldTable, int fromOffset, int toOffset) {
1000 _table[toOffset + _VALUE_INDEX] = oldTable[fromOffset + _VALUE_INDEX]; 1008 _table[toOffset + _VALUE_INDEX] = oldTable[fromOffset + _VALUE_INDEX];
1001 } 1009 }
1002 } 1010 }
OLDNEW
« no previous file with comments | « runtime/lib/array.dart ('k') | runtime/lib/growable_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698