OLD | NEW |
1 dart_library.library('collection/src/queue_list', null, /* Imports */[ | 1 dart_library.library('collection/src/queue_list', null, /* Imports */[ |
2 'dart/_runtime', | 2 'dart/_runtime', |
3 'dart/core', | 3 'dart/core', |
4 'dart/collection' | 4 'dart/collection' |
5 ], /* Lazy imports */[ | 5 ], /* Lazy imports */[ |
6 ], function(exports, dart, core, collection) { | 6 ], function(exports, dart, core, collection) { |
7 'use strict'; | 7 'use strict'; |
8 let dartx = dart.dartx; | 8 let dartx = dart.dartx; |
9 const _head = Symbol('_head'); | 9 const _head = Symbol('_head'); |
10 const _tail = Symbol('_tail'); | 10 const _tail = Symbol('_tail'); |
(...skipping 15 matching lines...) Expand all Loading... |
26 initialCapacity = QueueList$()._nextPowerOf2(initialCapacity); | 26 initialCapacity = QueueList$()._nextPowerOf2(initialCapacity); |
27 } | 27 } |
28 dart.assert(QueueList$()._isPowerOf2(initialCapacity)); | 28 dart.assert(QueueList$()._isPowerOf2(initialCapacity)); |
29 this[_table] = core.List$(E).new(initialCapacity); | 29 this[_table] = core.List$(E).new(initialCapacity); |
30 } | 30 } |
31 static from(source) { | 31 static from(source) { |
32 if (dart.is(source, core.List)) { | 32 if (dart.is(source, core.List)) { |
33 let length = source[dartx.length]; | 33 let length = source[dartx.length]; |
34 let queue = new (QueueList$(E))(dart.notNull(length) + 1); | 34 let queue = new (QueueList$(E))(dart.notNull(length) + 1); |
35 dart.assert(dart.notNull(queue[_table][dartx.length]) > dart.notNull(l
ength)); | 35 dart.assert(dart.notNull(queue[_table][dartx.length]) > dart.notNull(l
ength)); |
36 let sourceList = dart.as(source, core.List); | 36 let sourceList = source; |
37 queue[_table][dartx.setRange](0, length, dart.as(sourceList, core.Iter
able$(E)), 0); | 37 queue[_table][dartx.setRange](0, length, sourceList, 0); |
38 queue[_tail] = length; | 38 queue[_tail] = length; |
39 return queue; | 39 return queue; |
40 } else { | 40 } else { |
41 let _ = new (QueueList$(E))(); | 41 let _ = new (QueueList$(E))(); |
42 _.addAll(source); | 42 _.addAll(source); |
43 return _; | 43 return _; |
44 } | 44 } |
45 } | 45 } |
46 add(element) { | 46 add(element) { |
47 dart.as(element, E); | 47 dart.as(element, E); |
48 this[_add](element); | 48 this[_add](element); |
49 } | 49 } |
50 addAll(elements) { | 50 addAll(elements) { |
51 dart.as(elements, core.Iterable$(E)); | 51 dart.as(elements, core.Iterable$(E)); |
52 if (dart.is(elements, core.List)) { | 52 if (dart.is(elements, core.List)) { |
53 let list = dart.as(elements, core.List); | 53 let list = elements; |
54 let addCount = list[dartx.length]; | 54 let addCount = list[dartx.length]; |
55 let length = this.length; | 55 let length = this.length; |
56 if (dart.notNull(length) + dart.notNull(addCount) >= dart.notNull(this
[_table][dartx.length])) { | 56 if (dart.notNull(length) + dart.notNull(addCount) >= dart.notNull(this
[_table][dartx.length])) { |
57 this[_preGrow](dart.notNull(length) + dart.notNull(addCount)); | 57 this[_preGrow](dart.notNull(length) + dart.notNull(addCount)); |
58 this[_table][dartx.setRange](length, dart.notNull(length) + dart.not
Null(addCount), dart.as(list, core.Iterable$(E)), 0); | 58 this[_table][dartx.setRange](length, dart.notNull(length) + dart.not
Null(addCount), list, 0); |
59 this[_tail] = dart.notNull(this[_tail]) + dart.notNull(addCount); | 59 this[_tail] = dart.notNull(this[_tail]) + dart.notNull(addCount); |
60 } else { | 60 } else { |
61 let endSpace = dart.notNull(this[_table][dartx.length]) - dart.notNu
ll(this[_tail]); | 61 let endSpace = dart.notNull(this[_table][dartx.length]) - dart.notNu
ll(this[_tail]); |
62 if (dart.notNull(addCount) < endSpace) { | 62 if (dart.notNull(addCount) < endSpace) { |
63 this[_table][dartx.setRange](this[_tail], dart.notNull(this[_tail]
) + dart.notNull(addCount), dart.as(list, core.Iterable$(E)), 0); | 63 this[_table][dartx.setRange](this[_tail], dart.notNull(this[_tail]
) + dart.notNull(addCount), list, 0); |
64 this[_tail] = dart.notNull(this[_tail]) + dart.notNull(addCount); | 64 this[_tail] = dart.notNull(this[_tail]) + dart.notNull(addCount); |
65 } else { | 65 } else { |
66 let preSpace = dart.notNull(addCount) - endSpace; | 66 let preSpace = dart.notNull(addCount) - endSpace; |
67 this[_table][dartx.setRange](this[_tail], dart.notNull(this[_tail]
) + endSpace, dart.as(list, core.Iterable$(E)), 0); | 67 this[_table][dartx.setRange](this[_tail], dart.notNull(this[_tail]
) + endSpace, list, 0); |
68 this[_table][dartx.setRange](0, preSpace, dart.as(list, core.Itera
ble$(E)), endSpace); | 68 this[_table][dartx.setRange](0, preSpace, list, endSpace); |
69 this[_tail] = preSpace; | 69 this[_tail] = preSpace; |
70 } | 70 } |
71 } | 71 } |
72 } else { | 72 } else { |
73 for (let element of elements) | 73 for (let element of elements) |
74 this[_add](element); | 74 this[_add](element); |
75 } | 75 } |
76 } | 76 } |
77 toString() { | 77 toString() { |
78 return collection.IterableBase.iterableToFullString(this, "{", "}"); | 78 return collection.IterableBase.iterableToFullString(this, "{", "}"); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 'length' | 226 'length' |
227 ]); | 227 ]); |
228 QueueList._INITIAL_CAPACITY = 8; | 228 QueueList._INITIAL_CAPACITY = 8; |
229 return QueueList; | 229 return QueueList; |
230 }); | 230 }); |
231 let QueueList = QueueList$(); | 231 let QueueList = QueueList$(); |
232 // Exports: | 232 // Exports: |
233 exports.QueueList$ = QueueList$; | 233 exports.QueueList$ = QueueList$; |
234 exports.QueueList = QueueList; | 234 exports.QueueList = QueueList; |
235 }); | 235 }); |
OLD | NEW |