Skip to content

Commit b98ef8e

Browse files
author
Oren (electricessence)
committed
Updated to 2.3.0
1 parent 2d22932 commit b98ef8e

File tree

3 files changed

+161
-171
lines changed

3 files changed

+161
-171
lines changed

DeferredHashSet.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
namespace Open.RandomizationExtensions
4+
{
5+
class DeferredHashSet<T> : HashSet<T>, IDisposable
6+
{
7+
public DeferredHashSet(IEnumerator<T> source)
8+
{
9+
Source = source ?? throw new ArgumentNullException(nameof(source));
10+
}
11+
12+
public DeferredHashSet(IEnumerable<T> source)
13+
: this((source ?? throw new ArgumentNullException(nameof(source))).GetEnumerator())
14+
{
15+
16+
}
17+
18+
private readonly IEnumerator<T> Source;
19+
20+
public new bool Contains(T item)
21+
{
22+
if (base.Contains(item))
23+
return true;
24+
25+
while(Source.MoveNext())
26+
{
27+
var i = Source.Current;
28+
Add(i);
29+
if (item is null ? i is null : item.Equals(i))
30+
return true;
31+
}
32+
33+
return false;
34+
}
35+
36+
public void Dispose()
37+
{
38+
Source.Dispose();
39+
this.Clear();
40+
}
41+
}
42+
}

Open.RandomizationExtensions.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ Part of the "Open" set of libraries.</Description>
1414
<RepositoryUrl>https://github.com/electricessence/Open.RandomizationExtensions</RepositoryUrl>
1515
<RepositoryType>Git</RepositoryType>
1616
<PackageTags>random select</PackageTags>
17-
<Version>2.0.0</Version>
17+
<Version>2.3.0</Version>
18+
<LangVersion>latest</LangVersion>
19+
<Nullable>enable</Nullable>
1820
</PropertyGroup>
1921

2022
<ItemGroup>
21-
<PackageReference Include="Open.MemoryExtensions" Version="2.1.0" />
23+
<PackageReference Include="Open.MemoryExtensions" Version="2.3.0" />
2224
</ItemGroup>
2325

2426
</Project>

0 commit comments

Comments
 (0)