Skip to content

Commit

Permalink
Created new sandbox project for working on documentation samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ByronMayne committed Sep 10, 2023
1 parent 0b46cb0 commit 91b6842
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 14 deletions.
41 changes: 27 additions & 14 deletions documentation/generic/ring_buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@
A ring buffer is a data structure that efficiently manages a fixed-size, cyclically-referenced buffer, allowing for constant-time insertions and removals while overwriting the oldest data when full.


```csharp title=MyClass.cs
using Extended.Collections;
```csharp title=RingBufferSandbox.cs
using Extended.Collections.Generic;

public class MyClass()
namespace Extended.Collections.Playground.Generic
{
public MyClass()
public class RingBufferSandbox : Sandbox
{
RingBuffer<string> buffer = new RingBuffer<string>(3);
buffer.Add("A");
buffer.Add("B");
buffer.Add("C");
buffer.Add("D");
Log(buffer) // ["B", "C", "D"]
private readonly RingBuffer<string> m_buffer;

buffer.Remove("C");
Log(buffer); // ["B", "D"]
public RingBufferSandbox()
{
m_buffer = new RingBuffer<string>(3);
}

buffer.Clear();
Log(buffer) // []
protected override void Run()
{
m_buffer.Add("A");
m_buffer.Add("B");
m_buffer.Add("C");
Logger.Information("1. {Buffer}", m_buffer); // 1. [ "A", "B", "C" ]
m_buffer.Add("D");
Logger.Information("2. {Buffer}", m_buffer); // 2. [ "B", "C", "D" ]
m_buffer.Remove("C");
Logger.Information("3. {Buffer}", m_buffer); // 3. [ "B", "D" ]
m_buffer.Add("E");
Logger.Information("4. {Buffer}", m_buffer); // 4. [ "B", "D", "E" ]
m_buffer.Clear();
Logger.Information("5. {Buffer}", m_buffer); // [ ]
}
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
34 changes: 34 additions & 0 deletions src/Extended.Collections.Playground/Generic/RingBufferSandbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Extended.Collections.Generic;

namespace Extended.Collections.Playground.Generic
{
public class RingBufferSandbox : Sandbox
{
private readonly RingBuffer<string> m_buffer;

public RingBufferSandbox()
{
m_buffer = new RingBuffer<string>(3);
}

protected override void Run()
{
m_buffer.Add("A");
m_buffer.Add("B");
m_buffer.Add("C");
Logger.Information("1. {Buffer}", m_buffer); // 1. [ "A", "B", "C" ]

m_buffer.Add("D");
Logger.Information("2. {Buffer}", m_buffer); // 2. [ "B", "C", "D" ]

m_buffer.Remove("C");
Logger.Information("3. {Buffer}", m_buffer); // 3. [ "B", "D" ]

m_buffer.Add("E");
Logger.Information("4. {Buffer}", m_buffer); // 4. [ "B", "D", "E" ]

m_buffer.Clear();
Logger.Information("5. {Buffer}", m_buffer); // [ ]
}
}
}
10 changes: 10 additions & 0 deletions src/Extended.Collections.Playground/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Extended.Collections.Playground
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
18 changes: 18 additions & 0 deletions src/Extended.Collections.Playground/Sandbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Serilog;

namespace Extended.Collections.Playground
{
public abstract class Sandbox
{
public ILogger Logger { get; }

protected Sandbox()
{
Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
}

protected abstract void Run();
}
}

0 comments on commit 91b6842

Please sign in to comment.