Skip to content

Commit 5032808

Browse files
author
Ahmad Alhour
committed
Modernize to .NET 10, upgrade CI, fix ChainedHashTable bug
1 parent 504140e commit 5032808

11 files changed

Lines changed: 158 additions & 57 deletions

File tree

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2
2+
updates:
3+
# Keep NuGet packages up to date
4+
- package-ecosystem: "nuget"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
open-pull-requests-limit: 5
9+
labels:
10+
- "dependencies"
11+
- "nuget"
12+
13+
# Keep GitHub Actions up to date
14+
- package-ecosystem: "github-actions"
15+
directory: "/"
16+
schedule:
17+
interval: "weekly"
18+
open-pull-requests-limit: 5
19+
labels:
20+
- "dependencies"
21+
- "github-actions"
Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
name: Build and Test
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
48

59
jobs:
610
build:
7-
runs-on: ubuntu-latest
11+
name: Build & Test
12+
runs-on: ${{ matrix.os }}
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest, windows-latest, macos-latest]
18+
819
steps:
9-
- uses: actions/checkout@v1
10-
- name: Setup .NET Core
11-
uses: actions/setup-dotnet@v1
12-
with:
13-
dotnet-version: 2.2.108
14-
- name: Build with .NET Core
15-
run: dotnet build --configuration Release
16-
test:
17-
runs-on: ubuntu-latest
18-
needs: build
19-
steps:
20-
- uses: actions/checkout@v1
21-
- name: Run Tests
22-
run: dotnet test
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Setup .NET
24+
uses: actions/setup-dotnet@v4
25+
with:
26+
dotnet-version: '10.0.x'
27+
28+
- name: Cache NuGet packages
29+
uses: actions/cache@v4
30+
with:
31+
path: ~/.nuget/packages
32+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
33+
restore-keys: |
34+
${{ runner.os }}-nuget-
35+
36+
- name: Restore dependencies
37+
run: dotnet restore
38+
39+
- name: Build
40+
run: dotnet build --configuration Release --no-restore
41+
42+
- name: Test
43+
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage"
44+
45+
- name: Upload coverage reports
46+
uses: codecov/codecov-action@v4
47+
if: matrix.os == 'ubuntu-latest'
48+
with:
49+
token: ${{ secrets.CODECOV_TOKEN }}
50+
fail_ci_if_error: false

.github/workflows/greetings.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
name: Greetings
22

3-
on: [pull_request, issues]
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
issues:
7+
types: [opened]
8+
9+
permissions:
10+
issues: write
11+
pull-requests: write
412

513
jobs:
614
greeting:
715
runs-on: ubuntu-latest
816
steps:
9-
- uses: actions/first-interaction@v1
10-
with:
11-
repo-token: ${{ secrets.GITHUB_TOKEN }}
12-
issue-message: 'Thanks for supporting the development of C# Algorithms with your first issue! We look forward to handling it.'
13-
pr-message: 'Congratulations! You are officially a C# Algorithms contributor! :tada:'
17+
- name: Greet new contributors
18+
uses: actions/first-interaction@v1
19+
with:
20+
repo-token: ${{ secrets.GITHUB_TOKEN }}
21+
issue-message: |
22+
👋 Thanks for opening your first issue! We appreciate your interest in C# Algorithms.
23+
24+
We'll review it as soon as possible. In the meantime, feel free to check out our [Contributing Guidelines](https://github.com/aalhour/C-Sharp-Algorithms/blob/master/.github/CONTRIBUTING.md).
25+
pr-message: |
26+
🎉 Congratulations on your first pull request to C# Algorithms!
27+
28+
Thank you for contributing! We'll review your changes soon. Make sure all CI checks pass.

Algorithms/Algorithms.csproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
8+
<!-- Package metadata -->
9+
<PackageId>C-Sharp-Algorithms</PackageId>
10+
<Description>A library of standard algorithms implemented in C#</Description>
11+
<Authors>Ahmad Alhour</Authors>
12+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13+
<RepositoryUrl>https://github.com/aalhour/C-Sharp-Algorithms</RepositoryUrl>
14+
<PackageTags>algorithms;data-structures;csharp</PackageTags>
415
</PropertyGroup>
516

617
<ItemGroup>
718
<ProjectReference Include="..\DataStructures\DataStructures.csproj" />
819
</ItemGroup>
9-
</Project>
20+
</Project>
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
8+
<!-- Package metadata -->
9+
<PackageId>C-Sharp-Algorithms.DataStructures</PackageId>
10+
<Description>A library of standard data structures implemented in C#</Description>
11+
<Authors>Ahmad Alhour</Authors>
12+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13+
<RepositoryUrl>https://github.com/aalhour/C-Sharp-Algorithms</RepositoryUrl>
14+
<PackageTags>algorithms;data-structures;csharp</PackageTags>
415
</PropertyGroup>
5-
16+
617
<ItemGroup>
718
<EmbeddedResource Include="Data\PrimesDocument_10K.csv">
819
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
920
</EmbeddedResource>
1021
</ItemGroup>
11-
</Project>
22+
</Project>

DataStructures/Dictionaries/ChainedHashTable.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -583,30 +583,21 @@ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
583583
int hashTableIndex = 0;
584584
var currentChainNode = new DLinkedListNode<TKey, TValue>();
585585

586-
while (true)
586+
while (hashTableIndex < _hashTableStore.Length && i < array.Length)
587587
{
588-
KeyValuePair<TKey, TValue> pair;
589-
590-
if (i >= array.Length)
591-
break;
592-
593588
if (_hashTableStore[hashTableIndex] != null)
594589
{
595590
currentChainNode = _hashTableStore[hashTableIndex].Head;
596591
while (currentChainNode != null && i < array.Length)
597592
{
598-
pair = new KeyValuePair<TKey, TValue>(currentChainNode.Key, currentChainNode.Value);
593+
var pair = new KeyValuePair<TKey, TValue>(currentChainNode.Key, currentChainNode.Value);
599594
array[i] = pair;
600595
i++;
601-
hashTableIndex++;
602-
603596
currentChainNode = currentChainNode.Next;
604597
}
605598
}
606-
else
607-
{
608-
hashTableIndex++;
609-
}
599+
600+
hashTableIndex++;
610601
}
611602
}
612603

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ This is a C#.NET solution-project, and it contains three subprojects:
5353

5454
#### Requirements:
5555

56-
1. .NET Core >= 2.0
57-
2. XUnit
56+
* [.NET 10.0 SDK](https://dotnet.microsoft.com/download) (or later)
57+
58+
#### Building & Testing:
59+
60+
```bash
61+
# Restore packages
62+
dotnet restore
63+
64+
# Build the solution
65+
dotnet build
66+
67+
# Run all tests
68+
dotnet test
69+
```
5870

5971
#### A Note to Contributors:
6072

UnitTest/DataStructuresTests/QueueTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class QueueTest
88
[Fact]
99
public static void DoTest()
1010
{
11-
var queue = new Queue<string>();
11+
var queue = new DataStructures.Lists.Queue<string>();
1212
queue.Enqueue("aaa");
1313
queue.Enqueue("bbb");
1414
queue.Enqueue("ccc");

UnitTest/DataStructuresTests/StackTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class StackTest
99
public static void DoTest()
1010
{
1111
int top;
12-
Stack<int> stack = new Stack<int>();
12+
var stack = new DataStructures.Lists.Stack<int>();
1313

1414
stack.Push(1);
1515
stack.Push(2);

UnitTest/UnitTest.csproj

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<IsTestProject>true</IsTestProject>
49
</PropertyGroup>
510

611
<ItemGroup>
7-
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
9-
<PackageReference Include="xunit" Version="2.4.1" />
10-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
13+
<PackageReference Include="xunit" Version="2.9.2" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="6.0.2">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
</PackageReference>
1122
</ItemGroup>
1223

1324
<ItemGroup>
1425
<ProjectReference Include="..\Algorithms\Algorithms.csproj" />
15-
<!--<ProjectReference Include="..\DataStructures\DataStructures.csproj" />-->
16-
</ItemGroup>
17-
18-
<ItemGroup>
19-
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
2026
</ItemGroup>
2127
</Project>

0 commit comments

Comments
 (0)