factor/core/growable/growable-docs.factor

40 lines
2.3 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
USING: help.markup help.syntax kernel sequences
sequences.private ;
IN: growable
ARTICLE: "growable" "Resizable sequence implementation"
"Resizable sequences are implemented by having a wrapper object hold a reference to an underlying sequence, together with a fill pointer indicating how many elements of the underlying sequence are occupied. When the fill pointer exceeds the underlying sequence capacity, the underlying sequence grows."
2007-09-20 18:09:08 -04:00
$nl
"There is a resizable sequence mixin:"
{ $subsections growable }
"This mixin implements the sequence protocol by assuming the object has two specific slots:"
{ $list
{ { $snippet "length" } " - the fill pointer (number of occupied elements in the underlying storage)" }
{ { $snippet "underlying" } " - the underlying storage" }
}
2007-09-20 18:09:08 -04:00
"The underlying sequence must implement a generic word:"
{ $subsections resize }
2008-12-08 15:58:00 -05:00
{ $link "vectors" } " and " { $link "sbufs" } " are implemented using the resizable sequence facility." ;
2007-09-20 18:09:08 -04:00
ABOUT: "growable"
HELP: capacity
{ $values { "seq" "a vector or string buffer" } { "n" "the capacity of the sequence" } }
{ $description "Outputs the number of elements the sequence can hold without growing." } ;
HELP: new-size
{ $values { "old" "a positive integer" } { "new" "a positive integer" } }
{ $description "Computes the new size of a resizable sequence." } ;
HELP: ensure
2014-01-08 14:44:12 -05:00
{ $values { "n" "a non-negative integer" } { "seq" growable } }
{ $description "Ensures that " { $snippet "seq" } " has sufficient capacity to store an " { $snippet "n" } "th element." $nl "This word behaves as follows, depending on the relation between " { $snippet "n" } ", the capacity of the underlying storage, and the length of the sequence:"
2009-01-16 14:30:43 -05:00
{ $list
{ "If " { $snippet "n" } " is less than the length of the sequence, does nothing." }
2014-01-08 14:44:12 -05:00
{ "If " { $snippet "n" } " is greater than or equal to the capacity of the underlying storage, the underlying storage is grown." }
{ "If " { $snippet "n" } " is greater than or equal to the length, the length is increased." }
2009-01-16 14:30:43 -05:00
}
"In the case that new elements are added to the sequence (last two cases), the new elements are undefined." }
{ $notes "This word is used in the implementation of the " { $link set-nth } " generic for sequences supporting the resizable sequence protocol (see " { $link "growable" } ")."
2007-09-20 18:09:08 -04:00
} ;