C# 클래스 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.

파일 보기 프로젝트 열기: PaulMineau/AIMA.Net 1 사용 예제들

공개 메소드들

메소드 설명
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.

보호된 메소드들

메소드 설명
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.

메소드 상세

Append() 공개 메소드

Append a string to this buffer.
public Append ( CharBuffer s ) : void
s CharBuffer The string to append.
리턴 void

Append() 공개 메소드

Append a character to this buffer.
public Append ( char c ) : void
c char
리턴 void

Append() 공개 메소드

Append a string to this buffer.
public Append ( string s ) : void
s string The string to append.
리턴 void

CharBuffer() 공개 메소드

Default constructor.
public CharBuffer ( ) : System
리턴 System

CharBuffer() 공개 메소드

Construct with a specific capacity.
public CharBuffer ( int capacity ) : System
capacity int
리턴 System

CheckCapacity() 보호된 메소드

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

Clear() 공개 메소드

Empty the buffer.
public Clear ( ) : void
리턴 void

Grow() 보호된 메소드

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.
리턴 void

IndexOf() 공개 메소드

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.
리턴 int

Remove() 공개 메소드

Remove a character at the specified index.
public Remove ( int i ) : void
i int The index of the character to remove.
리턴 void

Remove() 공개 메소드

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.
리턴 void

SetBuffer() 공개 메소드

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.
리턴 void

ShiftToZero() 보호된 메소드

Move the buffer contents such that headIndex becomes 0.
protected ShiftToZero ( ) : void
리턴 void

SpeedTest() 공개 정적인 메소드

Compare speed to StringBuilder.
public static SpeedTest ( ) : void
리턴 void

TestSelf() 공개 정적인 메소드

Simple self test.
public static TestSelf ( ) : bool
리턴 bool

ToString() 공개 메소드

Return the current contents as a string.
public ToString ( ) : String
리턴 String

this() 공개 메소드

Indexer.
public this ( int index ) : char
index int
리턴 char