add some docs to circular

db4
Doug Coleman 2008-09-14 23:27:37 -05:00
parent e501a411fe
commit 7d418ec3de
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,58 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax io.streams.string sequences
math kernel ;
IN: circular
HELP: <circular-string>
{ $values
{ "n" integer }
{ "circular" circular } }
{ $description "Creates a new circular string object. A circular string is a string object that can be accessed out of bounds and the index will wrap around to the start of the string." } ;
HELP: <circular>
{ $values
{ "seq" sequence }
{ "circular" circular } }
{ $description "Creates a new " { $link circular } " object that wraps an existing sequence. By default, the index is set to zero." } ;
HELP: <growing-circular>
{ $values
{ "capacity" integer }
{ "growing-circular" growing-circular } }
{ $description "Creates a new growing-circular object." } ;
HELP: change-circular-start
{ $values
{ "n" integer } { "circular" circular } }
{ $description "Changes the start index of a circular object." } ;
HELP: circular
{ $description "A tuple class that stores a sequence and its start index." } ;
HELP: growing-circular
{ $description "A circular sequence that is growable." } ;
HELP: push-circular
{ $values
{ "elt" object } { "circular" circular } }
{ $description "Pushes an element to a " { $link circular } " object." } ;
HELP: push-growing-circular
{ $values
{ "elt" object } { "circular" circular } }
{ $description "Pushes an element onto a " { $link growing-circular } " object." } ;
ARTICLE: "circular" "circular"
"The " { $vocab-link "circular" } " vocabulary implements the " { $link "sequence-protocol" } " to allow an arbitrary start index and wrap-around indexing." $nl
"Creating a new circular object:"
{ $subsection <circular> }
{ $subsection <circular-string> }
{ $subsection <growing-circular> }
"Changing the start index:"
{ $subsection change-circular-start }
"Pushing new elements:"
{ $subsection push-circular }
{ $subsection push-growing-circular } ;
ABOUT: "circular"

View File

@ -11,9 +11,11 @@ TUPLE: circular seq start ;
: <circular> ( seq -- circular )
0 circular boa ;
<PRIVATE
: circular-wrap ( n circular -- n circular )
[ start>> + ] keep
[ seq>> length rem ] keep ; inline
PRIVATE>
M: circular length seq>> length ;
@ -37,11 +39,13 @@ TUPLE: growing-circular < circular length ;
M: growing-circular length length>> ;
<PRIVATE
: full? ( circular -- ? )
[ length ] [ seq>> length ] bi = ;
: set-peek ( elt seq -- )
[ length 1- ] keep set-nth ;
PRIVATE>
: push-growing-circular ( elt circular -- )
dup full? [ push-circular ]