Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

2015 004 Addition of Buffer module

Ken Friis Larsen edited this pageAug 12, 2015 ·3 revisions

Proposal 2015-004

Addition ofBuffer module

Author: Ken Friis Larsen
Last revised: August 11, 2015
Status: proposed
Discussion:issue #4


Synopsis

signature BUFFER =sigtypebufval new      : int -> bufval contents : buf -> stringval size     : buf -> intval clear    : buf -> unitval reset    : buf -> unitval addChar      : buf -> char -> unitval addString    : buf -> string -> unitval addSubString : buf -> substring -> unitendstructure Buffer :> BUFFER

Description

  • type buf

    A type of mutable string buffers that allows efficientconcatenation at the end and automatically expand as necessary. Itprovides accumulative concatenation of strings in quasi-linear time(instead of quadratic time when strings are concatenated pairwise).

  • new hintcreates a new empty buffer. RaisesSize ifhint <= 0 orhint > String.maxSize.The argument hint is used as the initial size of the internalstring that holds the buffer contents. The internal string isautomatically reallocated as contents is stored in the buffer. Forbest performance, hint should be of the same order of magnitude asthe number of characters that are expected to be stored in thebuffer (for instance, 80 for a buffer that holds one output line).Nothing bad will happen if the buffer grows beyond that limit,however. In doubt, takehint = 16 for instance.

  • contents bufreturns the contents ofbuf.

  • size bufreturns the size of the contents ofbuf.

  • clear bufemptysbuf.

  • reset bufemptysbuf and shrink the internal string to the initial hint.

  • addChar buf cappendsc at the end ofbuf.

  • addString buf sappendss at the end ofbuf.

  • addSubString buf ssappendsss at the end ofbuf.

Discussion

Generating strings efficiently is needed for many programming tasks. It is possible to implement this module with other parts of the Basis Library, however to get top performance you need to use the internal representation of strings (for some systems at least).

This module is shipped as part ofMoscow ML's library, since version 2.10.

Impact

Adopting this proposal should not affect existing programs.

Rationale

This module is a natural candidate for inclusion in the Basis Library. Similar structureshave been found to be useful in other programming languages, for instanceStringBuilder in Java and theBuffer module in O'Caml (the original inspiration for this module).


History

  • [2015-08-11] Proposed

Creative Commons License
This document is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp