-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a0f759c
Showing
41 changed files
with
5,475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: .NET 6 CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET SDK | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 6.0.300 | ||
- name: Build | ||
run: dotnet build --configuration Release | ||
- name: Test | ||
run: dotnet test --configuration Release --no-build --logger "console;verbosity=detailed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/.vs/ | ||
/*/bin/ | ||
/*/obj/ | ||
/Collection/dcx/ | ||
/Collection.Test/TestResults/ | ||
/Coverlet-Html/ | ||
/Collection/html/ | ||
/Collection/Properties/ | ||
/Collection.Test/Properties/ | ||
*.csproj.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright (c) 2022 Maroontress Fast Software. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the | ||
distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS *AS IS* AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS | ||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[*.cs] | ||
|
||
# SA1600: Elements should be documented | ||
dotnet_diagnostic.SA1600.severity = none | ||
|
||
# SA1101: Prefix local calls with this | ||
dotnet_diagnostic.SA1101.severity = none | ||
|
||
# SA1633: File should have header | ||
dotnet_diagnostic.SA1633.severity = none | ||
|
||
# SA1513: Closing brace should be followed by blank line | ||
dotnet_diagnostic.SA1513.severity = none | ||
|
||
# SA0001: XML comment analysis disabled | ||
dotnet_diagnostic.SA0001.severity = none | ||
|
||
# SA1002: Semicolons should be spaced correctly | ||
dotnet_diagnostic.SA1002.severity = none | ||
|
||
# SA1122: Use string.Empty for empty strings | ||
dotnet_diagnostic.SA1122.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="StyleChecker" Version="1.0.27" PrivateAssets="all" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Collection\Collection.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
213 changes: 213 additions & 0 deletions
213
Collection.Test/Maroontress/Collection/SimpleLinkedHashSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
namespace Maroontress.Collection; | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
public sealed class SimpleLinkedHashSet<T> : ISet<T> | ||
where T : notnull | ||
{ | ||
private Func<ISet<T>> keySet; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SimpleLinkedHashSet{T}"/> | ||
/// class. | ||
/// </summary> | ||
/// <param name="initialCapacity"> | ||
/// The initial capacity. | ||
/// </param> | ||
public SimpleLinkedHashSet(int initialCapacity) | ||
{ | ||
Map = new(initialCapacity); | ||
NewKeySet = () => | ||
{ | ||
var set = new HashSet<T>(Map.Keys); | ||
keySet = () => set; | ||
return set; | ||
}; | ||
keySet = NewKeySet; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public int Count => List.Count; | ||
|
||
/// <inheritdoc/> | ||
public bool IsReadOnly => false; | ||
|
||
private LinkedList<T> List { get; } = new(); | ||
|
||
private Dictionary<T, LinkedListNode<T>> Map { get; set; } | ||
|
||
private Func<ISet<T>> NewKeySet { get; } | ||
|
||
/// <inheritdoc/> | ||
public bool Add(T item) | ||
{ | ||
if (Map.ContainsKey(item)) | ||
{ | ||
return false; | ||
} | ||
var listNode = List.AddLast(item); | ||
Map[item] = listNode; | ||
keySet = NewKeySet; | ||
return true; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Clear() | ||
{ | ||
Map.Clear(); | ||
List.Clear(); | ||
keySet = NewKeySet; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool Contains(T item) => Map.ContainsKey(item); | ||
|
||
/// <inheritdoc/> | ||
public void CopyTo(T[] array, int arrayIndex) | ||
{ | ||
if (array is null) | ||
{ | ||
throw new ArgumentNullException(nameof(array)); | ||
} | ||
if (arrayIndex < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameof(arrayIndex), | ||
$"Illegal array index: {arrayIndex}"); | ||
} | ||
if (arrayIndex > array.Length | ||
|| array.Length < Count | ||
|| arrayIndex > array.Length - Count) | ||
{ | ||
throw new ArgumentException( | ||
"Too small array length"); | ||
} | ||
List.CopyTo(array, arrayIndex); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void ExceptWith(IEnumerable<T> other) | ||
{ | ||
if (other is null) | ||
{ | ||
throw new ArgumentNullException(nameof(other)); | ||
} | ||
foreach (var e in other) | ||
{ | ||
Remove(e); | ||
} | ||
keySet = NewKeySet; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IEnumerator<T> GetEnumerator() => List.GetEnumerator(); | ||
|
||
/// <inheritdoc/> | ||
public void IntersectWith(IEnumerable<T> other) | ||
{ | ||
if (other is null) | ||
{ | ||
throw new ArgumentNullException(nameof(other)); | ||
} | ||
var newMap = new Dictionary<T, LinkedListNode<T>>(); | ||
foreach (var e in other) | ||
{ | ||
if (!Map.Remove(e, out var node)) | ||
{ | ||
continue; | ||
} | ||
newMap[e] = node; | ||
} | ||
foreach (var v in Map.Values) | ||
{ | ||
List.Remove(v); | ||
} | ||
Map = newMap; | ||
keySet = NewKeySet; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool IsProperSubsetOf(IEnumerable<T> other) | ||
=> keySet().IsProperSubsetOf(other); | ||
|
||
/// <inheritdoc/> | ||
public bool IsProperSupersetOf(IEnumerable<T> other) | ||
=> keySet().IsProperSupersetOf(other); | ||
|
||
/// <inheritdoc/> | ||
public bool IsSubsetOf(IEnumerable<T> other) | ||
=> keySet().IsSubsetOf(other); | ||
|
||
/// <inheritdoc/> | ||
public bool IsSupersetOf(IEnumerable<T> other) | ||
=> keySet().IsSupersetOf(other); | ||
|
||
/// <inheritdoc/> | ||
public bool Overlaps(IEnumerable<T> other) | ||
=> keySet().Overlaps(other); | ||
|
||
/// <inheritdoc/> | ||
public bool Remove(T item) | ||
{ | ||
if (!Map.Remove(item, out var listNode)) | ||
{ | ||
return false; | ||
} | ||
List.Remove(listNode); | ||
keySet = NewKeySet; | ||
return true; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool SetEquals(IEnumerable<T> other) | ||
=> keySet().SetEquals(other); | ||
|
||
/// <inheritdoc/> | ||
public void SymmetricExceptWith(IEnumerable<T> other) | ||
{ | ||
if (other is null) | ||
{ | ||
throw new ArgumentNullException(nameof(other)); | ||
} | ||
if (ReferenceEquals(other, this)) | ||
{ | ||
Clear(); | ||
return; | ||
} | ||
var set = new HashSet<T>(); | ||
foreach (var e in other) | ||
{ | ||
if (!set.Add(e)) | ||
{ | ||
continue; | ||
} | ||
if (!Remove(e)) | ||
{ | ||
Add(e); | ||
} | ||
} | ||
keySet = NewKeySet; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void UnionWith(IEnumerable<T> other) | ||
{ | ||
if (other is null) | ||
{ | ||
throw new ArgumentNullException(nameof(other)); | ||
} | ||
foreach (var e in other) | ||
{ | ||
Add(e); | ||
} | ||
keySet = NewKeySet; | ||
} | ||
|
||
/// <inheritdoc/> | ||
void ICollection<T>.Add(T item) => Add(item); | ||
|
||
/// <inheritdoc/> | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} |
Oops, something went wrong.