Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge to master #2

Merged
merged 180 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
3473a48
add Utils project
nam20485 Aug 19, 2023
90824b2
List implemented
nam20485 Aug 19, 2023
316de69
add collections to be implemented
nam20485 Aug 19, 2023
780b6a6
remove template generated class
nam20485 Aug 19, 2023
9c2826e
add test project
nam20485 Aug 20, 2023
8042fe0
use Array.IndexOf() and remember to increase size during Insert
nam20485 Aug 20, 2023
c103e2f
add more empty types of DataStructures
nam20485 Aug 20, 2023
a31a5b1
comment
nam20485 Aug 20, 2023
6fb3734
LinkedList working
nam20485 Aug 20, 2023
76e2bb0
add Driver console app
nam20485 Aug 20, 2023
4dfe9a9
add package and update packages
nam20485 Aug 20, 2023
53aab9e
add some tests
nam20485 Aug 20, 2023
6fda178
fix warning from linter
nam20485 Aug 20, 2023
b96f03f
add AddRanged and use it in IEnumerable<TValue> ctor
nam20485 Aug 20, 2023
d60424e
change name generic type parameter
nam20485 Aug 20, 2023
9293809
changes
nam20485 Aug 20, 2023
29773d1
add methods to Queue class
nam20485 Aug 20, 2023
2a585f5
implemented Stack
nam20485 Aug 20, 2023
ac630af
minor changes
nam20485 Aug 20, 2023
2283663
Queue implemented
nam20485 Aug 20, 2023
2160c50
fix List
nam20485 Aug 21, 2023
aba77c4
add some tests
nam20485 Aug 21, 2023
c85eb35
minor changes
nam20485 Aug 21, 2023
e9f8fb0
implement Heap
nam20485 Aug 21, 2023
55b6c2d
make PriorityQueue inherit from Heap
nam20485 Aug 21, 2023
64e27bb
add a static method to allow for heap sorting IEnumerable<TValue> col…
nam20485 Aug 21, 2023
19d6ad6
better message when throwing ArgumentOutOfRangeException
nam20485 Aug 21, 2023
4b2cabc
add comparer class to allow for descending sort
nam20485 Aug 21, 2023
71f397b
override ToArray() to make sure only Count items are copied into the …
nam20485 Aug 21, 2023
2d61343
add a static Instance member to use when many repeated instantiations…
nam20485 Aug 21, 2023
031a239
make collection classes inherit from IDsCollection and DsCollecitonBase
nam20485 Aug 21, 2023
4873404
remove unnecessary more-derived extnesion overload
nam20485 Aug 21, 2023
75e8064
small optimization to avoid creating new instantiations of zero-lengt…
nam20485 Aug 21, 2023
871c174
enable XML doc file output
nam20485 Aug 21, 2023
8ed3979
add more methods to the interface and provide implementationsin Heap
nam20485 Aug 21, 2023
decc396
minor changes to Heap algorithms (set _heapSize to _items.Count, not …
nam20485 Aug 21, 2023
111e60d
add CopyOf() method
nam20485 Aug 22, 2023
8cd1913
fix ctor()s
nam20485 Aug 22, 2023
c00cc36
add big test
nam20485 Aug 22, 2023
f4c83ae
add some LinkedList tests
nam20485 Aug 22, 2023
e38f6e1
minor refactoring and fix Add
nam20485 Aug 22, 2023
61a315d
add SwapValues(int, int) method
nam20485 Aug 22, 2023
cf4cb6f
throw exception if collection == null
nam20485 Aug 22, 2023
59e7437
initial implementation of PriroityQueue
nam20485 Aug 23, 2023
e8ea94f
changes
nam20485 Aug 23, 2023
25e6c0c
add more Heap methods
nam20485 Aug 23, 2023
d7feb14
changes
nam20485 Aug 23, 2023
071080f
make List.EnsureCapacity() internal so it can be used by other IDsCol…
nam20485 Aug 23, 2023
ab4d211
set _count to 0 in Clear()
nam20485 Aug 23, 2023
f6b1fff
add reference to containg LinkedList in Node
nam20485 Aug 23, 2023
64eeab7
add optimization in Find to return node in O(1) time when value searc…
nam20485 Aug 23, 2023
d16406c
change how Remove and RemoveNode work
nam20485 Aug 23, 2023
9ee7eba
add Utils class
nam20485 Aug 23, 2023
db278b1
remove data theory with null collection of innputs
nam20485 Aug 23, 2023
8f844f9
change argument name
nam20485 Aug 23, 2023
dc91bea
hide access to Nodes in the LinkedList
nam20485 Aug 23, 2023
3bf939e
change LinkedListTests to use Contains not Find
nam20485 Aug 23, 2023
c331ac6
change AddRange to add the items to the underlying list and then call…
nam20485 Aug 23, 2023
d851edd
make Heap.Count return _heapSize and set _heapSize = 0 in Clear
nam20485 Aug 23, 2023
e0d0a08
fix List.CopyOf so that copy only has actual items
nam20485 Aug 23, 2023
09d5e2d
bail on Heapify if its called when _heapSize == 0
nam20485 Aug 23, 2023
49c0b8d
add TODO comments re: respecting _heapSize in various methods
nam20485 Aug 23, 2023
675fddb
TestIdsCollections working
nam20485 Aug 23, 2023
4fb618d
add IDsCcollection.ToHeap()
nam20485 Aug 23, 2023
f2c86ec
fix IsHeap and SatisfiesHeapProperty
nam20485 Aug 24, 2023
2e9ba55
fix indexer of List
nam20485 Aug 24, 2023
7756a3a
add IsSorted and SortType
nam20485 Aug 24, 2023
922ede2
add MakeList
nam20485 Aug 24, 2023
9ed4bee
add tests
nam20485 Aug 24, 2023
163ba87
fix Heap.CopyOnlyItemsTo
nam20485 Aug 24, 2023
72b3686
add MinHeap class
nam20485 Aug 24, 2023
94068cd
fix CopyOnlyItemsTo in Heap
nam20485 Aug 24, 2023
4635770
add tests for MinHeap
nam20485 Aug 24, 2023
3639e55
fix Heap.Sort
nam20485 Aug 24, 2023
9e897a9
PriorityQueue working
nam20485 Aug 24, 2023
03ed01a
add MinPriorityQueue class
nam20485 Aug 24, 2023
9e53c2d
add code for PQ
nam20485 Aug 24, 2023
10c13cd
add PQ tests
nam20485 Aug 24, 2023
bbbc1f1
add randon int sequencde class
nam20485 Aug 24, 2023
3b2c0eb
put test data generation classes in their own classes
nam20485 Aug 24, 2023
a22e7bd
rename Make to Array
nam20485 Aug 24, 2023
d04797f
refactor
nam20485 Aug 24, 2023
d4d321d
add Next() to RandomIntSequence for getting a single random int
nam20485 Aug 25, 2023
fab1ed4
fix Heap.Contains()
nam20485 Aug 25, 2023
405ee47
add bool List.Contains(TValue value, int upperBound)
nam20485 Aug 25, 2023
4f85cde
minor changes
nam20485 Aug 25, 2023
7df6318
add ToStack() and ToQueue() to IDsCollection
nam20485 Aug 25, 2023
715c8fb
remvoe unused IsReadOnly property
nam20485 Aug 25, 2023
9a80ddf
make Stack an IDsCollection
nam20485 Aug 25, 2023
f417027
remove ArgumentNullException in ctor() and rely on AddRange() to thr…
nam20485 Aug 25, 2023
ee88a61
make Queue an IDsCollection
nam20485 Aug 25, 2023
57cb289
move RandomIntSequence into Utils project
nam20485 Aug 25, 2023
a534ee9
add folders for organization
nam20485 Aug 25, 2023
3dc6691
add asserts
nam20485 Aug 25, 2023
388fb1d
rename test
nam20485 Aug 25, 2023
a6e0e1e
remove some commented out code
nam20485 Aug 25, 2023
5fbf459
add using
nam20485 Aug 25, 2023
1782e21
add ISort interface
nam20485 Aug 25, 2023
c809ac0
add Operations class for different IDsCollection interface method/ope…
nam20485 Aug 25, 2023
7e8b37f
rename
nam20485 Aug 25, 2023
6229d2c
add Test_IdsCollectionRandomOperations for random "stress" testing
nam20485 Aug 25, 2023
8e41bdf
fix List.GetEnumerator to only return number of items actually in the…
nam20485 Aug 25, 2023
b28cd0d
comment about "cast" operator overloads
nam20485 Aug 25, 2023
74b9e6e
add ToMinHeap()
nam20485 Aug 25, 2023
fe3de58
add the rest of the ToX() extensions
nam20485 Aug 25, 2023
96e4306
add more operation types
nam20485 Aug 25, 2023
0c9662c
implement more Operation.Types for random test method
nam20485 Aug 25, 2023
21a34c4
add ToString operation
nam20485 Aug 25, 2023
36b2a32
add more random operations, increase iteration count to 10,000
nam20485 Aug 25, 2023
b32ec7d
add MinHeap and Queue
nam20485 Aug 25, 2023
34d5d28
set TestDataCount = 10 and MaxValue to int.MaxValue
nam20485 Aug 25, 2023
5545ec9
Create add dotnet build and test workflow
nam20485 Aug 25, 2023
f9e4bd7
remove Console.WriteLine()'s in tests
nam20485 Aug 25, 2023
f0ad57e
Merge pull request #1 from nam20485/feature/add-dotnet-build-and-test…
nam20485 Aug 25, 2023
462693f
Merge branch 'development' of github.com:nam20485/Library into develo…
nam20485 Aug 25, 2023
afd953e
add VS Code workspace
nam20485 Aug 25, 2023
3b8b5b1
add pack and push NuGet package workflow
nam20485 Aug 25, 2023
0a387cf
build solution before packing
nam20485 Aug 25, 2023
d787e44
fix workflow
nam20485 Aug 25, 2023
a625b52
fix workflow
nam20485 Aug 25, 2023
7b26950
add pakcahes:write permission
nam20485 Aug 25, 2023
2dc4228
disable automatically packing a package on build since the workflow m…
nam20485 Aug 25, 2023
3253f39
make Contains respect collections' count
nam20485 Aug 25, 2023
c9237d6
fix Stack.GetEnumerator() enumerating infinitely
nam20485 Aug 25, 2023
9a4cbbc
add Stack back
nam20485 Aug 25, 2023
244483a
changes
nam20485 Aug 25, 2023
83a4863
include Version parameter when running dotnet commands to version the…
nam20485 Aug 26, 2023
ba70fe8
build $VERSION env var and use it for the $Version dotnet parameter
nam20485 Aug 26, 2023
5cd3bf9
add '--no-build --no-restore' to pack command
nam20485 Aug 26, 2023
d8b4f6d
remove comment
nam20485 Aug 26, 2023
c9c1342
move $VERSION env var to global workflow scope so its not repeated in…
nam20485 Aug 26, 2023
b340a01
disable generating package on project build
nam20485 Aug 26, 2023
12ce63e
add folder for Sets classes
nam20485 Aug 26, 2023
736b11d
add ToMinHeap() to interface
nam20485 Aug 26, 2023
72ac147
add the rest of the collections to the random operations test
nam20485 Aug 26, 2023
8448471
rename to minHeap for clarity
nam20485 Aug 26, 2023
97c0049
add TValue Remove() method to IDsCollection interface
nam20485 Aug 26, 2023
95eb48d
move PriorityQueue .Peek() and .Remove() up into base class Heap
nam20485 Aug 26, 2023
b9aa1e7
add and remove some comments
nam20485 Aug 26, 2023
5eb1427
fix some exceptions
nam20485 Aug 26, 2023
1fcad9a
using
nam20485 Aug 26, 2023
1528915
make MakeList generic
nam20485 Aug 26, 2023
915c680
add more collection types to MakeIDsCollections
nam20485 Aug 26, 2023
e0a36a9
make Operations class generic and create specilaized IDsOperations in…
nam20485 Aug 26, 2023
1507a5f
add SortType to Sorting namespace
nam20485 Aug 26, 2023
4ee20a2
move HeapSort into its own class
nam20485 Aug 26, 2023
65af264
fix AddRange()
nam20485 Aug 27, 2023
520023a
use smaller values in the random int[]s
nam20485 Aug 27, 2023
f83b1b2
test new Count after AddRange in random operations test
nam20485 Aug 27, 2023
3d789de
add tests for List's AddRange and RemoveLast
nam20485 Aug 27, 2023
0e01183
implement Tree<TValue>.Node
nam20485 Aug 27, 2023
c11d9fc
rename
nam20485 Aug 27, 2023
0a18405
add extension for swwapping values in T[]
nam20485 Aug 27, 2023
8be7fc4
minor change
nam20485 Aug 27, 2023
94c9961
implementation
nam20485 Aug 27, 2023
fe3fd52
remove unimplemented collections
nam20485 Aug 27, 2023
3f778e8
put an empty space in between brackets when printing empty list
nam20485 Aug 28, 2023
72b7fc0
comment out HashSet
nam20485 Aug 28, 2023
1280a39
add TestCircularBuffer()
nam20485 Aug 28, 2023
948025c
comment
nam20485 Aug 28, 2023
33660e0
more incomplete implementation of CircularBuffer
nam20485 Aug 29, 2023
e0d994b
add MultiValueDictionary class
nam20485 Aug 29, 2023
e12b206
add TestMultiValueDictionary()
nam20485 Aug 29, 2023
b476bb3
rename extensions class
nam20485 Aug 29, 2023
50fdc7a
minor refactor to reduce duplication
nam20485 Aug 29, 2023
5e81387
add recursive Array.Reverse extension
nam20485 Aug 29, 2023
4a57d78
add Remove(TKey, TValue) method
nam20485 Aug 29, 2023
6a01641
add set operation extensions
nam20485 Aug 29, 2023
271366f
add empty tests class for MVD
nam20485 Aug 29, 2023
58caeed
add T[].ReverseCopy() extensions
nam20485 Aug 30, 2023
83dc318
changes
nam20485 Aug 30, 2023
aee0ef5
fix comment
nam20485 Aug 30, 2023
e747b3f
add Set collection
nam20485 Sep 7, 2023
c036c9b
add TKey is notnull type constraint
nam20485 Sep 7, 2023
53fea18
add collection ctor
nam20485 Sep 7, 2023
2208a59
add some comments/TODOs
nam20485 Sep 7, 2023
93d4c0d
add initial skeleton of KeyValuePairList<K, V> class
nam20485 Sep 7, 2023
2c3a43c
add a TODO
nam20485 Sep 7, 2023
909ac27
remove notnull generic type constraint from the MVD interface and app…
nam20485 Sep 7, 2023
e45fd27
use a Dictionary<TValue, TValue> for the backing collection in Set to…
nam20485 Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/dotnet-publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Pack NuGet package and push to nam20485's package registry
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry

name: Pack and Publish .NET

on:
push:
branches: [ "master", "development" ]

env:
VERSION: ${{ vars.VERSION_PREFIX }}.${{ github.run_number }}

jobs:
pack-and-push:

runs-on: ubuntu-22.04
permissions:
packages: write
steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.400

- name: Build
run: dotnet build DataStructures --configuration Release /p:Version=${{ env.VERSION }}

- name: Pack NuGet Package
run: dotnet pack DataStructures --include-symbols --configuration Release --no-build --no-restore /p:Version=${{ env.VERSION }}

- name: Add NuGet Source
run: |
dotnet nuget add source --username nam20485 --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/nam20485/index.json"

- name: Push Package
run: |
dotnet nuget push "DataStructures/bin/Release/DataStructures.${{ env.VERSION }}.nupkg" --source "github"
dotnet nuget push "DataStructures/bin/Release/DataStructures.${{ env.VERSION }}.snupkg" --source "github"


28 changes: 28 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build and Test .NET

on:
push:
branches: [ "development" ]
pull_request:
branches: [ "master", "development" ]

jobs:
build-and-test:

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.400
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
19 changes: 19 additions & 0 deletions DataStructures/BinarySearchTree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library.DataStructures
{
public class BinarySearchTree<TValue> : Tree<TValue>
{
//public class BinaryNode : Node
//{
// //protected BinaryNode(Node parent, TValue value) : base(parent, value, )
// //{
// //}
//}

}
}
224 changes: 224 additions & 0 deletions DataStructures/CircularBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library.DataStructures
{
public class CircularBuffer<TValue> : DsCollectionBase<TValue>//, ICollection<TValue>
{
private readonly TValue[] _items;

private int _readIndex; // _head
private int _writeIndex; // _tail

//private int _head;
//private int _tail;
private bool _full;

public int Capacity => _items.Length;

public override int Count
{
get
{
if (_full)
{
return Capacity;
}
else
{
if (_readIndex >= _writeIndex)
{
return _readIndex - _writeIndex;
}
else
{
return Capacity + _readIndex - _writeIndex;
}
}

//size_t size = max_size_;

//if (!full_)
//{
// if (head_ >= tail_)
// {
// size = head_ - tail_;
// }
// else
// {
// size = max_size_ + head_ - tail_;
// }
//}

//return size;
}
}

public CircularBuffer(int capacity)
{
_items = new TValue[capacity];
_readIndex = 0;
_writeIndex = 0;
_full = false;
}

public CircularBuffer(IEnumerable<TValue> collection)
: this(collection.Count())
{
AddRange(collection);
}

public override void Add(TValue item)
{
AddLast(item);
}

public void AddLast(TValue item)
{
var overWroteReadIndex = false;
if (_writeIndex == _readIndex)
{
overWroteReadIndex = true;
}

_items[_writeIndex] = item;
Increment(ref _writeIndex);

if (overWroteReadIndex)
{
// we just overwrote the oldest item, increment the readIndex;
Increment(ref _readIndex);
}
}

public override bool Contains(TValue item)
{
return IndexOf(item) != -1;
}

public int IndexOf(TValue item)
{
var index = _readIndex;
while (index <= _writeIndex)
{
if (Equals(_items[index], item))
{
return index;
}
Increment(ref index);
}
return -1; ;
}

public override void Clear()
{
_writeIndex = 0;
_readIndex = 0;
Array.Clear(_items);
}

private void Increment(ref int index)
{
index++;
if (index == Capacity)
{
index = 0;
}
}

private void Decrement(ref int index)
{
index--;
if (index == -1)
{
index = Capacity - 1;
}
}

public override TValue Remove()
{
return RemoveFirst();
}

public void Enqueue(TValue value)
{
AddLast(value);
}

public TValue Dequeue()
{
return RemoveFirst();
}

private TValue RemoveFirst()
{
if (_writeIndex == _readIndex)
{
throw new InvalidOperationException("Cannot remove from empty buffer.");
}
else
{
var item = Peek();
Increment(ref _readIndex);
return item;
}
}

public TValue Peek()
{
if (_writeIndex == _readIndex)
{
throw new InvalidOperationException("Buffer is empty.");
}
return _items[_readIndex];
}

public override IEnumerator<TValue> GetEnumerator()
{
throw new NotImplementedException();
}

public override IDsCollection<TValue> CopyOf()
{
throw new NotImplementedException();
}

protected override string GetStringRepresentation()
{
var sb = new StringBuilder();
sb.Append(ToList());
sb.Append(Environment.NewLine);

if (_readIndex < _writeIndex)
{
sb.Append(new string(' ', _readIndex*3+1));
sb.Append('r');
sb.Append(new string(' ', (_writeIndex - _readIndex) * 3));
sb.Append('w');

}
else if (_writeIndex == _readIndex)
{
sb.Append(new string(' ', _readIndex * 3+1));
sb.Append("rw");
}
else
{
sb.Append(new string(' ', _writeIndex * 3+1));
sb.Append('r');
sb.Append(new string(' ', (_readIndex - _writeIndex) * 3));
sb.Append('w');
}
return sb.ToString();
}

protected override void CopyOnlyItemsTo(TValue[] array, int arrayIndex = 0)
{

}
}
}
7 changes: 0 additions & 7 deletions DataStructures/Class1.cs

This file was deleted.

27 changes: 26 additions & 1 deletion DataStructures/DataStructures.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Library.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<RepositoryUrl>https://github.com/nam20485/Library</RepositoryUrl>
<PackageProjectUrl>https://github.com/nam20485/Library</PackageProjectUrl>
<Authors>nam20485</Authors>
<Company>nam20485.com</Company>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>symbols.nupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;CS1591</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Utils\Utils.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Collections\" />
<Folder Include="Sets\" />
</ItemGroup>

</Project>
Loading
Loading