Skip to content

Commit a02c075

Browse files
committed
Update for ring-buffer->xvector API change
#1188
1 parent a0a918f commit a02c075

2 files changed

Lines changed: 75 additions & 7 deletions

File tree

doc/modutil.texi

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7445,11 +7445,11 @@ An error is signaled if the index is out of bounds.
74457445
@end defun
74467446

74477447

7448-
@defun ring-buffer->flat-vector rb :optional start end
7448+
@defun ring-buffer->xvector rb :optional start end
74497449
@c MOD data.ring-buffer
74507450
@c EN
74517451
Returns the current valid content of the ring buffer @var{rb}
7452-
as a fresh flat vector
7452+
as a fresh vector
74537453
of the same type as @var{rb}'s storage. If the optional @var{start}/@var{end}
74547454
indexes are given, the content between those indexes are taken.
74557455
@c JP
@@ -7462,18 +7462,86 @@ indexes are given, the content between those indexes are taken.
74627462
@example
74637463
(define rb (make-ring-buffer (make-vector 4)))
74647464

7465-
(ring-buffer->flat-vector rb) @result{} #()
7465+
(ring-buffer->xvector rb) @result{} #()
74667466

74677467
(ring-buffer-add-back! rb 'a)
74687468
(ring-buffer-add-back! rb 'b)
74697469
(ring-buffer-add-front! rb 'z)
74707470
(ring-buffer-add-front! rb 'y)
74717471

7472-
(ring-buffer->flat-vector rb) @result{} #(y z a b)
7473-
(ring-buffer->flat-vector rb 1 3) @result{} #(z a)
7472+
(ring-buffer->xvector rb) @result{} #(y z a b)
7473+
(ring-buffer->xvector rb 1 3) @result{} #(z a)
74747474
@end example
74757475
@end defun
74767476

7477+
@defun ring-buffer->xvector! target tstart rb :optional start end
7478+
@c MOD data.ring-buffer
7479+
@c EN
7480+
Like @code{ring-buffer->xvector} above, but store the result into
7481+
@var{target}, starting from index @var{tstart}. @var{Target} must be
7482+
the same type of vector of the backing storage of @var{rb},
7483+
and must be large enough to hold the result.
7484+
If the optional @var{start}/@var{end}
7485+
indexes are given, the content between those indexes are taken.
7486+
@c JP
7487+
@code{ring-buffer->xvector}と似ていますが、結果を@var{target}の、
7488+
インデックス@var{tstart}からに格納します。
7489+
@var{target}は@var{rb}のバッキングストレージと同じ型で、
7490+
結果を保持するのに十分な容量がなければなりません。
7491+
@var{start}/@var{end}インデックスを指定した場合はそのインデックスの範囲内の
7492+
内容だけが取り出されます。
7493+
@c COMMON
7494+
@end defun
7495+
7496+
7497+
@defun ring-buffer->xsubvectors rb :optional start end
7498+
@c MOD data.ring-buffer
7499+
@c EN
7500+
Returns @code{(vec start1 end1)} or @code{(vec start1 end1 vec start2 end2)},
7501+
where @var{vec} is the backing storage of ring buffer @var{rb},
7502+
and @var{start1}, @var{end1}, @var{start2}, @var{end2} are integer index
7503+
into @var{vec}. They represent the range(s) in the backing storage
7504+
where active ring buffer data is stored. It may be contiguous,
7505+
or splitted to two parts when the buffer is wrapped around.
7506+
7507+
The optional @var{start} and @var{end} arguments are indexes of
7508+
the contents of ring buffer (@emph{not} the indexes to the backing
7509+
storage) to limit the range of the contents to be extracted.
7510+
7511+
The returned list can be passed as arguments to
7512+
@code{vector-append-subvectors} (@pxref{R7RS vectors}) or
7513+
@code{@@vector-append-subvector} (@pxref{Uvector basic operations}).
7514+
7515+
This procedure is lightweight, for it doesn't allocate. However,
7516+
be aware that the content of @var{vec} may be changed and/or indexes
7517+
become invalid by operations on
7518+
@var{rb}. I you want a snapshot of the ring buffer contents,
7519+
you can use @code{ring-buffer->xvector} above.
7520+
@c JP
7521+
@code{(vec start1 end1)}か@code{(vec start1 end1 vec start2 end2)}を返します。
7522+
ここで、@var{vec}はリングバッファ@var{rb}のバッキングストレージ、
7523+
@var{start1}、@var{end1}、@var{start2}、@var{end2}はバッキングストレージの
7524+
整数インデックスです。これは、バッキングストレージ中の、リングバッファの有効な
7525+
データが存在する範囲を示しています。
7526+
有効なデータはひとつづきであるか、バッファの末尾でラップアラウンドして
7527+
二つの部分に分かれて存在します。
7528+
7529+
省略可能な@var{start}と@var{end}引数はリングバッファの内容への整数インデックス
7530+
(バッキングストレージのインデックスではなく)で、取り出す範囲を制限します。
7531+
7532+
返されるリストは、それを引数として
7533+
@code{vector-append-subvectors} (@ref{R7RS vectors}参照) あるいは
7534+
@code{@@vector-append-subvector} (@ref{Uvector basic operations}参照)
7535+
を呼び出すことができる形になっています。
7536+
7537+
この手続きはアロケーションを行わないので軽いですが、この後でリングバッファに
7538+
対する操作を行うと@var{vec}の内容が上書きされたり返されたインデックスが無効
7539+
になることに注意してください。ある時点でのリングバッファの内容のスナップショットを
7540+
保存したい場合は、上の@code{ring-buffer->xvector}が使えます。
7541+
@c COMMON
7542+
@end defun
7543+
7544+
74777545

74787546
@c ----------------------------------------------------------------------
74797547
@node Skew binary random-access lists, Sparse data containers, Ring buffer, Library modules - Utilities

lib/srfi/214.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
(define (flexvector-copy fv :optional (start 0)
102102
(end (flexvector-length fv)))
103103
(assume-type fv <ring-buffer>)
104-
(make-ring-buffer (ring-buffer->flat-vector fv start end)
104+
(make-ring-buffer (ring-buffer->xvector fv start end)
105105
:initial-tail-index (- end start)))
106106

107107
(define (flexvector-reverse-copy fv :optional (start 0)
@@ -123,7 +123,7 @@
123123
(let loop ([fvs fvs] [k 0])
124124
(if (null? fvs)
125125
(make-ring-buffer dest :initial-tail-index len)
126-
(begin (ring-buffer->flat-vector! dest k (car fvs))
126+
(begin (ring-buffer->xvector! dest k (car fvs))
127127
(loop (cdr fvs) (+ k (flexvector-length (car fvs)))))))))
128128

129129
;; flexvector-append-subvectors

0 commit comments

Comments
 (0)