@@ -58,7 +58,7 @@ for(var IndexedSequence____Key in IndexedSequence){if(IndexedSequence.hasOwnProp
58
58
Vector . prototype . set = function ( index , value ) { "use strict" ;
59
59
var tailOffset = getTailOffset ( this . $Vector_size ) ;
60
60
61
- if ( index + this . $Vector_origin >= tailOffset + SIZE ) {
61
+ if ( index >= this . length ) {
62
62
return this . withMutations ( function ( vect )
63
63
{ return vect . $Vector_setBounds ( 0 , index + 1 ) . set ( index , value ) ; }
64
64
) ;
@@ -176,10 +176,24 @@ for(var IndexedSequence____Key in IndexedSequence){if(IndexedSequence.hasOwnProp
176
176
177
177
// @pragma Composition
178
178
179
+ Vector . prototype . merge = function ( ) { "use strict" ; var seqs = Array . prototype . slice . call ( arguments , 0 ) ;
180
+ return ImmutableMap . prototype . merge . apply (
181
+ vectorWithLengthOfLongestSeq ( this , seqs ) , arguments ) ;
182
+ } ;
183
+
179
184
Vector . prototype . mergeWith = function ( fn ) { "use strict" ; var seqs = Array . prototype . slice . call ( arguments , 1 ) ;
180
- var merged = ImmutableMap . prototype . mergeWith . apply ( this , arguments ) ;
181
- var maxLength = Math . max . apply ( null , seqs . map ( function ( seq ) { return seq . length || 0 ; } ) ) ;
182
- return maxLength > merged . length ? merged . $Vector_setBounds ( 0 , maxLength ) : merged ;
185
+ return ImmutableMap . prototype . mergeWith . apply (
186
+ vectorWithLengthOfLongestSeq ( this , seqs ) , arguments ) ;
187
+ } ;
188
+
189
+ Vector . prototype . mergeDeep = function ( ) { "use strict" ; var seqs = Array . prototype . slice . call ( arguments , 0 ) ;
190
+ return ImmutableMap . prototype . mergeDeep . apply (
191
+ vectorWithLengthOfLongestSeq ( this , seqs ) , arguments ) ;
192
+ } ;
193
+
194
+ Vector . prototype . mergeDeepWith = function ( fn ) { "use strict" ; var seqs = Array . prototype . slice . call ( arguments , 1 ) ;
195
+ return ImmutableMap . prototype . mergeDeepWith . apply (
196
+ vectorWithLengthOfLongestSeq ( this , seqs ) , arguments ) ;
183
197
} ;
184
198
185
199
Vector . prototype . setLength = function ( length ) { "use strict" ;
@@ -206,15 +220,16 @@ for(var IndexedSequence____Key in IndexedSequence){if(IndexedSequence.hasOwnProp
206
220
207
221
// New origin might require creating a higher root.
208
222
var offsetShift = 0 ;
209
- while ( newOrigin < 0 ) {
223
+ while ( newOrigin + offsetShift < 0 ) {
224
+ // TODO: why only ever shifting over by 1?
210
225
newRoot = new VNode ( newRoot . array . length ? [ , newRoot ] : [ ] , owner ) ;
211
226
offsetShift += 1 << newLevel ;
212
- newOrigin += offsetShift ;
213
227
newLevel += SHIFT ;
214
228
}
215
229
if ( offsetShift ) {
216
- newSize += offsetShift ;
230
+ newOrigin += offsetShift ;
217
231
oldOrigin += offsetShift ;
232
+ newSize += offsetShift ;
218
233
oldSize += offsetShift ;
219
234
}
220
235
@@ -267,7 +282,9 @@ for(var IndexedSequence____Key in IndexedSequence){if(IndexedSequence.hasOwnProp
267
282
beginIndex = ( ( newOrigin ) >>> newLevel ) & MASK ;
268
283
endIndex = ( ( newTailOffset - 1 ) >>> newLevel ) & MASK ;
269
284
if ( beginIndex === endIndex ) {
270
- offsetShift += 1 << newLevel ;
285
+ if ( beginIndex ) {
286
+ offsetShift += ( 1 << newLevel ) * beginIndex ;
287
+ }
271
288
newLevel -= SHIFT ;
272
289
newRoot = newRoot && newRoot . array [ beginIndex ] ;
273
290
}
@@ -405,9 +422,6 @@ for(var IndexedSequence____Key in IndexedSequence){if(IndexedSequence.hasOwnProp
405
422
} ;
406
423
407
424
408
- Vector . prototype . merge = ImmutableMap . prototype . merge ;
409
- Vector . prototype . mergeDeep = ImmutableMap . prototype . mergeDeep ;
410
- Vector . prototype . mergeDeepWith = ImmutableMap . prototype . mergeDeepWith ;
411
425
Vector . prototype . withMutations = ImmutableMap . prototype . withMutations ;
412
426
Vector . prototype . updateIn = ImmutableMap . prototype . updateIn ;
413
427
@@ -600,6 +614,11 @@ Vector.prototype.updateIn = ImmutableMap.prototype.updateIn;
600
614
601
615
602
616
617
+ function vectorWithLengthOfLongestSeq ( vector , seqs ) {
618
+ var maxLength = Math . max . apply ( null , seqs . map ( function ( seq ) { return seq . length || 0 ; } ) ) ;
619
+ return maxLength > vector . length ? vector . setLength ( maxLength ) : vector ;
620
+ }
621
+
603
622
function rawIndex ( index , origin ) {
604
623
if ( index < 0 ) throw new Error ( 'Index out of bounds' ) ;
605
624
return index + origin ;
0 commit comments