Arrange code structure. Introduce dynamic scheduler and multi leader.
This commit is contained in:
@@ -32,7 +32,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace StgSharp.Commom.Collections
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond>
|
||||
{
|
||||
|
||||
+43
-22
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="CachePool"
|
||||
// file="CapacityFixedBag"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
@@ -25,36 +25,57 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Commom.Collections
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
/*
|
||||
public interface IPoolItem<TSignature>
|
||||
public sealed class CapacityFixedBag<T> : IEnumerable<T>
|
||||
{
|
||||
|
||||
public int ID
|
||||
private readonly T[] _buffer;
|
||||
|
||||
public CapacityFixedBag(int capacity)
|
||||
{
|
||||
get;
|
||||
init;
|
||||
_buffer = new T[capacity];
|
||||
}
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public int Capacity => _buffer.Length;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (Count >= _buffer.Length) {
|
||||
throw new InvalidOperationException("Bag capacity exceeded.");
|
||||
}
|
||||
_buffer[Count] = item;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Count; i++) {
|
||||
yield return _buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(T item)
|
||||
{
|
||||
int index = Array.IndexOf(_buffer, item, 0, Count);
|
||||
if (index >= 0)
|
||||
{
|
||||
_buffer[index] = _buffer[Count - 1];
|
||||
_buffer[Count - 1] = default!;
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class CacheIndexPool<TSignature, TItem> : IEnumerable<TItem>
|
||||
where TItem: IPoolItem<TSignature>
|
||||
{
|
||||
|
||||
public CacheIndexPool(
|
||||
Func<TSignature>
|
||||
) { }
|
||||
|
||||
}
|
||||
/**/
|
||||
}
|
||||
@@ -28,11 +28,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Commom.Collections
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public static class CapacityFixedListBuilder
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Commom.Collections
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
[CollectionBuilder(typeof(CapacityFixedStackBuilder), nameof(CapacityFixedStackBuilder.Create))]
|
||||
public class CapacityFixedStack<T> : IEnumerable<T>
|
||||
@@ -72,13 +72,7 @@ namespace StgSharp.Commom.Collections
|
||||
|
||||
public T Peek()
|
||||
{
|
||||
if (_index >= 0)
|
||||
{
|
||||
return _values[_index];
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
return _index >= 0 ? _values[_index] : throw new InvalidOperationException("Stack is empty.");
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
@@ -86,6 +80,7 @@ namespace StgSharp.Commom.Collections
|
||||
if (_index >= 0)
|
||||
{
|
||||
T item = _values[_index];
|
||||
_index--;
|
||||
return item;
|
||||
} else
|
||||
{
|
||||
@@ -95,13 +90,9 @@ namespace StgSharp.Commom.Collections
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
if (_index < _values.Length - 1)
|
||||
{
|
||||
_values[++_index] = item;
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
_values[++_index] = _index < _values.Length - 1 ?
|
||||
item :
|
||||
throw new InvalidOperationException("Stack is full.");
|
||||
}
|
||||
|
||||
public void PushRange(ReadOnlySpan<T> span)
|
||||
@@ -115,6 +106,21 @@ namespace StgSharp.Commom.Collections
|
||||
_index += span.Length;
|
||||
}
|
||||
|
||||
public bool TryPop(out T value)
|
||||
{
|
||||
if (_index >= 0)
|
||||
{
|
||||
T item = _values[_index];
|
||||
_index--;
|
||||
value = item;
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
value = default!;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal Span<T> GetValueLayout()
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Commom.Collections
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user