-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSetView.cs
More file actions
123 lines (107 loc) · 3.33 KB
/
Copy pathStringSetView.cs
File metadata and controls
123 lines (107 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright Subatomix Research Inc.
// SPDX-License-Identifier: MIT
using System.Collections;
namespace DependencyQueue;
/// <summary>
/// A read-only view over an exclusively-locked set of strings.
/// </summary>
public readonly struct StringSetView : IReadOnlyCollection<string> //, ISet<string>
{
private readonly SortedSet<string> _set;
private readonly AsyncMonitor.Lock _lock;
internal StringSetView(SortedSet<string> set, AsyncMonitor.Lock @lock)
{
_set = set;
_lock = @lock;
}
/// <summary>
/// Gets the underlying set.
/// </summary>
internal SortedSet<string> Set => _set;
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public int Count
{
get
{
_lock.RequireNotDisposed();
return _set.Count;
}
}
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public Enumerator GetEnumerator()
{
_lock.RequireNotDisposed();
return new(_set.GetEnumerator(), _lock);
}
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
IEnumerator<string> IEnumerable<string>.GetEnumerator()
=> GetEnumerator();
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
/// <summary>
/// An enumerator over an exclusively-locked set of strings.
/// </summary>
public struct Enumerator : IEnumerator<string>
{
private SortedSet<string>.Enumerator _enumerator;
private readonly AsyncMonitor.Lock _lock;
internal Enumerator(SortedSet<string>.Enumerator enumerator, AsyncMonitor.Lock @lock)
{
_enumerator = enumerator;
_lock = @lock;
}
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public string Current
{
get
{
_lock.RequireNotDisposed();
return _enumerator.Current;
}
}
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
object? IEnumerator.Current => Current;
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public bool MoveNext()
{
_lock.RequireNotDisposed();
return _enumerator.MoveNext();
}
/// <inheritdoc/>
/// <exception cref="ObjectDisposedException">
/// The underlying lock has been released.
/// </exception>
public void Reset()
{
_lock.RequireNotDisposed();
ViewHelpers.Reset(ref _enumerator);
}
/// <inheritdoc/>
public void Dispose()
{
_enumerator.Dispose();
}
}
}