You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/MemoryPools/Collections/Linq/Union.Enumerable.cs

70 lines
2.0 KiB

using System.Collections.Generic;
using MemoryPools.Collections.Specialized;
namespace MemoryPools.Collections.Linq
{
internal class UnionExprEnumerable<T> : IPoolingEnumerable<T>
{
private int _count;
private PoolingDictionary<T, int> _src;
public UnionExprEnumerable<T> Init(PoolingDictionary<T, int> src)
{
_src = src;
_count = 0;
return this;
}
public IPoolingEnumerator<T> GetEnumerator()
{
_count++;
return Pool<UnionExprEnumerator>.Get().Init(this, _src.GetEnumerator());
}
private void Dispose()
{
if(_count == 0) return;
_count--;
if (_count == 0)
{
_src?.Dispose();
7 months ago
Pool<PoolingDictionary<T, int>>.Return(_src!);
_src = default!;
7 months ago
Pool<UnionExprEnumerable<T>>.Return(this!);
}
}
internal class UnionExprEnumerator : IPoolingEnumerator<T>
{
private UnionExprEnumerable<T> _parent;
private IPoolingEnumerator<KeyValuePair<T, int>> _src;
public UnionExprEnumerator Init(UnionExprEnumerable<T> parent, IPoolingEnumerator<KeyValuePair<T, int>> src)
{
_src = src;
_parent = parent;
return this;
}
public bool MoveNext() => _src.MoveNext();
public void Reset() => _src.Reset();
7 months ago
object IPoolingEnumerator.Current => Current!;
public T Current => _src.Current.Key;
public void Dispose()
{
_src?.Dispose();
7 months ago
_src = null!;
_parent?.Dispose();
7 months ago
_parent = default!;
Pool<UnionExprEnumerator>.Return(this);
}
}
IPoolingEnumerator IPoolingEnumerable.GetEnumerator() => GetEnumerator();
}
}

Powered by TurnKey Linux.