本文整理汇总了C#中CircularBuffer.Append方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Append方法的具体用法?C# CircularBuffer.Append怎么用?C# CircularBuffer.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.Append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CircularBuffer_AppendBuffer
public void CircularBuffer_AppendBuffer()
{
CircularBuffer<char> cb1 = new CircularBuffer<char>(20);
CircularBuffer<char> cb2 = new CircularBuffer<char>(20);
// Read is one chunk, write is one chunk
cb2.Produce(3);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(3);
cb1.Append(cb2);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is one chunk, but read is two chunks
cb1.Reset();
cb2.Reset();
cb2.Produce(15);
cb2.Consume(14);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is one chunk
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Append("123456789012345".ToCharArray());
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is two chunks, readlength < writelength
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Produce(15);
cb2.Consume(14);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is two chunks, readlength > writelength
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Produce(7);
cb2.Consume(6);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
}
示例2: CircularBuffer_AppendArray
public void CircularBuffer_AppendArray()
{
CircularBuffer<char> cb = new CircularBuffer<char>(20);
cb.Produce(10);
cb.Consume(9);
Assert.AreEqual(1, cb.Length);
Assert.AreEqual(19, cb.Free);
cb.Append("ABCDEFGHIJKLMN".ToCharArray(), 0, 14);
Assert.AreEqual(15, cb.Length);
Assert.AreEqual(5, cb.Free);
Assert.AreEqual("ABCDEFGHIJKLMN", cb.GetString(1, 14));
cb.Consume(15);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(20, cb.Free);
cb.Append("12345678901234567890".ToCharArray());
Assert.AreEqual(0, cb.Free);
Assert.AreEqual(20, cb.Length);
Assert.AreEqual("12345678901234567890", cb.GetString());
}