C# Class RTools.Util.CharBuffer

Buffer for characters. This approximates StringBuilder but is designed to be faster for specific operations. This is about 30% faster for the operations I'm interested in (Append, Clear, Length, ToString). This trades off memory for speed.

To make Remove from the head fast, this is implemented as a ring buffer.

This uses head and tail indices into a fixed-size array. This will grow the array as necessary.

Afficher le fichier Open project: PaulMineau/AIMA.Net Class Usage Examples

Méthodes publiques

Méthode Description
Append ( CharBuffer s ) : void

Append a string to this buffer.

Append ( char c ) : void

Append a character to this buffer.

Append ( string s ) : void

Append a string to this buffer.

CharBuffer ( ) : System

Default constructor.

CharBuffer ( int capacity ) : System

Construct with a specific capacity.

Clear ( ) : void

Empty the buffer.

IndexOf ( char c ) : int

Find the first instance of a character in the buffer, and return its index. This returns -1 if the character is not found.

Remove ( int i ) : void

Remove a character at the specified index.

Remove ( int i, int n ) : void

Remove a specified number of characters at the specified index.

SetBuffer ( char b, int len ) : void

Overwrite this object's underlying buffer with the specified buffer.

SpeedTest ( ) : void

Compare speed to StringBuilder.

TestSelf ( ) : bool

Simple self test.

ToString ( ) : String

Return the current contents as a string.

this ( int index ) : char

Indexer.

Méthodes protégées

Méthode Description
CheckCapacity ( int requestedLength ) : void

Ensure that we're set for the requested length by potentially growing or shifting contents.

Grow ( int requestedLen ) : void

Reallocate the buffer to be larger. For the new size, this uses the max of the requested length and double the current capacity. This does not shift, meaning it does not change the head or tail indices.

ShiftToZero ( ) : void

Move the buffer contents such that headIndex becomes 0.

Method Details

Append() public méthode

Append a string to this buffer.
public Append ( CharBuffer s ) : void
s CharBuffer The string to append.
Résultat void

Append() public méthode

Append a character to this buffer.
public Append ( char c ) : void
c char
Résultat void

Append() public méthode

Append a string to this buffer.
public Append ( string s ) : void
s string The string to append.
Résultat void

CharBuffer() public méthode

Default constructor.
public CharBuffer ( ) : System
Résultat System

CharBuffer() public méthode

Construct with a specific capacity.
public CharBuffer ( int capacity ) : System
capacity int
Résultat System

CheckCapacity() protected méthode

Ensure that we're set for the requested length by potentially growing or shifting contents.
protected CheckCapacity ( int requestedLength ) : void
requestedLength int
Résultat void

Clear() public méthode

Empty the buffer.
public Clear ( ) : void
Résultat void

Grow() protected méthode

Reallocate the buffer to be larger. For the new size, this uses the max of the requested length and double the current capacity. This does not shift, meaning it does not change the head or tail indices.
protected Grow ( int requestedLen ) : void
requestedLen int The new requested length.
Résultat void

IndexOf() public méthode

Find the first instance of a character in the buffer, and return its index. This returns -1 if the character is not found.
public IndexOf ( char c ) : int
c char The character to find.
Résultat int

Remove() public méthode

Remove a character at the specified index.
public Remove ( int i ) : void
i int The index of the character to remove.
Résultat void

Remove() public méthode

Remove a specified number of characters at the specified index.
public Remove ( int i, int n ) : void
i int The index of the characters to remove.
n int The number of characters to remove.
Résultat void

SetBuffer() public méthode

Overwrite this object's underlying buffer with the specified buffer.
public SetBuffer ( char b, int len ) : void
b char The character array.
len int The number of characters to consider filled /// in the input buffer.
Résultat void

ShiftToZero() protected méthode

Move the buffer contents such that headIndex becomes 0.
protected ShiftToZero ( ) : void
Résultat void

SpeedTest() public static méthode

Compare speed to StringBuilder.
public static SpeedTest ( ) : void
Résultat void

TestSelf() public static méthode

Simple self test.
public static TestSelf ( ) : bool
Résultat bool

ToString() public méthode

Return the current contents as a string.
public ToString ( ) : String
Résultat String

this() public méthode

Indexer.
public this ( int index ) : char
index int
Résultat char