diff --git a/FantasyNetTest.sln.DotSettings.user b/FantasyNetTest.sln.DotSettings.user
index bfe1e53..63af743 100644
--- a/FantasyNetTest.sln.DotSettings.user
+++ b/FantasyNetTest.sln.DotSettings.user
@@ -4,6 +4,7 @@
ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
ForceIncluded
ForceIncluded
diff --git a/FantasyNetTest/Config.json b/FantasyNetTest/Config.json
index 6de0053..de1f127 100644
--- a/FantasyNetTest/Config.json
+++ b/FantasyNetTest/Config.json
@@ -1,5 +1,5 @@
{
"Server": "127.0.0.1:20001",
"Heartbeat": 5,
- "ProtocolScriptPath": "D:\\myself\\Games\\Fishing2\\Assets\\Scripts\\Generate\\NetworkProtocol"
+ "ProtocolScriptPath": "D:\\myself\\Fishing2\\Assets\\Scripts\\Generate\\NetworkProtocol"
}
\ No newline at end of file
diff --git a/FantasyNetTest/Fantasy.config b/FantasyNetTest/Fantasy.config
new file mode 100644
index 0000000..18bcc6a
--- /dev/null
+++ b/FantasyNetTest/Fantasy.config
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/FantasyNetTest/Fantasy.xsd b/FantasyNetTest/Fantasy.xsd
new file mode 100644
index 0000000..ecba449
--- /dev/null
+++ b/FantasyNetTest/Fantasy.xsd
@@ -0,0 +1,310 @@
+
+
+
+
+
+
+ Fantasy框架配置文件根元素
+
+
+
+
+
+ 配置表路径设置
+
+
+
+
+ ID生成器配置
+
+
+
+
+ 网络运行时配置
+
+
+
+
+ 会话运行时配置
+
+
+
+
+ 服务器配置
+
+
+
+
+
+
+
+
+
+
+ 配置表文件路径
+
+
+
+
+
+
+
+
+ ID生成器类型:Default(支持最多65535个Scene) 或 World(ID中包含WorldId,支持最多255个Scene,但解决合区ID重复问题)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 机器配置列表
+
+
+
+
+ 进程配置列表
+
+
+
+
+ 世界配置列表
+
+
+
+
+ 场景配置列表
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 机器ID
+
+
+
+
+ 外网IP地址
+
+
+
+
+ 外网绑定IP地址
+
+
+
+
+ 内网绑定IP地址
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 进程ID
+
+
+
+
+ 所属机器ID
+
+
+
+
+ 启动分组
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 数据库类型
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 数据库名称
+
+
+
+
+ 数据库连接字符串
+
+
+
+
+
+
+
+
+ 世界中配置的数据库
+
+
+
+
+
+
+
+ 世界ID
+
+
+
+
+ 世界名称
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 场景ID
+
+
+
+
+ 进程配置ID
+
+
+
+
+ 世界配置ID
+
+
+
+
+ 场景运行模式
+
+
+
+
+
+
+
+
+
+
+
+ 场景类型字符串
+
+
+
+
+ 网络协议类型
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 外网端口
+
+
+
+
+ 内网端口
+
+
+
+
+
+
+
+
+ 服务器内部网络协议
+
+
+
+
+
+
+
+
+
+
+ 消息体最大长度(字节),默认1048560字节(约1.02MB)
+
+
+
+
+
+
+
+
+ Session idle check timeout (in milliseconds)
+
+
+
+
+ Session idle check interval (in milliseconds)
+
+
+
+
+
\ No newline at end of file
diff --git a/FantasyNetTest/FantasyNetTest.csproj b/FantasyNetTest/FantasyNetTest.csproj
index 341df3e..c056915 100644
--- a/FantasyNetTest/FantasyNetTest.csproj
+++ b/FantasyNetTest/FantasyNetTest.csproj
@@ -9,23 +9,26 @@
true
+
+ TRACE;FANTASY_CONSOLE
+
+
+
+ TRACE;FANTASY_CONSOLE
+
+
- Never
+ Always
-
-
-
-
-
+
+
-
-
\ No newline at end of file
diff --git a/FantasyNetTest/Form1.cs b/FantasyNetTest/Form1.cs
index 275b880..4a0ea9b 100644
--- a/FantasyNetTest/Form1.cs
+++ b/FantasyNetTest/Form1.cs
@@ -1,11 +1,13 @@
using System.Globalization;
using System.Reflection;
using System.Text.Json;
-using NBC;
-using NBC.InnerMessage;
-using NBC.Network;
-using NBC.Network.Interface;
-using ProtoBuf;
+using Fantasy;
+using Fantasy.Async;
+using Fantasy.Helper;
+using Fantasy.InnerMessage;
+using Fantasy.Network;
+using Fantasy.Network.Interface;
+using LightProto;
using EventArgs = System.EventArgs;
#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑添加 'required' 修饰符或声明为可以为 null。
diff --git a/FantasyNetTest/LoginTask.cs b/FantasyNetTest/LoginTask.cs
index cedeb08..7d8083e 100644
--- a/FantasyNetTest/LoginTask.cs
+++ b/FantasyNetTest/LoginTask.cs
@@ -1,5 +1,5 @@
-using NBC;
-using NBC.Network;
+using Fantasy.Network;
+
namespace FantasyNetTest;
diff --git a/FantasyNetTest/NBC/Core/Assembly/AssemblyInfo.cs b/FantasyNetTest/NBC/Core/Assembly/AssemblyInfo.cs
deleted file mode 100644
index 7f6c1d0..0000000
--- a/FantasyNetTest/NBC/Core/Assembly/AssemblyInfo.cs
+++ /dev/null
@@ -1,89 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using NBC.DataStructure.Collection;
-
-// ReSharper disable CollectionNeverQueried.Global
-#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
-
-namespace NBC.Assembly
-{
- ///
- /// AssemblyInfo提供有关程序集和类型的信息
- ///
- public sealed class AssemblyInfo
- {
- ///
- /// 唯一标识
- ///
- public readonly long AssemblyIdentity;
- ///
- /// 获取或设置与此程序集相关联的 实例。
- ///
- public System.Reflection.Assembly Assembly { get; private set; }
- ///
- /// 程序集类型集合,获取一个列表,包含从程序集加载的所有类型。
- ///
- public readonly List AssemblyTypeList = new List();
- ///
- /// 程序集类型分组集合,获取一个分组列表,将接口类型映射到实现这些接口的类型。
- ///
- public readonly OneToManyList AssemblyTypeGroupList = new OneToManyList();
-
- ///
- /// 初始化 类的新实例。
- ///
- ///
- public AssemblyInfo(long assemblyIdentity)
- {
- AssemblyIdentity = assemblyIdentity;
- }
-
- ///
- /// 从指定的程序集加载类型信息并进行分类。
- ///
- /// 要加载信息的程序集。
- public void Load(System.Reflection.Assembly assembly)
- {
- Assembly = assembly;
- var assemblyTypes = assembly.GetTypes().ToList();
-
- foreach (var type in assemblyTypes)
- {
- if (type.IsAbstract || type.IsInterface)
- {
- continue;
- }
-
- var interfaces = type.GetInterfaces();
-
- foreach (var interfaceType in interfaces)
- {
- AssemblyTypeGroupList.Add(interfaceType, type);
- }
- }
-
- AssemblyTypeList.AddRange(assemblyTypes);
- }
-
- ///
- /// 重新加载程序集的类型信息。
- ///
- ///
- public void ReLoad(System.Reflection.Assembly assembly)
- {
- Unload();
- Load(assembly);
- }
-
- ///
- /// 卸载程序集的类型信息。
- ///
- public void Unload()
- {
- AssemblyTypeList.Clear();
- AssemblyTypeGroupList.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/Assembly/AssemblySystem.cs b/FantasyNetTest/NBC/Core/Assembly/AssemblySystem.cs
deleted file mode 100644
index 25de737..0000000
--- a/FantasyNetTest/NBC/Core/Assembly/AssemblySystem.cs
+++ /dev/null
@@ -1,286 +0,0 @@
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Security.Cryptography;
-using System.Text;
-using NBC.Async;
-using NBC.Helper;
-
-#pragma warning disable CS8604 // Possible null reference argument.
-#pragma warning disable CS8602 // Dereference of a possibly null reference.
-#pragma warning disable CS8603
-#pragma warning disable CS8618
-namespace NBC.Assembly
-{
- ///
- /// 管理程序集加载和卸载的帮助类。
- ///
- public static class AssemblySystem
- {
-#if FANTASY_WEBGL
- private static readonly List AssemblySystems = new List();
- private static readonly Dictionary AssemblyList = new Dictionary();
-#else
- private static readonly ConcurrentQueue AssemblySystems = new ConcurrentQueue();
- private static readonly ConcurrentDictionary AssemblyList = new ConcurrentDictionary();
-#endif
- ///
- /// 初始化 AssemblySystem。(仅限内部)
- ///
- ///
- internal static async FTask InnerInitialize(params System.Reflection.Assembly[] assemblies)
- {
- await LoadAssembly(typeof(AssemblySystem).Assembly);
- foreach (var assembly in assemblies)
- {
- await LoadAssembly(assembly);
- }
- }
-
- ///
- /// 加载指定的程序集,并触发相应的事件。
- ///
- /// 要加载的程序集。
- /// 如果当前Domain中已经存在同名的Assembly,使用Domain中的程序集。
- public static async FTask LoadAssembly(System.Reflection.Assembly assembly, bool isCurrentDomain = true)
- {
- if (isCurrentDomain)
- {
- var currentDomainAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
- var currentAssembly = currentDomainAssemblies.FirstOrDefault(d => d.GetName().Name == assembly.GetName().Name);
- if (currentAssembly != null)
- {
- assembly = currentAssembly;
- }
- }
-
- var assemblyIdentity = AssemblyIdentity(assembly);
-
- if (AssemblyList.TryGetValue(assemblyIdentity, out var assemblyInfo))
- {
- assemblyInfo.ReLoad(assembly);
- foreach (var assemblySystem in AssemblySystems)
- {
- await assemblySystem.ReLoad(assemblyIdentity);
- }
- }
- else
- {
- assemblyInfo = new AssemblyInfo(assemblyIdentity);
- assemblyInfo.Load(assembly);
- AssemblyList.TryAdd(assemblyIdentity, assemblyInfo);
- foreach (var assemblySystem in AssemblySystems)
- {
- await assemblySystem.Load(assemblyIdentity);
- }
- }
- }
-
- ///
- /// 卸载程序集
- ///
- ///
- public static async FTask UnLoadAssembly(System.Reflection.Assembly assembly)
- {
- var assemblyIdentity = AssemblyIdentity(assembly);
-
- if (!AssemblyList.Remove(assemblyIdentity, out var assemblyInfo))
- {
- return;
- }
-
- assemblyInfo.Unload();
- foreach (var assemblySystem in AssemblySystems)
- {
- await assemblySystem.OnUnLoad(assemblyIdentity);
- }
- }
-
- ///
- /// 将AssemblySystem接口的object注册到程序集管理中心
- ///
- ///
- public static async FTask Register(object obj)
- {
- if (obj is not IAssembly assemblySystem)
- {
- return;
- }
-#if FANTASY_WEBGL
- AssemblySystems.Add(assemblySystem);
-#else
- AssemblySystems.Enqueue(assemblySystem);
-#endif
- foreach (var (assemblyIdentity, _) in AssemblyList)
- {
- await assemblySystem.Load(assemblyIdentity);
- }
- }
-
- ///
- /// 程序集管理中心卸载注册的Load、ReLoad、UnLoad的接口
- ///
- ///
- public static void UnRegister(object obj)
- {
- if (obj is not IAssembly assemblySystem)
- {
- return;
- }
-#if FANTASY_WEBGL
- AssemblySystems.Remove(assemblySystem);
-#else
- var count = AssemblySystems.Count;
-
- for (var i = 0; i < count; i++)
- {
- if (!AssemblySystems.TryDequeue(out var removeAssemblySystem))
- {
- continue;
- }
-
- if (removeAssemblySystem == assemblySystem)
- {
- break;
- }
-
- AssemblySystems.Enqueue(removeAssemblySystem);
- }
-#endif
- }
-
- ///
- /// 获取所有已加载程序集中的所有类型。
- ///
- /// 所有已加载程序集中的类型。
- public static IEnumerable ForEach()
- {
- foreach (var (_, assemblyInfo) in AssemblyList)
- {
- foreach (var type in assemblyInfo.AssemblyTypeList)
- {
- yield return type;
- }
- }
- }
-
- ///
- /// 获取指定程序集中的所有类型。
- ///
- /// 程序集唯一标识。
- /// 指定程序集中的类型。
- public static IEnumerable ForEach(long assemblyIdentity)
- {
- if (!AssemblyList.TryGetValue(assemblyIdentity, out var assemblyInfo))
- {
- yield break;
- }
-
- foreach (var type in assemblyInfo.AssemblyTypeList)
- {
- yield return type;
- }
- }
-
- ///
- /// 获取所有已加载程序集中实现指定类型的所有类型。
- ///
- /// 要查找的基类或接口类型。
- /// 所有已加载程序集中实现指定类型的类型。
- public static IEnumerable ForEach(Type findType)
- {
- foreach (var (_, assemblyInfo) in AssemblyList)
- {
- if (!assemblyInfo.AssemblyTypeGroupList.TryGetValue(findType, out var assemblyLoad))
- {
- continue;
- }
-
- foreach (var type in assemblyLoad)
- {
- yield return type;
- }
- }
- }
-
- ///
- /// 获取指定程序集中实现指定类型的所有类型。
- ///
- /// 程序集唯一标识。
- /// 要查找的基类或接口类型。
- /// 指定程序集中实现指定类型的类型。
- public static IEnumerable ForEach(long assemblyIdentity, Type findType)
- {
- if (!AssemblyList.TryGetValue(assemblyIdentity, out var assemblyInfo))
- {
- yield break;
- }
-
- if (!assemblyInfo.AssemblyTypeGroupList.TryGetValue(findType, out var assemblyLoad))
- {
- yield break;
- }
-
- foreach (var type in assemblyLoad)
- {
- yield return type;
- }
- }
-
- ///
- /// 获取指定程序集的实例。
- ///
- /// 程序集名称。
- /// 指定程序集的实例,如果未加载则返回 null。
- public static System.Reflection.Assembly GetAssembly(long assemblyIdentity)
- {
- return !AssemblyList.TryGetValue(assemblyIdentity, out var assemblyInfo) ? null : assemblyInfo.Assembly;
- }
-
- ///
- /// 获取当前框架注册的Assembly
- ///
- ///
- public static IEnumerable ForEachAssembly
- {
- get
- {
- foreach (var (_, assemblyInfo) in AssemblyList)
- {
- yield return assemblyInfo.Assembly;
- }
- }
- }
-
- ///
- /// 根据Assembly的强命名计算唯一标识。
- ///
- ///
- ///
- private static long AssemblyIdentity(System.Reflection.Assembly assembly)
- {
- return HashCodeHelper.ComputeHash64(assembly.GetName().Name);
- }
-
- ///
- /// 释放资源,卸载所有加载的程序集。
- ///
- public static void Dispose()
- {
- DisposeAsync().Coroutine();
- }
-
- private static async FTask DisposeAsync()
- {
- foreach (var (_, assemblyInfo) in AssemblyList.ToArray())
- {
- await UnLoadAssembly(assemblyInfo.Assembly);
- }
-
- AssemblyList.Clear();
- AssemblySystems.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/Assembly/IAssembly.cs b/FantasyNetTest/NBC/Core/Assembly/IAssembly.cs
deleted file mode 100644
index f86c9f1..0000000
--- a/FantasyNetTest/NBC/Core/Assembly/IAssembly.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using NBC.Async;
-
-namespace NBC.Assembly
-{
- ///
- /// 实现这个接口、会再程序集首次加载、卸载、重载的时候调用
- ///
- public interface IAssembly : IDisposable
- {
- ///
- /// 程序集加载时调用
- ///
- /// 程序集标识
- public FTask Load(long assemblyIdentity);
- ///
- /// 程序集重新加载的时候调用
- ///
- /// 程序集标识
- public FTask ReLoad(long assemblyIdentity);
- ///
- /// 卸载的时候调用
- ///
- /// 程序集标识
- public FTask OnUnLoad(long assemblyIdentity);
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/Attributes/Attributes.cs b/FantasyNetTest/NBC/Core/Attributes/Attributes.cs
deleted file mode 100644
index 1c95110..0000000
--- a/FantasyNetTest/NBC/Core/Attributes/Attributes.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-
-namespace NBC
-{
- [AttributeUsage(AttributeTargets.Class)]
- public class BaseAttribute : Attribute
- {
- }
-
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Method)]
- public class SortAttribute : Attribute
- {
- public int Sort;
-
- public SortAttribute(int sort)
- {
- Sort = sort;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/CircularBuffer.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/CircularBuffer.cs
deleted file mode 100644
index d7a68c0..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/CircularBuffer.cs
+++ /dev/null
@@ -1,346 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
-#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
-
-namespace NBC.DataStructure.Collection
-{
- /// 环形缓存(自增式缓存,自动扩充、不会收缩缓存、所以不要用这个操作过大的IO流)
- /// 1、环大小8192,溢出的会自动增加环的大小。
- /// 2、每个块都是一个环形缓存,当溢出的时候会自动添加到下一个环中。
- /// 3、当读取完成后用过的环会放在缓存中,不会销毁掉。
- ///
- /// 自增式缓存类,继承自 Stream 和 IDisposable 接口。
- /// 环形缓存具有自动扩充的特性,但不会收缩,适用于操作不过大的 IO 流。
- ///
- public sealed class CircularBuffer : Stream, IDisposable
- {
- private byte[] _lastBuffer;
- ///
- /// 环形缓存块的默认大小
- ///
- public const int ChunkSize = 8192;
- private readonly Queue _bufferCache = new Queue();
- private readonly Queue _bufferQueue = new Queue();
- ///
- /// 获取或设置环形缓存的第一个索引位置
- ///
- public int FirstIndex { get; set; }
- ///
- /// 获取或设置环形缓存的最后一个索引位置
- ///
- public int LastIndex { get; set; }
- ///
- /// 获取环形缓存的总长度
- ///
- public override long Length
- {
- get
- {
- if (_bufferQueue.Count == 0)
- {
- return 0;
- }
-
- return (_bufferQueue.Count - 1) * ChunkSize + LastIndex - FirstIndex;
- }
- }
-
- ///
- /// 获取环形缓存的第一个块
- ///
- public byte[] First
- {
- get
- {
- if (_bufferQueue.Count == 0)
- {
- AddLast();
- }
-
- return _bufferQueue.Peek();
- }
- }
-
- ///
- /// 获取环形缓存的最后一个块
- ///
- public byte[] Last
- {
- get
- {
- if (_bufferQueue.Count == 0)
- {
- AddLast();
- }
-
- return _lastBuffer;
- }
- }
- ///
- /// 向环形缓存中添加一个新的块
- ///
- public void AddLast()
- {
- var buffer = _bufferCache.Count > 0 ? _bufferCache.Dequeue() : new byte[ChunkSize];
- _bufferQueue.Enqueue(buffer);
- _lastBuffer = buffer;
- }
- ///
- /// 从环形缓存中移除第一个块
- ///
- public void RemoveFirst()
- {
- _bufferCache.Enqueue(_bufferQueue.Dequeue());
- }
-
- ///
- /// 从流中读取指定数量的数据到缓存。
- ///
- /// 源数据流。
- /// 要读取的字节数。
- public void Read(Stream stream, int count)
- {
- if (count > Length)
- {
- throw new Exception($"bufferList length < count, {Length} {count}");
- }
-
- var copyCount = 0;
- while (copyCount < count)
- {
- var n = count - copyCount;
- if (ChunkSize - FirstIndex > n)
- {
- stream.Write(First, FirstIndex, n);
- FirstIndex += n;
- copyCount += n;
- }
- else
- {
- stream.Write(First, FirstIndex, ChunkSize - FirstIndex);
- copyCount += ChunkSize - FirstIndex;
- FirstIndex = 0;
- RemoveFirst();
- }
- }
- }
-
- ///
- /// 从缓存中读取指定数量的数据到内存。
- ///
- /// 目标内存。
- /// 要读取的字节数。
- public void Read(Memory memory, int count)
- {
- if (count > Length)
- {
- throw new Exception($"bufferList length < count, {Length} {count}");
- }
-
- var copyCount = 0;
- while (copyCount < count)
- {
- var n = count - copyCount;
- var asMemory = First.AsMemory();
-
- if (ChunkSize - FirstIndex > n)
- {
- var slice = asMemory.Slice(FirstIndex, n);
- slice.CopyTo(memory.Slice(copyCount, n));
- FirstIndex += n;
- copyCount += n;
- }
- else
- {
- var length = ChunkSize - FirstIndex;
- var slice = asMemory.Slice(FirstIndex, length);
- slice.CopyTo(memory.Slice(copyCount, length));
- copyCount += ChunkSize - FirstIndex;
- FirstIndex = 0;
- RemoveFirst();
- }
- }
- }
-
- ///
- /// 从自定义流中读取数据到指定的缓冲区。
- ///
- /// 目标缓冲区,用于存储读取的数据。
- /// 目标缓冲区中的起始偏移量。
- /// 要读取的字节数。
- /// 实际读取的字节数。
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (buffer.Length < offset + count)
- {
- throw new Exception($"buffer length < count, buffer length: {buffer.Length} {offset} {count}");
- }
-
- var length = Length;
- if (length < count)
- {
- count = (int) length;
- }
-
- var copyCount = 0;
-
- // 循环直到成功读取所需的字节数
- while (copyCount < count)
- {
- var copyLength = count - copyCount;
-
- if (ChunkSize - FirstIndex > copyLength)
- {
- // 将数据从当前块的缓冲区复制到目标缓冲区
- Array.Copy(First, FirstIndex, buffer, copyCount + offset, copyLength);
-
- FirstIndex += copyLength;
- copyCount += copyLength;
- continue;
- }
-
- // 复制当前块中剩余的数据,并切换到下一个块
- Array.Copy(First, FirstIndex, buffer, copyCount + offset, ChunkSize - FirstIndex);
- copyCount += ChunkSize - FirstIndex;
- FirstIndex = 0;
-
- RemoveFirst();
- }
-
- return count;
- }
-
- ///
- /// 将数据从给定的字节数组写入流中。
- ///
- /// 包含要写入的数据的字节数组。
- public void Write(byte[] buffer)
- {
- Write(buffer, 0, buffer.Length);
- }
-
- ///
- /// 将数据从给定的流写入流中。
- ///
- /// 包含要写入的数据的流。
- public void Write(Stream stream)
- {
- var copyCount = 0;
- var count = (int) (stream.Length - stream.Position);
-
- while (copyCount < count)
- {
- if (LastIndex == ChunkSize)
- {
- AddLast();
- LastIndex = 0;
- }
-
- var n = count - copyCount;
-
- if (ChunkSize - LastIndex > n)
- {
- _ = stream.Read(Last, LastIndex, n);
- LastIndex += count - copyCount;
- copyCount += n;
- }
- else
- {
- _ = stream.Read(Last, LastIndex, ChunkSize - LastIndex);
- copyCount += ChunkSize - LastIndex;
- LastIndex = ChunkSize;
- }
- }
- }
-
- ///
- /// 将数据从给定的字节数组写入流中。
- ///
- /// 包含要写入的数据的字节数组。
- /// 开始写入的缓冲区中的索引。
- /// 要写入的字节数。
- public override void Write(byte[] buffer, int offset, int count)
- {
- var copyCount = 0;
-
- while (copyCount < count)
- {
- if (ChunkSize == LastIndex)
- {
- AddLast();
- LastIndex = 0;
- }
-
- var byteLength = count - copyCount;
-
- if (ChunkSize - LastIndex > byteLength)
- {
- Array.Copy(buffer, copyCount + offset, Last, LastIndex, byteLength);
- LastIndex += byteLength;
- copyCount += byteLength;
- }
- else
- {
- Array.Copy(buffer, copyCount + offset, Last, LastIndex, ChunkSize - LastIndex);
- copyCount += ChunkSize - LastIndex;
- LastIndex = ChunkSize;
- }
- }
- }
-
- ///
- /// 获取一个值,指示流是否支持读取操作。
- ///
- public override bool CanRead { get; } = true;
- ///
- /// 获取一个值,指示流是否支持寻找操作。
- ///
- public override bool CanSeek { get; } = false;
- ///
- /// 获取一个值,指示流是否支持写入操作。
- ///
- public override bool CanWrite { get; } = true;
- ///
- /// 获取或设置流中的位置。
- ///
- public override long Position { get; set; }
-
- ///
- /// 刷新流(在此实现中引发未实现异常)。
- ///
- public override void Flush()
- {
- throw new NotImplementedException();
- }
-
- ///
- /// 在流中寻找特定位置(在此实现中引发未实现异常)。
- ///
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- ///
- /// 设置流的长度(在此实现中引发未实现异常)。
- ///
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- ///
- /// 释放 CustomStream 使用的所有资源。
- ///
- public new void Dispose()
- {
- _bufferQueue.Clear();
- _lastBuffer = null;
- FirstIndex = 0;
- LastIndex = 0;
- base.Dispose();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/ConcurrentOneToManyListPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/ConcurrentOneToManyListPool.cs
deleted file mode 100644
index d8a5e94..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/ConcurrentOneToManyListPool.cs
+++ /dev/null
@@ -1,197 +0,0 @@
-#if !FANTASY_WEBGL
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using NBC.Pool;
-
-#pragma warning disable CS8603 // Possible null reference return.
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 并发的一对多列表池,用于维护具有相同键的多个值的关联关系,实现了 接口。
- ///
- /// 关键字的类型,不能为空。
- /// 值的类型。
- public class ConcurrentOneToManyListPool : ConcurrentOneToManyList, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 的实例。
- ///
- /// 创建的实例。
- public static ConcurrentOneToManyListPool Create()
- {
- var a = MultiThreadPool.Rent>();
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放实例占用的资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- // 清空实例的数据
- Clear();
- // 将实例返回到池中以便重用
- MultiThreadPool.Return(this);
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 并发的一对多列表,用于维护具有相同键的多个值的关联关系。
- ///
- /// 关键字的类型,不能为空。
- /// 值的类型。
- public class ConcurrentOneToManyList : ConcurrentDictionary> where TKey : notnull
- {
- private readonly Queue> _queue = new Queue>();
- private readonly int _recyclingLimit = 120;
-
- ///
- /// 初始化 类的新实例。
- ///
- public ConcurrentOneToManyList()
- {
- }
-
- ///
- /// 设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public ConcurrentOneToManyList(int recyclingLimit)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断指定键的列表是否包含指定值。
- ///
- /// 要搜索的键。
- /// 要搜索的值。
- /// 如果列表包含值,则为 true;否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 向指定键的列表中添加一个值。
- ///
- /// 要添加值的键。
- /// 要添加的值。
- public void Add(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Add(value);
- base[key] = list;
- return;
- }
-
- list.Add(value);
- }
-
- ///
- /// 获取指定键的列表中的第一个值。
- ///
- /// 要获取第一个值的键。
- /// 指定键的列表中的第一个值,如果不存在则为默认值。
- public TValue First(TKey key)
- {
- return !TryGetValue(key, out var list) ? default : list.FirstOrDefault();
- }
-
- ///
- /// 从指定键的列表中移除一个值。
- ///
- /// 要移除值的键。
- /// 要移除的值。
- public void RemoveValue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list)) return;
-
- list.Remove(value);
-
- if (list.Count == 0) RemoveKey(key);
- }
-
- ///
- /// 从字典中移除指定键以及其关联的列表。
- ///
- /// 要移除的键。
- public void RemoveKey(TKey key)
- {
- if (!TryRemove(key, out var list)) return;
-
- Recycle(list);
- }
-
- ///
- /// 从队列中获取一个列表,如果队列为空则创建一个新的列表。
- ///
- /// 获取的列表。
- private List Fetch()
- {
- return _queue.Count <= 0 ? new List() : _queue.Dequeue();
- }
-
- ///
- /// 将一个列表回收到队列中。
- ///
- /// 要回收的列表。
- private void Recycle(List list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
-
- ///
- /// 清空当前类的数据,包括从基类继承的数据以及自定义的数据队列。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/ConcurrentOneToManyQueuePool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/ConcurrentOneToManyQueuePool.cs
deleted file mode 100644
index e6ee79f..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/ConcurrentOneToManyQueuePool.cs
+++ /dev/null
@@ -1,194 +0,0 @@
-#if !FANTASY_WEBGL
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using NBC.Pool;
-
-#pragma warning disable CS8603
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 表示一个并发的一对多队列池,用于维护具有相同键的多个值的关联关系,实现了 接口。
- ///
- /// 关键字的类型,不能为空。
- /// 值的类型。
- public class ConcurrentOneToManyQueuePool : ConcurrentOneToManyQueue, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建并返回一个 的实例。
- ///
- /// 创建的实例。
- public static ConcurrentOneToManyQueuePool Create()
- {
- var a = MultiThreadPool.Rent>();
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前实例所占用的资源,并将实例返回到对象池中,以便重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
- // 将实例返回到对象池中,以便重用
- MultiThreadPool.Return(this);
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 表示一个并发的一对多队列,用于维护具有相同键的多个值的关联关系。
- ///
- /// 关键字的类型,不能为空。
- /// 值的类型。
- public class ConcurrentOneToManyQueue : ConcurrentDictionary> where TKey : notnull
- {
- private readonly Queue> _queue = new Queue>();
- private readonly int _recyclingLimit;
-
- ///
- /// 设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public ConcurrentOneToManyQueue(int recyclingLimit = 0)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断指定键的队列是否包含指定值。
- ///
- /// 要搜索的键。
- /// 要搜索的值。
- /// 如果队列包含值,则为 true;否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 向指定键的队列中添加一个值。
- ///
- /// 要添加值的键。
- /// 要添加的值。
- public void Enqueue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Enqueue(value);
- TryAdd(key, list);
- return;
- }
-
- list.Enqueue(value);
- }
-
- ///
- /// 从指定键的队列中出队并返回一个值。
- ///
- /// 要出队的键。
- /// 出队的值,如果队列为空则为默认值。
- public TValue Dequeue(TKey key)
- {
- if (!TryGetValue(key, out var list) || list.Count == 0) return default;
-
- var value = list.Dequeue();
-
- if (list.Count == 0) RemoveKey(key);
-
- return value;
- }
-
- ///
- /// 尝试从指定键的队列中出队一个值。
- ///
- /// 要出队的键。
- /// 出队的值,如果队列为空则为默认值。
- /// 如果成功出队,则为 true;否则为 false。
- public bool TryDequeue(TKey key, out TValue value)
- {
- value = Dequeue(key);
-
- return value != null;
- }
-
- ///
- /// 从字典中移除指定键以及其关联的队列。
- ///
- /// 要移除的键。
- public void RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var list)) return;
-
- TryRemove(key, out _);
- Recycle(list);
- }
-
- ///
- /// 从队列中获取一个新的队列,如果队列为空则创建一个新的队列。
- ///
- /// 获取的队列。
- private Queue Fetch()
- {
- return _queue.Count <= 0 ? new Queue() : _queue.Dequeue();
- }
-
- ///
- /// 将一个队列回收到队列池中。
- ///
- /// 要回收的队列。
- private void Recycle(Queue list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
-
- ///
- /// 清空当前类的数据,包括从基类继承的键值对字典中的数据以及自定义的队列池。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/HashSetPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/HashSetPool.cs
deleted file mode 100644
index 5e46af0..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/HashSetPool.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 可释放的哈希集合对象池。
- ///
- /// 哈希集合中元素的类型。
- public sealed class HashSetPool : HashSet, IDisposable, IPool
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 释放实例所占用的资源,并将实例返回到对象池中,以便重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 创建一个 哈希集合池的实例。
- ///
- /// 创建的实例。
- public static HashSetPool Create()
- {
-#if FANTASY_WEBGL
- var list = Pool>.Rent();
- list._isDispose = false;
- list._isPool = true;
- return list;
-#else
- var list = MultiThreadPool.Rent>();
- list._isDispose = false;
- list._isPool = true;
- return list;
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 基本哈希集合对象池,他自持有实际的哈希集合。
- ///
- /// 哈希集合中元素的类型。
- public sealed class HashSetBasePool : IDisposable, IPool
- {
- private bool _isPool;
-
- ///
- /// 存储实际的哈希集合
- ///
- public HashSet Set = new HashSet();
-
- ///
- /// 创建一个 基本哈希集合对象池的实例。
- ///
- /// 创建的实例。
- public static HashSetBasePool Create()
- {
-#if FANTASY_WEBGL
- var hashSetBasePool = Pool>.Rent();
- hashSetBasePool._isPool = true;
- return hashSetBasePool;
-#else
- var hashSetBasePool = MultiThreadPool.Rent>();
- hashSetBasePool._isPool = true;
- return hashSetBasePool;
-#endif
- }
-
- ///
- /// 释放实例所占用的资源,并将实例返回到对象池中,以便重用。
- ///
- public void Dispose()
- {
- Set.Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- throw new NotImplementedException();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/ListPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/ListPool.cs
deleted file mode 100644
index 13c272f..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/ListPool.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 可释放的列表(List)对象池。
- ///
- /// 列表中元素的类型。
- public sealed class ListPool : List, IDisposable, IPool
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 释放实例所占用的资源,并将实例返回到对象池中,以便重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 使用指定的元素创建一个 列表(List)对象池的实例。
- ///
- /// 要添加到列表的元素。
- /// 创建的实例。
- public static ListPool Create(params T[] args)
- {
-#if FANTASY_WEBGL
- var list = Pool>.Rent();
-#else
- var list = MultiThreadPool.Rent>();
-#endif
- list._isDispose = false;
- list._isPool = true;
-
- if (args != null)
- {
- list.AddRange(args);
- }
-
- return list;
- }
-
- ///
- /// 使用指定的列表创建一个 列表(List)对象池的实例。
- ///
- /// 要添加到列表的元素列表。
- /// 创建的实例。
- public static ListPool Create(List args)
- {
-#if FANTASY_WEBGL
- var list = Pool>.Rent();
-#else
- var list = MultiThreadPool.Rent>();
-#endif
- list._isDispose = false;
- list._isPool = true;
-
- if (args != null)
- {
- list.AddRange(args);
- }
-
- return list;
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyHashSetPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyHashSetPool.cs
deleted file mode 100644
index e0a223d..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyHashSetPool.cs
+++ /dev/null
@@ -1,208 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 一对多哈希集合(OneToManyHashSet)对象池。
- ///
- /// 键的类型。
- /// 值的类型。
- public class OneToManyHashSetPool : OneToManyHashSet, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 一对多哈希集合(OneToManyHashSet)对象池的实例。
- ///
- /// 创建的实例。
- public static OneToManyHashSetPool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放实例所占用的资源,并将实例返回到对象池中,以便重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 一对多哈希集合(OneToManyHashSet),用于创建和管理键对应多个值的集合。
- ///
- /// 键的类型。
- /// 值的类型。
- public class OneToManyHashSet : Dictionary> where TKey : notnull
- {
- /// 用于回收和重用的空闲值集合队列。
- private readonly Queue> _queue = new Queue>();
- /// 设置最大回收限制,用于控制值集合的最大数量。
- private readonly int _recyclingLimit = 120;
- /// 一个空的、不包含任何元素的哈希集合,用于在查找失败时返回。
- private static HashSet _empty = new HashSet();
-
- ///
- /// 初始化 类的新实例。
- ///
- public OneToManyHashSet() { }
-
- ///
- /// 设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public OneToManyHashSet(int recyclingLimit)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断指定的键值对是否存在于集合中。
- ///
- /// 键。
- /// 值。
- /// 如果存在则为 true,否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 添加指定的键值对到集合中。
- ///
- /// 键。
- /// 值。
- public void Add(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Add(value);
- Add(key, list);
-
- return;
- }
-
- list.Add(value);
- }
-
- ///
- /// 从集合中移除指定键对应的值。
- ///
- /// 键。
- /// 要移除的值。
- public void RemoveValue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list)) return;
-
- list.Remove(value);
-
- if (list.Count == 0) RemoveKey(key);
- }
-
- ///
- /// 从集合中移除指定键及其对应的值集合。
- ///
- /// 键。
- public void RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var list)) return;
-
- Remove(key);
- Recycle(list);
- }
-
- ///
- /// 获取指定键对应的值集合,如果不存在则返回一个空的哈希集合。
- ///
- /// 键。
- /// 对应的值集合或空的哈希集合。
- public HashSet GetValue(TKey key)
- {
- if (TryGetValue(key, out HashSet value))
- {
- return value;
- }
-
- return _empty;
- }
-
- ///
- /// 从队列中获取一个空闲的值集合,或者创建一个新的。
- ///
- /// 值集合。
- private HashSet Fetch()
- {
- return _queue.Count <= 0 ? new HashSet() : _queue.Dequeue();
- }
-
- ///
- /// 回收值集合到队列中,以便重复利用。
- ///
- /// 要回收的值集合。
- private void Recycle(HashSet list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
-
- ///
- /// 清空集合中的数据并和队列。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyListPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyListPool.cs
deleted file mode 100644
index 1f7d469..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyListPool.cs
+++ /dev/null
@@ -1,253 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using NBC.Pool;
-
-#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
-#pragma warning disable CS8603 // Possible null reference return.
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 可回收的、一对多关系的列表池。
- ///
- /// 键的类型。
- /// 值的类型。
- public class OneToManyListPool : OneToManyList, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 一对多关系的列表池的实例。
- ///
- /// 创建的实例。
- public static OneToManyListPool Create()
- {
-#if FANTASY_WEBGL || FANTASY_EXPORTER
- var list = Pool>.Rent();
-#else
- var list = MultiThreadPool.Rent>();
-#endif
- list._isDispose = false;
- list._isPool = true;
- return list;
- }
-
- ///
- /// 释放当前对象所占用的资源,并将对象回收到对象池中。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL || FANTASY_EXPORTER
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 一对多关系的列表字典。
- ///
- /// 键的类型。
- /// 值的类型。
- public class OneToManyList : Dictionary> where TKey : notnull
- {
- private readonly int _recyclingLimit = 120;
- private static readonly List Empty = new List();
- private readonly Queue> _queue = new Queue>();
-
- ///
- /// 初始化一个新的 实例。
- ///
- public OneToManyList() { }
-
- ///
- /// 对整个字典的所有 List 进行排序
- ///
- public void SortAll()
- {
- foreach (var key in Keys.ToList()) // 使用 ToList() 避免修改集合异常
- {
- this[key] = this[key].OrderByDescending(GetSortValue).ToList();
- }
- }
-
- // 获取对象的排序值(SortAttribute 的值,默认 0)
- private int GetSortValue(TValue obj)
- {
- if (obj == null) return 0;
-
- var sortAttr = obj.GetType().GetCustomAttribute();
- return sortAttr?.Sort ?? 0;
- }
-
- ///
- /// 设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public OneToManyList(int recyclingLimit)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断给定的键和值是否存在于列表中。
- ///
- /// 要搜索的键。
- /// 要搜索的值。
- /// 如果存在则为 ,否则为 。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 向列表中添加指定键和值。
- ///
- /// 要添加值的键。
- /// 要添加的值。
- public void Add(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Add(value);
- Add(key, list);
-
- return;
- }
-
- list.Add(value);
- }
-
- ///
- /// 获取指定键对应的列表中的第一个值。
- ///
- /// 要获取值的键。
- /// 键对应的列表中的第一个值。
- public TValue First(TKey key)
- {
- return !TryGetValue(key, out var list) ? default : list.FirstOrDefault();
- }
-
- ///
- /// 从列表中移除指定键和值。
- ///
- /// 要移除值的键。
- /// 要移除的值。
- /// 如果成功移除则为 ,否则为 。
- public bool RemoveValue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- return true;
- }
-
- var isRemove = list.Remove(value);
-
- if (list.Count == 0)
- {
- isRemove = RemoveByKey(key);
- }
-
- return isRemove;
- }
-
- ///
- /// 从列表中移除指定键及其关联的所有值。
- ///
- /// 要移除的键。
- /// 如果成功移除则为 ,否则为 。
- public bool RemoveByKey(TKey key)
- {
- if (!TryGetValue(key, out var list))
- {
- return false;
- }
-
- Remove(key);
- Recycle(list);
- return true;
- }
-
- ///
- /// 获取指定键关联的所有值的列表。
- ///
- /// 要获取值的键。
- /// 键关联的所有值的列表。
- public List GetValues(TKey key)
- {
- if (TryGetValue(key, out List list))
- {
- return list;
- }
-
- return Empty;
- }
-
- ///
- /// 清除字典中的所有键值对,并回收相关的值集合。
- ///
- public new void Clear()
- {
- foreach (var keyValuePair in this) Recycle(keyValuePair.Value);
-
- base.Clear();
- }
-
- ///
- /// 从空闲值集合队列中获取一个值集合,如果队列为空则创建一个新的值集合。
- ///
- /// 从队列中获取的值集合。
- private List Fetch()
- {
- return _queue.Count <= 0 ? new List() : _queue.Dequeue();
- }
-
- ///
- /// 回收一个不再使用的值集合到空闲值集合队列中。
- ///
- /// 要回收的值集合。
- private void Recycle(List list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyQueuePool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyQueuePool.cs
deleted file mode 100644
index e787ba8..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/OneToManyQueuePool.cs
+++ /dev/null
@@ -1,204 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-#pragma warning disable CS8603
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 支持一对多关系的队列池,用于存储具有相同键的值的队列集合。
- ///
- /// 键的类型。
- /// 值的类型。
- public class OneToManyQueuePool : OneToManyQueue, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 一对多关系的队列池的实例。
- ///
- /// 创建的实例。
- public static OneToManyQueuePool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前实例所占用的资源,并将实例回收到对象池中。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 支持一对多关系的队列,用于存储具有相同键的值的队列集合。
- ///
- /// 键的类型。
- /// 值的类型。
- public class OneToManyQueue : Dictionary> where TKey : notnull
- {
- private readonly Queue> _queue = new Queue>();
- private readonly int _recyclingLimit;
-
- ///
- /// 创建一个 一对多关系的队列的实例。设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public OneToManyQueue(int recyclingLimit = 0)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断指定键的值队列是否包含指定的值。
- ///
- /// 要查找的键。
- /// 要查找的值。
- /// 如果存在,则为 true;否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 将指定的值添加到指定键的值队列中。
- ///
- /// 要添加值的键。
- /// 要添加的值。
- public void Enqueue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Enqueue(value);
- Add(key, list);
- return;
- }
-
- list.Enqueue(value);
- }
-
- ///
- /// 从指定键的值队列中出队一个值。
- ///
- /// 要出队的键。
- /// 出队的值。
- public TValue Dequeue(TKey key)
- {
- if (!TryGetValue(key, out var list) || list.Count == 0)
- {
- return default;
- }
-
- var value = list.Dequeue();
-
- if (list.Count == 0)
- {
- RemoveKey(key);
- }
-
- return value;
- }
-
- ///
- /// 尝试从指定键的值队列中出队一个值。
- ///
- /// 要出队的键。
- /// 出队的值。
- /// 如果成功出队,则为 true;否则为 false。
- public bool TryDequeue(TKey key, out TValue value)
- {
- value = Dequeue(key);
-
- return value != null;
- }
-
- ///
- /// 从字典中移除指定键及其对应的值队列。
- ///
- /// 要移除的键。
- public void RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var list)) return;
-
- Remove(key);
- Recycle(list);
- }
-
- ///
- /// 从队列池中获取一个值队列。如果队列池为空,则创建一个新的值队列。
- ///
- /// 获取的值队列。
- private Queue Fetch()
- {
- return _queue.Count <= 0 ? new Queue() : _queue.Dequeue();
- }
-
- ///
- /// 回收一个不再使用的值队列到队列池中,以便重用。
- ///
- /// 要回收的值队列。
- private void Recycle(Queue list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
-
- ///
- /// 清空当前实例的数据,同时回收所有值队列。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/ReuseList.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/ReuseList.cs
deleted file mode 100644
index 50be9bc..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/ReuseList.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 可重用的列表,继承自 类。该类支持通过对象池重用列表实例,以减少对象分配和释放的开销。
- ///
- /// 列表中元素的类型。
- public sealed class ReuseList : List, IDisposable, IPool
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 可重用的列表的实例。
- ///
- /// 创建的实例。
- public static ReuseList Create()
- {
-#if FANTASY_WEBGL
- var list = Pool>.Rent();
-#else
- var list = MultiThreadPool.Rent>();
-#endif
- list._isDispose = false;
- list._isPool = true;
- return list;
- }
-
- ///
- /// 释放该实例所占用的资源,并将实例返回到对象池中,以便重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedConcurrentOneToManyListPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedConcurrentOneToManyListPool.cs
deleted file mode 100644
index 98198a9..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedConcurrentOneToManyListPool.cs
+++ /dev/null
@@ -1,226 +0,0 @@
-#if !FANTASY_WEBGL
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NBC.Pool;
-
-#pragma warning disable CS8603
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 基于排序字典和并发集合实现的一对多映射列表的对象池包装类,继承自 类,
- /// 同时实现了 接口,以支持对象的重用和释放。
- ///
- /// 键的类型。
- /// 值的类型。
- public class SortedConcurrentOneToManyListPool : SortedConcurrentOneToManyList, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个新的 实例,使用默认的参数设置。
- ///
- /// 新创建的 实例。
- public static SortedConcurrentOneToManyListPool Create()
- {
- var a = MultiThreadPool.Rent>();
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前对象池实例,将其返回到对象池以供重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
- MultiThreadPool.Return(this);
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 基于排序字典和并发集合实现的一多对映射列表类,继承自 类,
- /// 用于在多个值与一个键关联的情况下进行管理和存储。该类支持并发操作,适用于多线程环境。
- ///
- /// 键的类型。
- /// 值的类型。
- public class SortedConcurrentOneToManyList : SortedDictionary> where TKey : notnull
- {
- /// 用于同步操作的锁对象,它确保在多线程环境下对数据的安全访问。
- private readonly object _lockObject = new object();
- /// 用于存储缓存的队列。
- private readonly Queue> _queue = new Queue>();
- /// 控制缓存回收的限制。当缓存的数量超过此限制时,旧的缓存将会被回收。
- private readonly int _recyclingLimit;
-
- ///
- /// 初始化一个新的 类的实例,使用默认的参数设置。
- ///
- public SortedConcurrentOneToManyList()
- {
- }
-
- ///
- /// 初始化一个新的 类的实例,指定最大缓存数量。
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public SortedConcurrentOneToManyList(int recyclingLimit = 0)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 检查指定的键和值是否存在于映射列表中。
- ///
- /// 要检查的键。
- /// 要检查的值。
- /// 如果存在,则为 true;否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- lock (_lockObject)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
- }
-
- ///
- /// 将指定的值添加到与指定键关联的列表中。
- ///
- /// 要关联值的键。
- /// 要添加到列表的值。
- public void Add(TKey key, TValue value)
- {
- lock (_lockObject)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Add(value);
- base[key] = list;
- return;
- }
-
- list.Add(value);
- }
- }
-
- ///
- /// 获取与指定键关联的列表中的第一个值。
- /// 如果列表不存在或为空,则返回默认值。
- ///
- /// 要获取第一个值的键。
- /// 第一个值,或默认值。
- public TValue First(TKey key)
- {
- lock (_lockObject)
- {
- return !TryGetValue(key, out var list) ? default : list.FirstOrDefault();
- }
- }
-
- ///
- /// 从与指定键关联的列表中移除指定的值。
- /// 如果列表不存在或值不存在于列表中,则不执行任何操作。
- ///
- /// 要移除值的键。
- /// 要移除的值。
- public void RemoveValue(TKey key, TValue value)
- {
- lock (_lockObject)
- {
- if (!TryGetValue(key, out var list)) return;
-
- list.Remove(value);
-
- if (list.Count == 0) RemoveKey(key);
- }
- }
-
- ///
- /// 从映射列表中移除指定的键及其关联的列表。
- /// 如果键不存在于映射列表中,则不执行任何操作。
- ///
- /// 要移除的键。
- public void RemoveKey(TKey key)
- {
- lock (_lockObject)
- {
- if (!TryGetValue(key, out var list)) return;
-
- Remove(key);
-
- Recycle(list);
- }
- }
-
- ///
- /// 从缓存中获取一个可重用的列表。如果缓存中不存在列表,则创建一个新的列表并返回。
- ///
- /// 可重用的列表。
- private List Fetch()
- {
- lock (_lockObject)
- {
- return _queue.Count <= 0 ? new List() : _queue.Dequeue();
- }
- }
-
- ///
- /// 将不再使用的列表回收到缓存中,以便重复利用。如果缓存数量超过限制,则丢弃列表而不进行回收。
- ///
- /// 要回收的列表。
- private void Recycle(List list)
- {
- lock (_lockObject)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
- }
-
- ///
- /// 清空映射列表以及队列。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedOneToManyHashSetPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedOneToManyHashSetPool.cs
deleted file mode 100644
index 0c49ca8..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedOneToManyHashSetPool.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 基于排序字典实现的一对多关系的映射哈希集合的对象池包装类,将唯一键映射到多个值的哈希集合。
- /// 同时实现了 接口,以支持对象的重用和释放。
- ///
- /// 字典中键的类型。
- /// 哈希集合中值的类型。
- public class SortedOneToManyHashSetPool : SortedOneToManyHashSet, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 实例。
- ///
- /// 新创建的实例。
- public static SortedOneToManyHashSetPool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前对象池实例,将其返回到对象池以供重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 基于排序字典实现的一对多关系的映射哈希集合类,将唯一键映射到多个值的哈希集合。
- /// 用于在多个值与一个键关联的情况下进行管理和存储。
- ///
- /// 字典中键的类型。
- /// 集合中值的类型。
- public class SortedOneToManyHashSet : SortedDictionary> where TKey : notnull
- {
- private readonly Queue> _queue = new Queue>();
- private readonly int _recyclingLimit = 120;
-
- ///
- /// 创建一个新的 实例。
- ///
- public SortedOneToManyHashSet() { }
-
- ///
- /// 创建一个新的 实例,设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public SortedOneToManyHashSet(int recyclingLimit)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断哈希集合中是否包含指定的键值对。
- ///
- /// 要查找的键。
- /// 要查找的值。
- /// 如果键值对存在,则为 true;否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 将指定值添加到给定键关联的哈希集合中。
- ///
- /// 要添加值的键。
- /// 要添加的值。
- public void Add(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Add(value);
- Add(key, list);
-
- return;
- }
-
- list.Add(value);
- }
-
- ///
- /// 从指定键关联的哈希集合中移除特定值。
- /// 如果哈希集合不存在或值不存在于集合中,则不执行任何操作。
- ///
- /// 要移除值的键。
- /// 要移除的值。
- public void RemoveValue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list)) return;
-
- list.Remove(value);
-
- if (list.Count == 0) RemoveKey(key);
- }
-
- ///
- /// 从字典中移除指定键以及关联的哈希集合,并将集合进行回收。
- /// 如果键不存在于映射列表中,则不执行任何操作。
- ///
- /// 要移除的键。
- public void RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var list)) return;
-
- Remove(key);
-
- Recycle(list);
- }
-
- ///
- /// 获取一个空的或回收的哈希集合。
- ///
- /// 获取的哈希集合实例。
- private HashSet Fetch()
- {
- return _queue.Count <= 0 ? new HashSet() : _queue.Dequeue();
- }
-
- ///
- /// 回收一个哈希集合,将其清空并放入回收队列中。
- ///
- /// 要回收的哈希集合。
- private void Recycle(HashSet list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(list);
- }
-
- ///
- /// 重写 Clear 方法,清空字典并清空回收队列。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedOneToManyListPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedOneToManyListPool.cs
deleted file mode 100644
index dc349c9..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Collection/SortedOneToManyListPool.cs
+++ /dev/null
@@ -1,217 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NBC.Pool;
-
-#pragma warning disable CS8603
-
-namespace NBC.DataStructure.Collection
-{
- ///
- /// 基于排序字典实现的一对多映射列表的对象池包装类,继承自 类,
- /// 同时实现了 接口,以支持对象的重用和释放。
- ///
- /// 字典中键的类型。
- /// 列表中值的类型。
- public class SortedOneToManyListPool : SortedOneToManyList, IDisposable, IPool where TKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 实例。
- ///
- /// 新创建的实例。
- public static SortedOneToManyListPool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前对象池实例,将其返回到对象池以供重用。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 基于排序字典实现的一对多关系的映射列表类,将唯一键映射到包含多个值的列表。
- /// 用于在多个值与一个键关联的情况下进行管理和存储。
- ///
- /// 字典中键的类型。
- /// 列表中值的类型。
- public class SortedOneToManyList : SortedDictionary> where TKey : notnull
- {
- private readonly Queue> _queue = new Queue>();
- private readonly int _recyclingLimit;
-
- ///
- /// 创建一个新的 实例。
- ///
- public SortedOneToManyList()
- {
- }
-
- ///
- /// 创建一个新的 实例,设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public SortedOneToManyList(int recyclingLimit = 0)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 判断列表中是否包含指定的键值对。
- ///
- /// 要查找的键。
- /// 要查找的值。
- /// 如果键值对存在,则为 true;否则为 false。
- public bool Contains(TKey key, TValue value)
- {
- TryGetValue(key, out var list);
-
- return list != null && list.Contains(value);
- }
-
- ///
- /// 将指定值添加到给定键关联的列表中。
- ///
- /// 要添加值的键。
- /// 要添加的值。
- public void Add(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- list = Fetch();
- list.Add(value);
- base[key] = list;
- return;
- }
-
- list.Add(value);
- }
-
- ///
- /// 获取指定键关联的列表中的第一个值。
- ///
- /// 要查找值的键。
- /// 指定键关联的列表中的第一个值,如果列表为空则返回默认值。
- public TValue First(TKey key)
- {
- return !TryGetValue(key, out var list) ? default : list.FirstOrDefault();
- }
-
- ///
- /// 从指定键关联的列表中移除特定值。
- ///
- /// 要移除值的键。
- /// 要移除的值。
-
- public void RemoveValue(TKey key, TValue value)
- {
- if (!TryGetValue(key, out var list))
- {
- return;
- }
-
- list.Remove(value);
-
- if (list.Count == 0)
- {
- RemoveKey(key);
- }
- }
-
- ///
- /// 从字典中移除指定键以及关联的列表,并将列表进行回收。
- ///
- /// 要移除的键。
-
- public void RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var list))
- {
- return;
- }
-
- Remove(key);
- Recycle(list);
- }
-
- ///
- /// 获取一个空的或回收的列表。
- ///
- /// 获取的列表实例。
- private List Fetch()
- {
- return _queue.Count <= 0 ? new List() : _queue.Dequeue();
- }
-
- ///
- /// 回收一个列表,将其清空并放入回收队列中。如果缓存数量超过限制,则丢弃列表而不进行回收
- ///
- /// 要回收的列表。
- private void Recycle(List list)
- {
- list.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit)
- {
- return;
- }
-
- _queue.Enqueue(list);
- }
-
- ///
- /// 重写 Clear 方法,清空字典并清空回收队列。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DictionaryExtensions.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DictionaryExtensions.cs
deleted file mode 100644
index 609c411..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DictionaryExtensions.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Collections.Generic;
-#pragma warning disable CS8601 // Possible null reference assignment.
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 提供对字典的扩展方法。
- ///
- public static class DictionaryExtensions
- {
- ///
- /// 尝试从字典中移除指定键,并返回相应的值。
- ///
- /// 字典中键的类型。
- /// 字典中值的类型。
- /// 要操作的字典实例。
- /// 要移除的键。
- /// 从字典中移除的值(如果成功移除)。
- /// 如果成功移除键值对,则为 true;否则为 false。
- public static bool TryRemove(this IDictionary self, T key, out TV value)
- {
- if (!self.TryGetValue(key, out value))
- {
- return false;
- }
-
- self.Remove(key);
- return true;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DictionaryPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DictionaryPool.cs
deleted file mode 100644
index a65c8f1..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DictionaryPool.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 提供一个可以使用对象池管理的字典类。
- ///
- /// 字典中键的类型。
- /// 字典中值的类型。
- public sealed class DictionaryPool : Dictionary, IDisposable, IPool where TM : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 释放实例占用的资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 创建一个新的 实例。
- ///
- /// 新创建的实例。
- public static DictionaryPool Create()
- {
-#if FANTASY_WEBGL
- var dictionary = Pool>.Rent();
-#else
- var dictionary = MultiThreadPool.Rent>();
-#endif
- dictionary._isDispose = false;
- dictionary._isPool = true;
- return dictionary;
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DoubleMapDictionaryPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DoubleMapDictionaryPool.cs
deleted file mode 100644
index d786881..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/DoubleMapDictionaryPool.cs
+++ /dev/null
@@ -1,289 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-#pragma warning disable CS8601 // Possible null reference assignment.
-#pragma warning disable CS8604 // Possible null reference argument.
-#pragma warning disable CS8603 // Possible null reference return.
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 提供一个双向映射字典对象池类,用于双向键值对映射。
- ///
- /// 字典中键的类型。
- /// 字典中值的类型。
- public class DoubleMapDictionaryPool : DoubleMapDictionary, IDisposable, IPool where TKey : notnull where TValue : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个新的 实例。
- ///
- /// 新创建的实例。
- public static DoubleMapDictionaryPool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放实例占用的资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 可以实现双向映射的字典类,用于将键和值进行双向映射。
- ///
- /// 键的类型,不能为 null。
- /// 值的类型,不能为 null。
- public class DoubleMapDictionary where TK : notnull where TV : notnull
- {
- private readonly Dictionary _kv = new Dictionary();
- private readonly Dictionary _vk = new Dictionary();
-
- ///
- /// 创建一个新的空的 实例。
- ///
- public DoubleMapDictionary() { }
-
- ///
- /// 创建一个新的具有指定初始容量的 实例。
- ///
- /// 初始容量。
- public DoubleMapDictionary(int capacity)
- {
- _kv = new Dictionary(capacity);
- _vk = new Dictionary(capacity);
- }
-
- ///
- /// 获取包含字典中所有键的列表。
- ///
- public List Keys => new List(_kv.Keys);
-
- ///
- /// 获取包含字典中所有值的列表。
- ///
- public List Values => new List(_vk.Keys);
-
- ///
- /// 对字典中的每个键值对执行指定的操作。
- ///
- /// 要执行的操作。
- public void ForEach(Action action)
- {
- if (action == null)
- {
- return;
- }
-
- var keys = _kv.Keys;
- foreach (var key in keys)
- {
- action(key, _kv[key]);
- }
- }
-
- ///
- /// 将指定的键值对添加到字典中。
- ///
- /// 要添加的键。
- /// 要添加的值。
- public void Add(TK key, TV value)
- {
- if (key == null || value == null || _kv.ContainsKey(key) || _vk.ContainsKey(value))
- {
- return;
- }
-
- _kv.Add(key, value);
- _vk.Add(value, key);
- }
-
- ///
- /// 根据指定的键获取相应的值。
- ///
- /// 要查找值的键。
- /// 与指定键关联的值,如果找不到键,则返回默认值。
- public TV GetValueByKey(TK key)
- {
- if (key != null && _kv.ContainsKey(key))
- {
- return _kv[key];
- }
-
- return default;
- }
-
- ///
- /// 尝试根据指定的键获取相应的值。
- ///
- /// 要查找值的键。
- /// 如果找到,则为与指定键关联的值;否则为值的默认值。
- /// 如果找到键,则为 true;否则为 false。
- public bool TryGetValueByKey(TK key, out TV value)
- {
- var result = key != null && _kv.ContainsKey(key);
-
- value = result ? _kv[key] : default;
-
- return result;
- }
-
- ///
- /// 根据指定的值获取相应的键。
- ///
- /// 要查找键的值。
- /// 与指定值关联的键,如果找不到值,则返回默认键。
- public TK GetKeyByValue(TV value)
- {
- if (value != null && _vk.ContainsKey(value))
- {
- return _vk[value];
- }
-
- return default;
- }
-
- ///
- /// 尝试根据指定的值获取相应的键。
- ///
- /// 要查找键的值。
- /// 如果找到,则为与指定值关联的键;否则为键的默认值。
- /// 如果找到值,则为 true;否则为 false。
- public bool TryGetKeyByValue(TV value, out TK key)
- {
- var result = value != null && _vk.ContainsKey(value);
-
- key = result ? _vk[value] : default;
-
- return result;
- }
-
- ///
- /// 根据指定的键移除键值对。
- ///
- /// 要移除的键。
- public void RemoveByKey(TK key)
- {
- if (key == null)
- {
- return;
- }
-
- if (!_kv.TryGetValue(key, out var value))
- {
- return;
- }
-
- _kv.Remove(key);
- _vk.Remove(value);
- }
-
- ///
- /// 根据指定的值移除键值对。
- ///
- /// 要移除的值。
- public void RemoveByValue(TV value)
- {
- if (value == null)
- {
- return;
- }
-
- if (!_vk.TryGetValue(value, out var key))
- {
- return;
- }
-
- _kv.Remove(key);
- _vk.Remove(value);
- }
-
- ///
- /// 清空字典中的所有键值对。
- ///
- public void Clear()
- {
- _kv.Clear();
- _vk.Clear();
- }
-
- ///
- /// 判断字典是否包含指定的键。
- ///
- /// 要检查的键。
- /// 如果字典包含指定的键,则为 true;否则为 false。
- public bool ContainsKey(TK key)
- {
- return key != null && _kv.ContainsKey(key);
- }
-
- ///
- /// 判断字典是否包含指定的值。
- ///
- /// 要检查的值。
- /// 如果字典包含指定的值,则为 true;否则为 false。
- public bool ContainsValue(TV value)
- {
- return value != null && _vk.ContainsKey(value);
- }
-
- ///
- /// 判断字典是否包含指定的键值对。
- ///
- /// 要检查的键。
- /// 要检查的值。
- /// 如果字典包含指定的键值对,则为 true;否则为 false。
- public bool Contains(TK key, TV value)
- {
- if (key == null || value == null)
- {
- return false;
- }
-
- return _kv.ContainsKey(key) && _vk.ContainsKey(value);
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/EntityDictionary.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/EntityDictionary.cs
deleted file mode 100644
index 4c4d25f..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/EntityDictionary.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 提供一个带资源释放功能的实体字典类,支持使用对象池管理。
- ///
- /// 字典中键的类型。
- /// 字典中值的类型,必须实现 IDisposable 接口。
- public sealed class EntityDictionary : Dictionary, IDisposable, IPool where TN : IDisposable where TM : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个新的 实例。
- ///
- /// 新创建的实例。
- public static EntityDictionary Create()
- {
-#if FANTASY_WEBGL
- var entityDictionary = Pool>.Rent();
-#else
- var entityDictionary = MultiThreadPool.Rent>();
-#endif
- entityDictionary._isDispose = false;
- entityDictionary._isPool = true;
- return entityDictionary;
- }
-
- ///
- /// 清空字典中的所有键值对,并释放值的资源。
- ///
- public new void Clear()
- {
- foreach (var keyValuePair in this)
- {
- keyValuePair.Value.Dispose();
- }
-
- base.Clear();
- }
-
- ///
- /// 清空字典中的所有键值对,但不释放值的资源。
- ///
- public void ClearNotDispose()
- {
- base.Clear();
- }
-
- ///
- /// 释放实例占用的资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/OneToManyDictionaryPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/OneToManyDictionaryPool.cs
deleted file mode 100644
index 3d47561..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/OneToManyDictionaryPool.cs
+++ /dev/null
@@ -1,247 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NBC.Pool;
-
-#pragma warning disable CS8603
-#pragma warning disable CS8601
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 一对多映射关系的字典对象池。
- ///
- /// 外部字典中的键类型。
- /// 内部字典中的键类型。
- /// 内部字典中的值类型。
- public class OneToManyDictionaryPool : OneToManyDictionary, IDisposable, IPool where TKey : notnull where TValueKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 的实例。
- ///
- /// 新创建的 OneToManyDictionaryPool 实例。
- public static OneToManyDictionaryPool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前实例及其资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 一对多映射关系的字典。每个键都对应一个内部字典,该内部字典将键值映射到相应的值。
- ///
- /// 外部字典中的键类型。
- /// 内部字典中的键类型。
- /// 内部字典中的值类型。
- public class OneToManyDictionary : Dictionary>
- where TKey : notnull where TValueKey : notnull
- {
- private readonly Queue> _queue = new Queue>();
- private readonly int _recyclingLimit = 120;
-
- ///
- /// 创建一个新的 实例。
- ///
- public OneToManyDictionary() { }
-
- ///
- /// 创建一个新的 实例,并指定最大缓存数量。
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public OneToManyDictionary(int recyclingLimit = 0)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 检查是否包含指定的键值对。
- ///
- /// 外部字典中的键。
- /// 内部字典中的键。
- /// 如果包含指定的键值对,则为 true;否则为 false。
- public bool Contains(TKey key, TValueKey valueKey)
- {
- TryGetValue(key, out var dic);
-
- return dic != null && dic.ContainsKey(valueKey);
- }
-
- ///
- /// 尝试获取指定键值对的值。
- ///
- /// 外部字典中的键。
- /// 内部字典中的键。
- /// 获取的值,如果操作成功,则为值;否则为默认值。
- /// 如果操作成功,则为 true;否则为 false。
- public bool TryGetValue(TKey key, TValueKey valueKey, out TValue value)
- {
- value = default;
- return TryGetValue(key, out var dic) && dic.TryGetValue(valueKey, out value);
- }
-
- ///
- /// 获取指定键的第一个值。
- ///
- /// 要获取第一个值的键。
- public TValue First(TKey key)
- {
- return !TryGetValue(key, out var dic) ? default : dic.First().Value;
- }
-
- ///
- /// 向字典中添加指定的键值对。
- ///
- /// 要添加键值对的键。
- /// 要添加键值对的内部字典键。
- /// 要添加的值。
- public void Add(TKey key, TValueKey valueKey, TValue value)
- {
- if (!TryGetValue(key, out var dic))
- {
- dic = Fetch();
- dic[valueKey] = value;
- // dic.Add(valueKey, value);
- Add(key, dic);
-
- return;
- }
-
- dic[valueKey] = value;
- // dic.Add(valueKey, value);
- }
-
- ///
- /// 从字典中移除指定的键值对。
- ///
- /// 要移除键值对的键。
- /// 要移除键值对的内部字典键。
- /// 如果成功移除键值对,则为 true;否则为 false。
- public bool Remove(TKey key, TValueKey valueKey)
- {
- if (!TryGetValue(key, out var dic)) return false;
-
- var result = dic.Remove(valueKey);
-
- if (dic.Count == 0) RemoveKey(key);
-
- return result;
- }
-
- ///
- /// 从字典中移除指定的键值对。
- ///
- /// 要移除键值对的键。
- /// 要移除键值对的内部字典键。
- /// 如果成功移除键值对,则为移除的值;否则为默认值。
- /// 如果成功移除键值对,则为 true;否则为 false。
- public bool Remove(TKey key, TValueKey valueKey, out TValue value)
- {
- if (!TryGetValue(key, out var dic))
- {
- value = default;
- return false;
- }
-
- var result = dic.TryGetValue(valueKey, out value);
-
- if (result) dic.Remove(valueKey);
-
- if (dic.Count == 0) RemoveKey(key);
-
- return result;
- }
-
- ///
- /// 移除字典中的指定键及其相关的所有键值对。
- ///
- /// 要移除的键。
- public void RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var dic)) return;
-
- Remove(key);
- Recycle(dic);
- }
-
- ///
- /// 从对象池中获取一个内部字典实例,如果池中没有,则创建一个新实例。
- ///
- /// 获取的内部字典实例。
- private Dictionary Fetch()
- {
- return _queue.Count <= 0 ? new Dictionary() : _queue.Dequeue();
- }
-
- ///
- /// 将不再使用的内部字典实例放回对象池中,以便后续重用。
- ///
- /// 要放回对象池的内部字典实例。
- private void Recycle(Dictionary dic)
- {
- dic.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit) return;
-
- _queue.Enqueue(dic);
- }
-
- ///
- /// 清空字典中的所有键值对,并将不再使用的内部字典实例放回对象池中。
- ///
- public new void Clear()
- {
- foreach (var keyValuePair in this) Recycle(keyValuePair.Value);
-
- base.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/OneToManySortedDictionaryPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/OneToManySortedDictionaryPool.cs
deleted file mode 100644
index c6208a7..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/OneToManySortedDictionaryPool.cs
+++ /dev/null
@@ -1,250 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-#pragma warning disable CS8601
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 一对多映射关系的排序字典对象池。
- ///
- /// 外部字典中的键类型。
- /// 内部字典中的排序键类型。
- /// 内部字典中的值类型。
- public class OneToManySortedDictionaryPool : OneToManySortedDictionary, IDisposable, IPool where TKey : notnull where TSortedKey : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个 的实例。
- ///
- /// 新创建的 OneToManySortedDictionaryPool 实例。
- public static OneToManySortedDictionaryPool Create()
- {
-#if FANTASY_WEBGL
- var a = Pool>.Rent();
-#else
- var a = MultiThreadPool.Rent>();
-#endif
- a._isDispose = false;
- a._isPool = true;
- return a;
- }
-
- ///
- /// 释放当前实例及其资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-
- ///
- /// 一对多映射关系的排序字典。每个外部键映射到一个内部排序字典,该内部排序字典将排序键映射到相应的值。
- ///
- /// 外部字典中的键类型。
- /// 内部字典中的排序键类型。
- /// 内部字典中的值类型。
- public class
- OneToManySortedDictionary : Dictionary>
- where TSortedKey : notnull where TKey : notnull
- {
- /// 缓存队列的回收限制
- private readonly int _recyclingLimit = 120;
- /// 缓存队列,用于存储已回收的内部排序字典
- private readonly Queue> _queue = new Queue>();
-
- ///
- /// 创建一个新的 实例。
- ///
- protected OneToManySortedDictionary() { }
-
- ///
- /// 创建一个新的 实例。设置最大缓存数量
- ///
- ///
- /// 1:防止数据量过大、所以超过recyclingLimit的数据还是走GC.
- /// 2:设置成0不控制数量,全部缓存
- ///
- public OneToManySortedDictionary(int recyclingLimit)
- {
- _recyclingLimit = recyclingLimit;
- }
-
- ///
- /// 检查字典是否包含指定的外部键。
- ///
- /// 要检查的外部键。
- /// 如果字典包含指定的外部键,则为 true;否则为 false。
- public bool Contains(TKey key)
- {
- return this.ContainsKey(key);
- }
-
- ///
- /// 检查字典是否包含指定的外部键和排序键。
- ///
- /// 要检查的外部键。
- /// 要检查的排序键。
- /// 如果字典包含指定的外部键和排序键,则为 true;否则为 false。
- public bool Contains(TKey key, TSortedKey sortedKey)
- {
- return TryGetValue(key, out var dic) && dic.ContainsKey(sortedKey);
- }
-
- ///
- /// 尝试从字典中获取指定外部键对应的内部排序字典。
- ///
- /// 要获取内部排序字典的外部键。
- /// 获取到的内部排序字典,如果找不到则为 null。
- /// 如果找到内部排序字典,则为 true;否则为 false。
- public new bool TryGetValue(TKey key, out SortedDictionary dic)
- {
- return base.TryGetValue(key, out dic);
- }
-
- ///
- /// 尝试从字典中获取指定外部键和排序键对应的值。
- ///
- /// 要获取值的外部键。
- /// 要获取值的排序键。
- /// 获取到的值,如果找不到则为 default。
- /// 如果找到值,则为 true;否则为 false。
- public bool TryGetValueBySortedKey(TKey key, TSortedKey sortedKey, out TValue value)
- {
- if (base.TryGetValue(key, out var dic))
- {
- return dic.TryGetValue(sortedKey, out value);
- }
-
- value = default;
- return false;
- }
-
- ///
- /// 向字典中添加一个值,关联到指定的外部键和排序键。
- ///
- /// 要关联值的外部键。
- /// 要关联值的排序键。
- /// 要添加的值。
- public void Add(TKey key, TSortedKey sortedKey, TValue value)
- {
- if (!TryGetValue(key, out var dic))
- {
- dic = Fetch();
- dic.Add(sortedKey, value);
- Add(key, dic);
-
- return;
- }
-
- dic.Add(sortedKey, value);
- }
-
- ///
- /// 从字典中移除指定外部键和排序键关联的值。
- ///
- /// 要移除值的外部键。
- /// 要移除值的排序键。
- /// 如果成功移除值,则为 true;否则为 false。
- public bool RemoveSortedKey(TKey key, TSortedKey sortedKey)
- {
- if (!TryGetValue(key, out var dic))
- {
- return false;
- }
-
- var isRemove = dic.Remove(sortedKey);
-
- if (dic.Count == 0)
- {
- isRemove = RemoveKey(key);
- }
-
- return isRemove;
- }
-
- ///
- /// 从字典中移除指定外部键及其关联的所有值。
- ///
- /// 要移除的外部键。
- /// 如果成功移除外部键及其关联的所有值,则为 true;否则为 false。
- public bool RemoveKey(TKey key)
- {
- if (!TryGetValue(key, out var list))
- {
- return false;
- }
-
- Remove(key);
- Recycle(list);
- return true;
- }
-
- ///
- /// 从缓存队列中获取一个内部排序字典。
- ///
- /// 一个内部排序字典。
- private SortedDictionary Fetch()
- {
- return _queue.Count <= 0 ? new SortedDictionary() : _queue.Dequeue();
- }
-
- ///
- /// 回收一个内部排序字典到缓存队列。
- ///
- /// 要回收的内部排序字典。
- private void Recycle(SortedDictionary dic)
- {
- dic.Clear();
-
- if (_recyclingLimit != 0 && _queue.Count > _recyclingLimit)
- {
- return;
- }
-
- _queue.Enqueue(dic);
- }
-
- ///
- /// 清空字典以及内部排序字典缓存队列,释放所有资源。
- ///
- protected new void Clear()
- {
- base.Clear();
- _queue.Clear();
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/ReuseDictionary.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/ReuseDictionary.cs
deleted file mode 100644
index 04fea5b..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/ReuseDictionary.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 提供一个可以重用的字典类,支持使用对象池管理。
- ///
- /// 字典中键的类型。
- /// 字典中值的类型。
- public sealed class ReuseDictionary : Dictionary, IDisposable, IPool where TM : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 创建一个新的 实例。
- ///
- /// 新创建的实例。
- public static ReuseDictionary Create()
- {
-#if FANTASY_WEBGL
- var entityDictionary = Pool>.Rent();
-#else
- var entityDictionary = MultiThreadPool.Rent>();
-#endif
- entityDictionary._isDispose = false;
- entityDictionary._isPool = true;
- return entityDictionary;
- }
-
- ///
- /// 释放实例占用的资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/SortedDictionaryPool.cs b/FantasyNetTest/NBC/Core/DataStructure/Dictionary/SortedDictionaryPool.cs
deleted file mode 100644
index b774175..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/Dictionary/SortedDictionaryPool.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NBC.Pool;
-
-namespace NBC.DataStructure.Dictionary
-{
- ///
- /// 提供一个可以使用对象池管理的排序字典类。
- ///
- ///
- ///
- public sealed class SortedDictionaryPool : SortedDictionary, IDisposable, IPool where TM : notnull
- {
- private bool _isPool;
- private bool _isDispose;
-
- ///
- /// 释放实例占用的资源。
- ///
- public void Dispose()
- {
- if (_isDispose)
- {
- return;
- }
-
- _isDispose = true;
- Clear();
-#if FANTASY_WEBGL
- Pool>.Return(this);
-#else
- MultiThreadPool.Return(this);
-#endif
- }
-
- ///
- /// 创建一个新的 实例。
- ///
- /// 新创建的实例。
- public static SortedDictionaryPool Create()
- {
-#if FANTASY_WEBGL
- var dictionary = Pool>.Rent();
-#else
- var dictionary = MultiThreadPool.Rent>();
-#endif
- dictionary._isDispose = false;
- dictionary._isPool = true;
- return dictionary;
- }
-
- ///
- /// 获取一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public bool IsPool()
- {
- return _isPool;
- }
-
- ///
- /// 设置一个值,该值指示当前实例是否为对象池中的实例。
- ///
- ///
- public void SetIsPool(bool isPool)
- {
- _isPool = isPool;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueGenerics.cs b/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueGenerics.cs
deleted file mode 100644
index 4c1ae0e..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueGenerics.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-// ReSharper disable SwapViaDeconstruction
-// ReSharper disable UseIndexFromEndExpression
-// ReSharper disable ConvertToPrimaryConstructor
-using System;
-using System.Collections.Generic;
-#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
-
-#pragma warning disable CS8601 // Possible null reference assignment.
-namespace NBC.DataStructure.PriorityQueue
-{
- ///
- /// 优先队列
- ///
- /// 节点数据
- /// 排序的类型、
- public sealed class PriorityQueue where TPriority : IComparable
- {
- private readonly List> _heap;
-
- public PriorityQueue(int initialCapacity = 16)
- {
- _heap = new List>(initialCapacity);
- }
-
- public int Count => _heap.Count;
-
- public void Enqueue(TElement element, TPriority priority)
- {
- _heap.Add(new PriorityQueueItem(element, priority));
- HeapifyUp(_heap.Count - 1);
- }
-
- public TElement Dequeue()
- {
- if (_heap.Count == 0)
- {
- throw new InvalidOperationException("The queue is empty.");
- }
-
- var item = _heap[0];
- _heap[0] = _heap[_heap.Count - 1];
- _heap.RemoveAt(_heap.Count - 1);
- HeapifyDown(0);
- return item.Element;
- }
-
- public bool TryDequeue(out TElement element)
- {
- if (_heap.Count == 0)
- {
- element = default(TElement);
- return false;
- }
-
- element = Dequeue();
- return true;
- }
-
- public TElement Peek()
- {
- if (_heap.Count == 0)
- {
- throw new InvalidOperationException("The queue is empty.");
- }
- return _heap[0].Element;
- }
-
- // ReSharper disable once IdentifierTypo
- private void HeapifyUp(int index)
- {
- while (index > 0)
- {
- var parentIndex = (index - 1) / 2;
- if (_heap[index].Priority.CompareTo(_heap[parentIndex].Priority) >= 0)
- {
- break;
- }
- Swap(index, parentIndex);
- index = parentIndex;
- }
- }
-
- // ReSharper disable once IdentifierTypo
- private void HeapifyDown(int index)
- {
- var lastIndex = _heap.Count - 1;
- while (true)
- {
- var smallestIndex = index;
- var leftChildIndex = 2 * index + 1;
- var rightChildIndex = 2 * index + 2;
-
- if (leftChildIndex <= lastIndex && _heap[leftChildIndex].Priority.CompareTo(_heap[smallestIndex].Priority) < 0)
- {
- smallestIndex = leftChildIndex;
- }
-
- if (rightChildIndex <= lastIndex && _heap[rightChildIndex].Priority.CompareTo(_heap[smallestIndex].Priority) < 0)
- {
- smallestIndex = rightChildIndex;
- }
-
- if (smallestIndex == index)
- {
- break;
- }
-
- Swap(index, smallestIndex);
- index = smallestIndex;
- }
- }
-
- private void Swap(int index1, int index2)
- {
- var temp = _heap[index1];
- _heap[index1] = _heap[index2];
- _heap[index2] = temp;
- }
- }
-}
-
diff --git a/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueItem.cs b/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueItem.cs
deleted file mode 100644
index 754b313..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueItem.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// ReSharper disable ConvertToPrimaryConstructor
-// ReSharper disable SwapViaDeconstruction
-// ReSharper disable InconsistentNaming
-#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
-namespace NBC.DataStructure.PriorityQueue
-{
- public struct PriorityQueueItemUint
- {
- public T Element { get; set; }
- public uint Priority { get; set; }
-
- public PriorityQueueItemUint(T element, uint priority)
- {
- Element = element;
- Priority = priority;
- }
- }
-
- public struct PriorityQueueItem
- {
- public T Element { get; }
- public T1 Priority { get; }
-
- public PriorityQueueItem(T element, T1 priority)
- {
- Element = element;
- Priority = priority;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueSimple.cs b/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueSimple.cs
deleted file mode 100644
index 9841c06..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/PriorityQueue/PriorityQueueSimple.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-// ReSharper disable SwapViaDeconstruction
-// ReSharper disable UseIndexFromEndExpression
-// ReSharper disable ConvertToPrimaryConstructor
-using System;
-using System.Collections.Generic;
-#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
-#pragma warning disable CS8601 // Possible null reference assignment.
-namespace NBC.DataStructure.PriorityQueue
-{
- public sealed class PriorityQueue where T : IComparable
- {
- private readonly List _heap;
-
- public PriorityQueue(int initialCapacity = 16)
- {
- _heap = new List(initialCapacity);
- }
-
- public int Count => _heap.Count;
-
- public void Enqueue(T item)
- {
- _heap.Add(item);
- HeapifyUp(_heap.Count - 1);
- }
-
- public T Dequeue()
- {
- if (_heap.Count == 0)
- {
- throw new InvalidOperationException("The queue is empty.");
- }
-
- var item = _heap[0];
- var heapCount = _heap.Count - 1;
- _heap[0] = _heap[heapCount];
- _heap.RemoveAt(heapCount);
- HeapifyDown(0);
- return item;
- }
-
- public bool TryDequeue(out T item)
- {
- if (_heap.Count == 0)
- {
- item = default(T);
- return false;
- }
-
- item = Dequeue();
- return true;
- }
-
- public T Peek()
- {
- if (_heap.Count == 0)
- {
- throw new InvalidOperationException("The queue is empty.");
- }
- return _heap[0];
- }
-
- // ReSharper disable once IdentifierTypo
- private void HeapifyUp(int index)
- {
- while (index > 0)
- {
- var parentIndex = (index - 1) / 2;
- if (_heap[index].CompareTo(_heap[parentIndex]) >= 0)
- {
- break;
- }
- Swap(index, parentIndex);
- index = parentIndex;
- }
- }
-
- // ReSharper disable once IdentifierTypo
- private void HeapifyDown(int index)
- {
- var lastIndex = _heap.Count - 1;
- while (true)
- {
- var smallestIndex = index;
- var leftChildIndex = 2 * index + 1;
- var rightChildIndex = 2 * index + 2;
-
- if (leftChildIndex <= lastIndex && _heap[leftChildIndex].CompareTo(_heap[smallestIndex]) < 0)
- {
- smallestIndex = leftChildIndex;
- }
-
- if (rightChildIndex <= lastIndex && _heap[rightChildIndex].CompareTo(_heap[smallestIndex]) < 0)
- {
- smallestIndex = rightChildIndex;
- }
-
- if (smallestIndex == index)
- {
- break;
- }
-
- Swap(index, smallestIndex);
- index = smallestIndex;
- }
- }
-
- private void Swap(int index1, int index2)
- {
- var temp = _heap[index1];
- _heap[index1] = _heap[index2];
- _heap[index2] = temp;
- }
- }
-}
-
diff --git a/FantasyNetTest/NBC/Core/DataStructure/SkipTable/SkipTable.cs b/FantasyNetTest/NBC/Core/DataStructure/SkipTable/SkipTable.cs
deleted file mode 100644
index b4ca0c5..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/SkipTable/SkipTable.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-
-#pragma warning disable CS8602 // Dereference of a possibly null reference.
-#pragma warning disable CS8601 // Possible null reference assignment.
-#pragma warning disable CS8604 // Possible null reference argument.
-#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
-#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
-namespace NBC.DataStructure.SkipTable
-{
- ///
- /// 跳表数据结构(升序版)
- ///
- /// 跳表中存储的值的类型。
- public class SkipTable : SkipTableBase
- {
- ///
- /// 创建一个新的跳表实例。
- ///
- /// 跳表的最大层数。
- public SkipTable(int maxLayer = 8) : base(maxLayer) { }
-
- ///
- /// 向跳表中添加一个新节点。
- ///
- /// 节点的主排序键。
- /// 节点的副排序键。
- /// 节点的唯一键。
- /// 要添加的值。
- public override void Add(long sortKey, long viceKey, long key, TValue value)
- {
- var rLevel = 1;
-
- while (rLevel <= MaxLayer && Random.Next(3) == 0)
- {
- ++rLevel;
- }
-
- SkipTableNode cur = TopHeader, last = null;
-
- for (var layer = MaxLayer; layer >= 1; --layer)
- {
- // 节点有next节点,且 (next主键 < 插入主键) 或 (next主键 == 插入主键 且 next副键 < 插入副键)
- while (cur.Right != null && ((cur.Right.SortKey < sortKey) ||
- (cur.Right.SortKey == sortKey && cur.Right.ViceKey < viceKey)))
- {
- cur = cur.Right;
- }
-
- if (layer <= rLevel)
- {
- var currentRight = cur.Right;
-
- // 在当前层插入新节点
- cur.Right = new SkipTableNode(sortKey, viceKey, key, value, layer == 1 ? cur.Index + 1 : 0, cur, cur.Right, null);
-
- if (currentRight != null)
- {
- currentRight.Left = cur.Right;
- }
-
- if (last != null)
- {
- last.Down = cur.Right;
- }
-
- if (layer == 1)
- {
- // 更新索引信息
- cur.Right.Index = cur.Index + 1;
- Node.Add(key, cur.Right);
-
- SkipTableNode v = cur.Right.Right;
-
- while (v != null)
- {
- v.Index++;
- v = v.Right;
- }
- }
-
- last = cur.Right;
- }
-
- cur = cur.Down;
- }
- }
-
- ///
- /// 从跳表中移除一个节点。
- ///
- /// 节点的主排序键。
- /// 节点的副排序键。
- /// 节点的唯一键。
- /// 被移除的节点的值。
- /// 如果成功移除节点,则为 true;否则为 false。
- public override bool Remove(long sortKey, long viceKey, long key, out TValue value)
- {
- value = default;
- var seen = false;
- var cur = TopHeader;
-
- for (var layer = MaxLayer; layer >= 1; --layer)
- {
- // 先按照主键查找 再 按副键查找
- while (cur.Right != null && cur.Right.SortKey < sortKey && cur.Right.Key != key) cur = cur.Right;
- while (cur.Right != null && (cur.Right.SortKey == sortKey && cur.Right.ViceKey <= viceKey) &&
- cur.Right.Key != key) cur = cur.Right;
-
- var isFind = false;
- var currentCur = cur;
- SkipTableNode removeCur = null;
- // 如果当前不是要删除的节点、但主键和副键都一样、需要特殊处理下。
- if (cur.Right != null && cur.Right.Key == key)
- {
- isFind = true;
- removeCur = cur.Right;
- currentCur = cur;
- }
- else
- {
- // 先向左查找下
- var currentNode = cur.Left;
- while (currentNode != null && currentNode.SortKey == sortKey && currentNode.ViceKey == viceKey)
- {
- if (currentNode.Key == key)
- {
- isFind = true;
- removeCur = currentNode;
- currentCur = currentNode.Left;
- break;
- }
-
- currentNode = currentNode.Left;
- }
-
- // 再向右查找下
- if (!isFind)
- {
- currentNode = cur.Right;
- while (currentNode != null && currentNode.SortKey == sortKey && currentNode.ViceKey == viceKey)
- {
- if (currentNode.Key == key)
- {
- isFind = true;
- removeCur = currentNode;
- currentCur = currentNode.Left;
- break;
- }
-
- currentNode = currentNode.Right;
- }
- }
- }
-
- if (isFind && currentCur != null)
- {
- value = removeCur.Value;
- currentCur.Right = removeCur.Right;
-
- if (removeCur.Right != null)
- {
- removeCur.Right.Left = currentCur;
- removeCur.Right = null;
- }
-
- removeCur.Left = null;
- removeCur.Down = null;
- removeCur.Value = default;
-
- if (layer == 1)
- {
- var tempCur = currentCur.Right;
- while (tempCur != null)
- {
- tempCur.Index--;
- tempCur = tempCur.Right;
- }
-
- Node.Remove(removeCur.Key);
- }
-
- seen = true;
- }
-
- cur = cur.Down;
- }
-
- return seen;
- }
- }
-}
\ No newline at end of file
diff --git a/FantasyNetTest/NBC/Core/DataStructure/SkipTable/SkipTableBase.cs b/FantasyNetTest/NBC/Core/DataStructure/SkipTable/SkipTableBase.cs
deleted file mode 100644
index 86798d9..0000000
--- a/FantasyNetTest/NBC/Core/DataStructure/SkipTable/SkipTableBase.cs
+++ /dev/null
@@ -1,282 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using NBC.DataStructure.Collection;
-
-#pragma warning disable CS8601
-#pragma warning disable CS8603
-#pragma warning disable CS8625
-#pragma warning disable CS8604
-
-namespace NBC.DataStructure.SkipTable
-{
- ///
- /// 抽象的跳表基类,提供跳表的基本功能和操作。
- ///
- /// 跳表中存储的值的类型。
- public abstract class SkipTableBase : IEnumerable>
- {
- ///
- /// 跳表的最大层数
- ///
- public readonly int MaxLayer;
- ///
- /// 跳表的顶部头节点
- ///
- public readonly SkipTableNode TopHeader;
- ///
- /// 跳表的底部头节点
- ///
- public SkipTableNode BottomHeader;
- ///
- /// 跳表中节点的数量,使用了 Node 字典的计数
- ///
- public int Count => Node.Count;
- ///
- /// 用于生成随机数的随机数生成器
- ///
- protected readonly Random Random = new Random();
- ///
- /// 存储跳表节点的字典
- ///
- protected readonly Dictionary> Node = new();
- ///
- /// 用于辅助反向查找的栈
- ///
- protected readonly Stack> AntiFindStack = new Stack>();
-
- ///
- /// 初始化一个新的跳表实例。
- ///
- /// 跳表的最大层数,默认为 8。
- protected SkipTableBase(int maxLayer = 8)
- {
- MaxLayer = maxLayer;
- var cur = TopHeader = new SkipTableNode(long.MinValue, 0, 0, default, 0, null, null, null);
-
- for (var layer = MaxLayer - 1; layer >= 1; --layer)
- {
- cur.Down = new SkipTableNode