factor/library/collections/growable.facts

50 lines
3.2 KiB
Plaintext
Raw Normal View History

IN: sequences-internals
USING: help kernel sequences ;
2006-08-15 21:23:05 -04:00
HELP: set-fill
{ $values { "n" "a new fill pointer" } { "seq" "a resizable sequence" } }
{ $contract "Sets the fill pointer (number of occupied elements in the underlying storage) of a resizable sequence." }
{ $side-effects "seq" }
{ $warning "This word is in the " { $vocab-link "sequences-internals" } " vocabulary because it is not safe. Changing the fill pointer to a negative value, or a value higher than the underlying sequence length can lead to memory corruption. User code should use " { $link set-length } " instead." } ;
2006-08-15 21:23:05 -04:00
HELP: underlying
{ $values { "seq" "a resizable sequence" } { "underlying" "the underlying sequence" } }
{ $contract "Outputs the underlying storage of a resizable sequence." } ;
2006-08-15 21:23:05 -04:00
HELP: set-underlying
{ $values { "underlying" "a sequence" } { "seq" "a resizable sequence" } }
{ $contract "Modifies the underlying storage of a resizable sequence." }
{ $warning "This word is in the " { $vocab-link "sequences-internals" } " vocabulary because it is not safe. Setting an underlying sequence shorter than the fill pointer can lead to memory corruption." } ;
2006-08-15 21:23:05 -04:00
HELP: capacity
{ $values { "seq" "a vector or string buffer" } { "n" "the capacity of the sequence" } }
2006-08-15 21:23:05 -04:00
{ $description "Outputs the number of elements the sequence can hold without growing." } ;
2006-08-15 21:23:05 -04:00
HELP: new-size
{ $values { "old" "a positive integer" } { "new" "a positive integer" } }
{ $description "Computes the new size of a resizable sequence." } ;
2006-08-15 21:23:05 -04:00
HELP: ensure
{ $values { "n" "a positive integer" } { "seq" "a resizable sequence" } }
{ $description "If " { $snippet "n" } " is less than the length of the sequence, does nothing. Otherwise, if " { $snippet "n" } " also exceeds the capacity of the underlying storage, the underlying storage is grown, and the fill pointer is reset. Finally, if " { $snippet "n" } " is greater than or equal to the length but less than the capacity of the underlying storage, the fill pointer is moved and nothing else is done."
$terpri
"This word is used in the implementation of the " { $link set-nth } " generic for sequences supporting the resizable sequence protocol (see " { $link "sequences-resizable" } ")."
} ;
2006-08-15 21:23:05 -04:00
HELP: bounds-error
{ $values { "n" "a positive integer" } { "seq" "a sequence" } }
2006-08-01 17:35:00 -04:00
{ $description "Throws a " { $link bounds-error } "." }
{ $error-description "Thrown by " { $link nth } ", " { $link set-nth } " and " { $link set-length } " if the given index lies beyond the bounds of the sequence." } ;
2006-08-15 21:23:05 -04:00
HELP: bounds-check
{ $values { "n" "a positive integer" } { "seq" "a sequence" } }
{ $description "Throws an error if " { $snippet "n" } " is negative or if it is greater than or equal to the length of " { $snippet "seq" } ". Otherwise the two inputs remain on the stack." } ;
2006-08-15 21:23:05 -04:00
HELP: grow-length
{ $values { "n" "a positive integer" } { "seq" "a sequence" } }
{ $description "An implementation of the " { $link set-length } " generic for sequences supporting the resizable sequence protocol (see " { $link "sequences-resizable" } ")." } ;
HELP: clone-resizable
{ $values { "seq" "a resizable sequence" } { "newseq" "a fresh sequence" } }
{ $description "An implementation of the " { $link clone } " generic for sequences supporting the resizable sequence protocol (see " { $link "sequences-resizable" } ")." } ;