set-length ( n seq -- )
Factor documentation > Factor handbook > The language > Collections > Sequence operations > Sequence protocol
Prev:set-nth-unsafe ( elt n seq -- )
Next:lengthen ( n seq -- )


Vocabulary
sequences

Inputs and outputs
na non-negative integer
seqa resizable sequence


Generic word contract
Resizes a sequence. The initial contents of the new area is undefined.

Errors
Throws a no-method error if the sequence is not resizable, and a bounds-error if the new length is negative.

Side effects
Modifies seq

Definition
IN: sequences

GENERIC: set-length ( n seq -- )


Methods
USING: accessors grouping.private kernel math sequences ;

M: abstract-clumps set-length
[ n>> + 1 - ] [ seq>> ] bi set-length ; inline


USING: accessors grouping.private kernel math sequences ;

M: abstract-groups set-length
[ n>> * ] [ seq>> ] bi set-length ; inline


USING: accessors sequences sequences.repeating ;

M: cycles set-length length<< ;


USING: accessors growable kernel math sequences
sequences.private ;

M: growable set-length
bounds-check-head 2dup length <
[ 2dup contract ] [ 2dup capacity > [ 2dup expand ] when ]
if length<< ;


USING: accessors sequences sequences.modified ;

M: modified set-length seq>> set-length ;


USING: accessors kernel math sequences sequences.inserters ;

M: offset-growable set-length
[ offset>> + ] [ underlying>> ] bi set-length ; inline


USING: accessors kernel sequences sequences.modified ;

M: summed set-length seqs>> [ set-length ] with each ;


USING: accessors kernel sequences xml.data ;

M: tag set-length [ children>> ] call \ set-length execute ;


USING: accessors kernel sequences xml.data ;

M: xml-chunk set-length [ seq>> ] call \ set-length execute ;


USING: accessors kernel sequences xml.data ;

M: xml set-length [ body>> ] call \ set-length execute ;