lengthen ( n seq -- )
Factor handbook » The language » Collections » Sequence operations » Sequence protocol

Prev:set-length ( n seq -- )
Next:like ( seq exemplar -- newseq )


Vocabulary
sequences

Inputs
na non-negative integer
seqa resizable sequence


Outputs
None

Generic word contract
Ensures the sequence has a length of at least n elements. This word differs from set-length in two respects:
This word does not shrink the sequence if n is less than its length.
The word doubles the underlying storage of seq, whereas set-length is permitted to set it to equal n. This ensures that repeated calls to this word with constant increments of n do not result in a quadratic amount of copying, so that for example push-all can run efficiently when used in a loop.


Examples
USING: kernel prettyprint sequences ; 6 V{ 1 1 1 1 } [ lengthen ] keep .
V{ 1 1 1 1 0 0 }

Showing how the underlying storage grows:
USING: accessors kernel prettyprint sequences ; 6 V{ 1 1 1 1 } [ lengthen ] keep underlying>> .
{ 1 1 1 1 0 0 0 0 0 0 0 0 0 0 }

When n is less than the length of seq:
USING: kernel prettyprint sequences ; 2 V{ 1 2 3 4 5 6 7 8 } [ lengthen ] keep .
V{ 1 2 3 4 5 6 7 8 }


Definition


Methods