Class 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.
Inherited Members
Namespace: RTools_NTS.Util
Assembly: NetTopologySuite.dll
Syntax
public class CharBuffer
Remarks
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.
Constructors
| Edit this page View SourceCharBuffer()
Default constructor.
Declaration
public CharBuffer()
CharBuffer(int)
Construct with a specific capacity.
Declaration
public CharBuffer(int capacity)
Parameters
Type | Name | Description |
---|---|---|
int | capacity |
Properties
| Edit this page View SourceCapacity
Returns the capacity of this character buffer.
Declaration
public int Capacity { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Indexer.
Declaration
public char this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index |
Property Value
Type | Description |
---|---|
char |
Length
Gets/Sets the number of characters in the character buffer. Increasing the length this way provides indeterminate results.
Declaration
public int Length { get; set; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceAppend(CharBuffer)
Append a string to this buffer.
Declaration
public void Append(CharBuffer s)
Parameters
Type | Name | Description |
---|---|---|
CharBuffer | s | The string to append. |
Append(char)
Append a character to this buffer.
Declaration
public void Append(char c)
Parameters
Type | Name | Description |
---|---|---|
char | c |
Append(string)
Append a string to this buffer.
Declaration
public void Append(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | The string to append. |
CheckCapacity(int)
Ensure that we're set for the requested length by potentially growing or shifting contents.
Declaration
protected void CheckCapacity(int requestedLength)
Parameters
Type | Name | Description |
---|---|---|
int | requestedLength |
Clear()
Empty the buffer.
Declaration
public void Clear()
Grow(int)
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.
Declaration
protected void Grow(int requestedLen)
Parameters
Type | Name | Description |
---|---|---|
int | requestedLen | The new requested length. |
IndexOf(char)
Find the first instance of a character in the buffer, and return its index. This returns -1 if the character is not found.
Declaration
public int IndexOf(char c)
Parameters
Type | Name | Description |
---|---|---|
char | c | The character to find. |
Returns
Type | Description |
---|---|
int | The index of the specified character, or -1 for not found. |
Remove(int)
Remove a character at the specified index.
Declaration
public void Remove(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the character to remove. |
Remove(int, int)
Remove a specified number of characters at the specified index.
Declaration
public void Remove(int i, int n)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the characters to remove. |
int | n | The number of characters to remove. |
SetBuffer(char[], int)
Overwrite this object's underlying buffer with the specified buffer.
Declaration
public void SetBuffer(char[] b, int len)
Parameters
Type | Name | Description |
---|---|---|
char[] | b | The character array. |
int | len | The number of characters to consider filled in the input buffer. |
ShiftToZero()
Move the buffer contents such that headIndex becomes 0.
Declaration
protected void ShiftToZero()
ToString()
Return the current contents as a string.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The new string. |