Skip to content

Commit

Permalink
Updated the code examples to use remark-code-import
Browse files Browse the repository at this point in the history
This copies the source code from the solutions to make sure it compiles and does not go out of date.
  • Loading branch information
ByronMayne committed Sep 12, 2023
1 parent 1d8851e commit 4918f3c
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 86 deletions.
37 changes: 2 additions & 35 deletions documentation/generic/ring_buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,6 @@
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=RingBufferSandbox.cs
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); // [ ]
}
}
}
```csharp file=../../src/Extended.Collections.Playground\Generic\RingBufferSandbox.cs#L2-
// Imported
```
2 changes: 2 additions & 0 deletions documentation/generic/specialized/_category_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label: 'Specialized'
position: 1
25 changes: 2 additions & 23 deletions documentation/generic/specialized/ordered_dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,7 @@ Cons:

### Hypothetical Use Case:
Suppose you are building a task management application, and you need to maintain a list of tasks for a project while preserving the order in which they were added. An OrderedDictionary can be useful in this scenario to store and manage tasks associated with a project.
```cs
using System;
using System.Collections.Specialized;

class Program
{
static void Main()
{
// Create an OrderedDictionary to store tasks for a project.
OrderedDictionary<string, string> projectTasks = new OrderedDictionary<string, string>();

// Add tasks to the project in a specific order.
projectTasks.Add("Task1", "Complete research");
projectTasks.Add("Task2", "Write documentation");
projectTasks.Add("Task3", "Test functionality");

// Access tasks by their keys while maintaining their order.
Console.WriteLine("Project Tasks:");
foreach (DictionaryEntry entry in projectTasks)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}
}
}
```csharp file=../../../src/Extended.Collections.Playground\Generic\Specialized\OrderedDictionarySandbox.cs#L2-
// Imported
```
6 changes: 6 additions & 0 deletions docusaurus/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
const path = require('path')
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/oceanicNext');

Expand Down Expand Up @@ -43,6 +44,11 @@ const config = {
breadcrumbs: true,
routeBasePath: '/',
showLastUpdateTime: true,
remarkPlugins: [
[require('remark-code-import'), {
removeRedundantIndentations: true,
}]
],
editUrl: ({docPath}) =>
`https://github.com/ByronMayne/Extended.Collections/edit/main/documentation/${docPath}`,

Expand Down
4 changes: 3 additions & 1 deletion docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react-dom": "^17.0.2",
"remark-code-import": "0.4.0",
"remark-jargon": "^2.22.2"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "2.4.1",
Expand Down
56 changes: 55 additions & 1 deletion docusaurus/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6338,6 +6338,14 @@ relateurl@^0.2.7:
resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9"
integrity sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog==

remark-code-import@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/remark-code-import/-/remark-code-import-0.4.0.tgz#94cbfe74087c55a84e65f0a972c0977cac8fc7f6"
integrity sha512-3UHRIfr7+kRBGOy6Bzp4c1dl8BLCLv+saBTAgW4+lPfs56vV6yBhO038i6MJTEoyXX1zli7l8tMGIHbYANdtZg==
dependencies:
to-gatsby-remark-plugin "^0.1.0"
unist-util-visit "^2.0.1"

remark-emoji@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/remark-emoji/-/remark-emoji-2.2.0.tgz#1c702090a1525da5b80e15a8f963ef2c8236cac7"
Expand All @@ -6352,6 +6360,13 @@ remark-footnotes@2.0.0:
resolved "https://registry.yarnpkg.com/remark-footnotes/-/remark-footnotes-2.0.0.tgz#9001c4c2ffebba55695d2dd80ffb8b82f7e6303f"
integrity sha512-3Clt8ZMH75Ayjp9q4CorNeyjwIxHFcTkaektplKGl2A1jNGEUey8cKL0ZC5vJwfcD5GFGsNLImLG/NGzWIzoMQ==

remark-jargon@^2.22.2:
version "2.22.2"
resolved "https://registry.yarnpkg.com/remark-jargon/-/remark-jargon-2.22.2.tgz#d81cefe6ecd419488c7ac1936add4c6d9e958ea0"
integrity sha512-TRQozoCzaOt9dNlgdffWVujZP5FRO+SSDHAUDVqYZi110J7HbcCiYTvIOJdwH2roMtQGd0bnGWibDyRCjeXlZA==
dependencies:
unist-util-visit "^4.1.0"

remark-mdx@1.6.22:
version "1.6.22"
resolved "https://registry.yarnpkg.com/remark-mdx/-/remark-mdx-1.6.22.tgz#06a8dab07dcfdd57f3373af7f86bd0e992108bbd"
Expand Down Expand Up @@ -7056,6 +7071,13 @@ to-fast-properties@^2.0.0:
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
integrity sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==

to-gatsby-remark-plugin@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/to-gatsby-remark-plugin/-/to-gatsby-remark-plugin-0.1.0.tgz#34167b2c3cf3209745cf97e5a488042586f9990d"
integrity sha512-blmhJ/gIrytWnWLgPSRCkhCPeki6UBK2daa3k9mGahN7GjwHu8KrS7F70MvwlsG7IE794JLgwAdCbi4hU4faFQ==
dependencies:
to-vfile "^6.1.0"

to-readable-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/to-readable-stream/-/to-readable-stream-1.0.0.tgz#ce0aa0c2f3df6adf852efb404a783e77c0475771"
Expand All @@ -7068,6 +7090,14 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

to-vfile@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/to-vfile/-/to-vfile-6.1.0.tgz#5f7a3f65813c2c4e34ee1f7643a5646344627699"
integrity sha512-BxX8EkCxOAZe+D/ToHdDsJcVI4HqQfmw0tCkp31zf3dNP/XWIAjU4CmeuSwsSoOzOTqHPOL0KUzyZqJplkD0Qw==
dependencies:
is-buffer "^2.0.0"
vfile "^4.0.0"

toidentifier@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
Expand Down Expand Up @@ -7215,6 +7245,13 @@ unist-util-is@^4.0.0:
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-4.1.0.tgz#976e5f462a7a5de73d94b706bac1b90671b57797"
integrity sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg==

unist-util-is@^5.0.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-5.2.1.tgz#b74960e145c18dcb6226bc57933597f5486deae9"
integrity sha512-u9njyyfEh43npf1M+yGKDGVPbY/JWEemg5nH05ncKPfi+kBbKBJoTdsogMu33uhytuLlv9y0O7GH7fEdwLdLQw==
dependencies:
"@types/unist" "^2.0.0"

unist-util-position@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/unist-util-position/-/unist-util-position-3.1.0.tgz#1c42ee6301f8d52f47d14f62bbdb796571fa2d47"
Expand Down Expand Up @@ -7249,7 +7286,15 @@ unist-util-visit-parents@^3.0.0:
"@types/unist" "^2.0.0"
unist-util-is "^4.0.0"

unist-util-visit@2.0.3, unist-util-visit@^2.0.0, unist-util-visit@^2.0.3:
unist-util-visit-parents@^5.1.1:
version "5.1.3"
resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-5.1.3.tgz#b4520811b0ca34285633785045df7a8d6776cfeb"
integrity sha512-x6+y8g7wWMyQhL1iZfhIPhDAs7Xwbn9nRosDXl7qoPTSCy0yNxnKc+hWokFifWQIDGi154rdUqKvbCa4+1kLhg==
dependencies:
"@types/unist" "^2.0.0"
unist-util-is "^5.0.0"

unist-util-visit@2.0.3, unist-util-visit@^2.0.0, unist-util-visit@^2.0.1, unist-util-visit@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c"
integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==
Expand All @@ -7258,6 +7303,15 @@ unist-util-visit@2.0.3, unist-util-visit@^2.0.0, unist-util-visit@^2.0.3:
unist-util-is "^4.0.0"
unist-util-visit-parents "^3.0.0"

unist-util-visit@^4.1.0:
version "4.1.2"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-4.1.2.tgz#125a42d1eb876283715a3cb5cceaa531828c72e2"
integrity sha512-MSd8OUGISqHdVvfY9TPhyK2VdUrPgxkUtWSuMHF6XAAFuL4LokseigBnZtPnJMu+FbynTkFNnFlyjxpVKujMRg==
dependencies:
"@types/unist" "^2.0.0"
unist-util-is "^5.0.0"
unist-util-visit-parents "^5.1.1"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
Expand Down
45 changes: 19 additions & 26 deletions src/Extended.Collections.Playground/Generic/RingBufferSandbox.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
using Extended.Collections.Generic;
namespace Extended.Collections.Playground.Generic;
using Extended.Collections.Generic;

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

public RingBufferSandbox()
{
m_buffer = new RingBuffer<string>(3);
}
private readonly RingBuffer<string> m_buffer = new (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" ]
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.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.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.Add("E");
Logger.Information("4. {Buffer}", m_buffer); // 4. [ "B", "D", "E" ]

m_buffer.Clear();
Logger.Information("5. {Buffer}", m_buffer); // [ ]
}
m_buffer.Clear();
Logger.Information("5. {Buffer}", m_buffer); // [ ]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Extended.Collections.Generic.Specialized;
using System.Collections;

namespace Extended.Collections.Playground.Generic.Specialized;

public class OrderedDictionarySandbox : Sandbox
{
private OrderedDictionary<string, string> m_tasks = new ();

protected override void Run()
{
// Add tasks to the project in a specific order.
m_tasks.Add("Task1", "Complete research");
m_tasks.Add("Task2", "Write documentation");
m_tasks.Add("Task3", "Test functionality");

// Access tasks by their keys while maintaining their order.
Console.WriteLine("Project Tasks:");
foreach (KeyValuePair<string, string> entry in m_tasks)
{
Console.WriteLine($"TaskId: {entry.Key}");
Console.WriteLine($"Name:{entry.Value}");
}

// Remove
m_tasks.RemoveAt(1); // Remove by index
m_tasks.Remove("Task1"); // Remove by key

Logger.Information("Value: {Value}", m_tasks);
// 1. [ 'Task2' ] = "Write documentation"
// 2. [ 'Task3' ] = "Test functionality"
}
}

0 comments on commit 4918f3c

Please sign in to comment.