diff --git a/.editorconfig b/.editorconfig
index 31aad27..571f3cc 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -5,3 +5,113 @@ dotnet_diagnostic.IDE0051.severity = none
# IDE0052: 删除未读的私有成员
dotnet_diagnostic.IDE0052.severity = none
+end_of_line = crlf
+dotnet_style_qualification_for_field = false:silent
+dotnet_style_qualification_for_property = false:silent
+dotnet_style_qualification_for_method = false:silent
+
+[*.cs]
+#### 命名样式 ####
+
+# 命名规则
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# 符号规范
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# 命名样式
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+csharp_using_directive_placement = outside_namespace:silent
+csharp_style_expression_bodied_methods = false:silent
+csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_properties = true:silent
+csharp_style_expression_bodied_indexers = true:silent
+csharp_style_expression_bodied_accessors = true:silent
+csharp_style_expression_bodied_lambdas = true:silent
+csharp_style_expression_bodied_local_functions = false:silent
+csharp_style_conditional_delegate_call = true:suggestion
+
+[*.vb]
+#### 命名样式 ####
+
+# 命名规则
+
+dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion
+dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface
+dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始
+
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
+
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
+
+# 符号规范
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.类型.required_modifiers =
+
+dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
+dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.非字段成员.required_modifiers =
+
+# 命名样式
+
+dotnet_naming_style.以_i_开始.required_prefix = I
+dotnet_naming_style.以_i_开始.required_suffix =
+dotnet_naming_style.以_i_开始.word_separator =
+dotnet_naming_style.以_i_开始.capitalization = pascal_case
+
+dotnet_naming_style.帕斯卡拼写法.required_prefix =
+dotnet_naming_style.帕斯卡拼写法.required_suffix =
+dotnet_naming_style.帕斯卡拼写法.word_separator =
+dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
+
+dotnet_naming_style.帕斯卡拼写法.required_prefix =
+dotnet_naming_style.帕斯卡拼写法.required_suffix =
+dotnet_naming_style.帕斯卡拼写法.word_separator =
+dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
diff --git a/TYLDDB.Parser.Test/Program.cs b/TYLDDB.Parser.Test/Program.cs
deleted file mode 100644
index fc62551..0000000
--- a/TYLDDB.Parser.Test/Program.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using TimeRecord;
-using TYLDDB.Parser;
-
-string content = @"
-string::""str_name""=""name1"";
-int::""int_value""=""123"";
-short::""short_value""=""32767"";
-long::""long_value""=""2147483647"";
-float::""float_value""=""3.14f"";
-double::""double_value""=""3.141592653589793"";
-boolean::""bool""=""true"";
-char::""char_value""=""127"";
-decimal::decima_value = 19.99m"";
-internaldb::""db_name""={};
-";
-
-var parser = new Parser();
-var time = new HighPrecisionTimer();
-time.Start();
-// 调用 Parse 方法进行解析
-var result = Parser.ParseString(content);
-time.Stop();
-// 输出找到的所有键值对
-if (result.Count > 0)
-{
- foreach (var entry in result)
- {
- Console.WriteLine($"{entry.Key}: {entry.Value}");
- }
-}
-
-Console.WriteLine($"Time: {time.ElapsedMilliseconds()}ms");
-Console.ReadLine();
\ No newline at end of file
diff --git a/TYLDDB.Parser.Test/TYLDDB.Parser.Test.csproj b/TYLDDB.Parser.Test/TYLDDB.Parser.Test.csproj
deleted file mode 100644
index 700866e..0000000
--- a/TYLDDB.Parser.Test/TYLDDB.Parser.Test.csproj
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- Exe
- net8.0
- enable
- enable
-
-
-
-
-
-
-
-
diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs
index 9158a16..ada0a5c 100644
--- a/TYLDDB.Test/Program.cs
+++ b/TYLDDB.Test/Program.cs
@@ -2,6 +2,7 @@
using TYLDDB;
string dbFilePath = "./example.lddb";
+List testData = [];
///////////////////////////////////////////////////////////////////////////////////////////////////////// 实例化
var lddb = new LDDB();
@@ -20,7 +21,14 @@
lddb.LoadDatabase("database1");
Console.WriteLine(lddb.GetLoadingDatabaseContent()); // 输出database1内容
loadDbTimer.Stop();
-WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为: ", loadDbTimer.ElapsedMilliseconds());
+WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为(V1): ", loadDbTimer.ElapsedMilliseconds());
+
+HighPrecisionTimer loadDbV2Timer = new(); // 从发起读取数据库到成功返回读取内容的总时间
+loadDbV2Timer.Start();
+lddb.LoadDatabase_V2("database1");
+Console.WriteLine(lddb.GetLoadingDatabaseContent()); // 输出database1内容
+loadDbV2Timer.Stop();
+WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为(V2): ", loadDbV2Timer.ElapsedMilliseconds());
///////////////////////////////////////////////////////////////////////////////////////////////////////// 获取所有数据库名称
HighPrecisionTimer readAllDbNameTimer = new(); // 从发起读取数据库名称到成功返回读取内容的总时间
@@ -37,11 +45,48 @@
WriteTime("从发起读取数据库名称到成功返回读取内容的总时间为: ", readAllDbNameTimer.ElapsedMilliseconds());
///////////////////////////////////////////////////////////////////////////////////////////////////////// 数据库解析缓存
-HighPrecisionTimer parseDbTimer = new(); // 从发起解析文件到成功解析并写入缓存的总时间
+HighPrecisionTimer parseDbTimer = new(); // 从发起解析文件到成功解析并写入缓存的总时间(同步)
parseDbTimer.Start();
-await lddb.ParseAsync();
+await lddb.Parse();
parseDbTimer.Stop();
-WriteTime("从发起解析文件到成功解析并写入缓存的总时间: ", parseDbTimer.ElapsedMilliseconds());
+WriteTime("从发起解析文件到成功解析并写入缓存的总时间(同步): ", parseDbTimer.ElapsedMilliseconds());
+HighPrecisionTimer parseDbTimerAsync = new(); // 从发起解析文件到成功解析并写入缓存的总时间(异步)
+parseDbTimerAsync.Start();
+await lddb.ParseAsync();
+parseDbTimerAsync.Stop();
+WriteTime("从发起解析文件到成功解析并写入缓存的总时间(异步): ", parseDbTimerAsync.ElapsedMilliseconds());
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////// 并发词典数据库全类型同步搜寻
+HighPrecisionTimer allTypeSearchFromConcurrentDictionaryTimer = new();
+allTypeSearchFromConcurrentDictionaryTimer.Start();
+string[] AllTypeSearchFromConcurrentDictionaryResult = lddb.AllTypeSearchFromConcurrentDictionary("str_name");
+allTypeSearchFromConcurrentDictionaryTimer.Stop();
+// 使用 foreach 输出数组的每个元素
+foreach (var str in AllTypeSearchFromConcurrentDictionaryResult)
+{
+ Console.WriteLine(str);
+}
+WriteTime("并发词典数据库全类型同步搜寻: ", allTypeSearchFromConcurrentDictionaryTimer.ElapsedMilliseconds());
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////// 信号量线程锁词典数据库全类型同步搜寻
+HighPrecisionTimer allTypeSearchFromSemaphoreThreadLockTimer = new();
+allTypeSearchFromSemaphoreThreadLockTimer.Start();
+string[] AllTypeSearchFromSemaphoreThreadLockResult = lddb.AllTypeSearchFromSemaphoreThreadLock("str_name");
+allTypeSearchFromSemaphoreThreadLockTimer.Stop();
+// 使用 foreach 输出数组的每个元素
+foreach (var str in AllTypeSearchFromSemaphoreThreadLockResult)
+{
+ Console.WriteLine(str);
+}
+WriteTime("信号量线程锁词典数据库全类型同步搜寻: ", allTypeSearchFromSemaphoreThreadLockTimer.ElapsedMilliseconds());
+
+
+
+
+
+
+
+
@@ -54,13 +99,45 @@
+
+
+
+ExportTestData();
Console.ReadLine();
////////////////////////////////////////////////////////////////////////////////////////////////////////// Test Method
///////////////////////////////////////////////////////////////////////////////////////////////////////// 工具
-static void WriteTime(string what, double time)
+void WriteTime(string what, double time)
{
- Console.WriteLine(what + time + "ms\n");
+ string data = what + time + "ms\n";
+ Console.WriteLine(data);
+ AddTestData(data);
Console.WriteLine();
}
+
+void AddTestData(string data)
+{
+ testData.Add(data);
+}
+
+void ExportTestData()
+{
+ // 获取当前日期和时间,格式化为 "yyyy-MM-dd HH-mm"
+ string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm") + ".txt";
+
+ // 指定文件路径
+ string directoryPath = "./testdata/";
+ string filePath = Path.Combine(directoryPath, fileName);
+
+ // 确保目录存在,如果不存在则创建
+ if (!Directory.Exists(directoryPath))
+ {
+ Directory.CreateDirectory(directoryPath);
+ }
+
+ // 将 List 中的每一行写入文件
+ File.WriteAllLines(filePath, testData);
+
+ Console.WriteLine($"数据已成功写入文件: {filePath}");
+}
diff --git a/TYLDDB.Test/TYLDDB.Test.csproj b/TYLDDB.Test/TYLDDB.Test.csproj
index 1f5fc44..7b6fdbd 100644
--- a/TYLDDB.Test/TYLDDB.Test.csproj
+++ b/TYLDDB.Test/TYLDDB.Test.csproj
@@ -5,6 +5,8 @@
net8.0
enable
enable
+ True
+ False
diff --git a/TYLDDB.Test/example.lddb b/TYLDDB.Test/example.lddb
index d895a31..0f79eeb 100644
--- a/TYLDDB.Test/example.lddb
+++ b/TYLDDB.Test/example.lddb
@@ -1,14 +1,13 @@
database1::{
- string::"str_name"="name1";
+ string::"str_name"="name1 space test";
int::"int_value"="123";
short::"short_value"="32767";
long::"long_value"="2147483647";
- float::"float_value"="3.14f";
+ float::"float_value"="3.14";
double::"double_value"="3.141592653589793";
boolean::"bool"="true";
- char::"char_value"="127";
- decimal::decima_value = 19.99m";
- internaldb::"db_name"={};
+ char::"char_value"="A";
+ decimal::decimal_value = 19.99";
distributeddb::"distributed_db_name"="./example.lddb";
};
database2::{
@@ -20,7 +19,7 @@ database2::{
double::"double_value"="3.141592653589793"
boolean::"bool"="true"
char::"char_value"="127"
- decimal::decima_value = 19.99m"
+ decimal::decimal_value = 19.99m"
internaldb::"db_name"={};
distributeddb::"distributed_db_name"="./example.lddb";
};
diff --git a/TYLDDB.Utils.Writer.Test/Program.cs b/TYLDDB.Utils.Writer.Test/Program.cs
deleted file mode 100644
index 2e269e1..0000000
--- a/TYLDDB.Utils.Writer.Test/Program.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using TimeRecord;
-using TYLDDB.Utils;
-
-string largeString = new('A', 1);
-string syncFilePath = "sync.txt";
-string asyncFilePath = "async.txt";
-string syncChunkFilePath = "sync-chunk.txt";
-string asyncChunkFilePath = "async-chunk.txt";
-
-var syncTime = new HighPrecisionTimer();
-var asyncTime = new HighPrecisionTimer();
-var syncChunkTime = new HighPrecisionTimer();
-var asyncChunkTime = new HighPrecisionTimer();
-
-syncTime.Start();
-Writer.WriteStringToFile(syncFilePath, largeString);
-syncTime.Stop();
-
-asyncTime.Start();
-await Writer.WriteStringToFileAsync(asyncFilePath, largeString);
-asyncTime.Stop();
-
-syncChunkTime.Start();
-Writer.WriteStringToFileInChunks(syncChunkFilePath, largeString);
-syncChunkTime.Stop();
-
-asyncChunkTime.Start();
-await Writer.WriteStringToFileInChunksAsync(asyncChunkFilePath, largeString);
-asyncChunkTime.Stop();
-
-Console.WriteLine("测试结果:");
-Console.WriteLine($"同步写入:{syncTime.ElapsedMilliseconds()}ms");
-Console.WriteLine($"异步写入:{asyncTime.ElapsedMilliseconds()}ms");
-Console.WriteLine($"同步分块写入:{syncChunkTime.ElapsedMilliseconds()}ms");
-Console.WriteLine($"异步分块写入:{asyncChunkTime.ElapsedMilliseconds()}ms");
-
-Console.ReadLine();
diff --git a/TYLDDB.Utils.Writer.Test/TYLDDB.Utils.Writer.Test.csproj b/TYLDDB.Utils.Writer.Test/TYLDDB.Utils.Writer.Test.csproj
deleted file mode 100644
index 700866e..0000000
--- a/TYLDDB.Utils.Writer.Test/TYLDDB.Utils.Writer.Test.csproj
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- Exe
- net8.0
- enable
- enable
-
-
-
-
-
-
-
-
diff --git a/TYLDDB/Parser/Parser.cs b/TYLDDB/Parser/Parser.cs
index 02c995b..a0d522d 100644
--- a/TYLDDB/Parser/Parser.cs
+++ b/TYLDDB/Parser/Parser.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
+using System.Threading.Tasks;
namespace TYLDDB.Parser
{
@@ -11,7 +12,7 @@ namespace TYLDDB.Parser
public class DataParser
{
// 定义正则表达式来匹配键值对(类型::"key"="value")
- private readonly static string pattern = @"(?<=^|\s)(\w+)\s*::\s*""([^""]+)""";
+ private readonly static string pattern = @"(\w+)\s*::\s*""([^""]+)""\s*=\s*""([^""]+)"";";
///
/// Parses the given content and finds all matching key-value pairs.
@@ -32,11 +33,12 @@ public static Dictionary ParseString(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配,加入到结果字典
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 将匹配的键值对添加到字典中
result[matchedKey] = matchedValue;
@@ -47,6 +49,14 @@ public static Dictionary ParseString(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseStringAsync(string content) => Task.FromResult(ParseString(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -66,11 +76,12 @@ public static Dictionary ParseInt(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value; // 这是类型,比如 int, short, long
+ string matchedKey = match.Groups[2].Value; // 这是键,比如 int_value, string_value
+ string matchedValue = match.Groups[3].Value; // 这是值的字符串部分,比如 "123", "32767"
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 int 类型
if (int.TryParse(matchedValue, out int intValue))
@@ -89,6 +100,14 @@ public static Dictionary ParseInt(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseIntAsync(string content) => Task.FromResult(ParseInt(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -108,11 +127,12 @@ public static Dictionary ParseShort(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 short 类型
if (short.TryParse(matchedValue, out short shortValue))
@@ -131,6 +151,14 @@ public static Dictionary ParseShort(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseShortAsync(string content) => Task.FromResult(ParseShort(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -150,11 +178,12 @@ public static Dictionary ParseLong(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 long 类型
if (long.TryParse(matchedValue, out long longValue))
@@ -173,6 +202,14 @@ public static Dictionary ParseLong(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseLongAsync(string content) => Task.FromResult(ParseLong(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -192,11 +229,12 @@ public static Dictionary ParseFloat(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 short 类型
if (float.TryParse(matchedValue, out float floatValue))
@@ -215,6 +253,14 @@ public static Dictionary ParseFloat(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseFloatAsync(string content) => Task.FromResult(ParseFloat(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -234,11 +280,12 @@ public static Dictionary ParseDouble(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 short 类型
if (double.TryParse(matchedValue, out double Value))
@@ -257,6 +304,14 @@ public static Dictionary ParseDouble(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseDoubleAsync(string content) => Task.FromResult(ParseDouble(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -276,11 +331,12 @@ public static Dictionary ParseBoolean(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 short 类型
if (bool.TryParse(matchedValue, out bool Value))
@@ -299,6 +355,14 @@ public static Dictionary ParseBoolean(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseBooleanAsync(string content) => Task.FromResult(ParseBoolean(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -318,11 +382,12 @@ public static Dictionary ParseChar(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 short 类型
if (char.TryParse(matchedValue, out char Value))
@@ -341,6 +406,14 @@ public static Dictionary ParseChar(string content)
return result;
}
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseCharAsync(string content) => Task.FromResult(ParseChar(content));
+
///
/// Parses the given content and finds all matching key-value pairs.
/// 解析给定的内容并查找所有匹配的键值对。
@@ -360,11 +433,12 @@ public static Dictionary ParseDecimal(string content)
// 遍历所有的匹配项
foreach (Match match in matches)
{
- string matchedKey = match.Groups[1].Value;
- string matchedValue = match.Groups[2].Value;
+ string matchedType = match.Groups[1].Value;
+ string matchedKey = match.Groups[2].Value;
+ string matchedValue = match.Groups[3].Value;
// 如果提供的类型与键的类型匹配
- if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(type, matchedType, StringComparison.OrdinalIgnoreCase))
{
// 尝试将值转换为 short 类型
if (decimal.TryParse(matchedValue, out decimal Value))
@@ -382,5 +456,13 @@ public static Dictionary ParseDecimal(string content)
// 返回结果字典,若没有匹配项则返回空字典
return result;
}
+
+ ///
+ /// Parses the given content and finds all matching key-value pairs.
+ /// 解析给定的内容并查找所有匹配的键值对。
+ ///
+ /// The content string to be parsed, containing key-value pairs.
要解析的内容字符串,包含键值对。
+ /// A dictionary containing all matched key-value pairs. If no matching key-value pair is found, an empty dictionary is returned.
包含所有匹配的键值对的字典。如果没有找到匹配的键值对,返回空字典。
+ public static Task> ParseDecimalAsync(string content) => Task.FromResult(ParseDecimal(content));
}
}
diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs
index 5370b06..e04cf39 100644
--- a/TYLDDB/TYLDDB.cs
+++ b/TYLDDB/TYLDDB.cs
@@ -1,8 +1,10 @@
using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using TYLDDB.Basic;
using TYLDDB.Parser;
using TYLDDB.Utils;
+using TYLDDB.Utils.Database;
using TYLDDB.Utils.FastCache.ConcurrentDictionary;
using TYLDDB.Utils.FastCache.SemaphoreThreadLock;
@@ -20,7 +22,9 @@ public class LDDB
///
public LDDB()
{
- database = new Database(); // 实例化数据库操作类
+ // 实例化数据库操作类
+ database_v1 = new Database_V1();
+ database_v2 = new Database_V2();
// 实例化并发词典
cdStringDictionary = new CdStringDictionary();
@@ -48,10 +52,9 @@ public LDDB()
///////////////////////////////////////////////////// 私有字段
private string _filePath; // 存储文件路径
private string _fileContent; // 存储文件内容
- private string _database; // 存储正在访问的数据库
private string _databaseContent; // 存储数据库内容
- private bool _isRead = false; // 是否已调用读取文件
- private Database database;
+ private Database_V1 database_v1;
+ private Database_V2 database_v2;
private CdStringDictionary cdStringDictionary;
private CdShortDictionary cdShortDictionary;
private CdLongDictionary cdLongDictionary;
@@ -90,6 +93,7 @@ public string FilePath
}
}
}
+
///
/// Names of all databases in the current file
/// 当前文件内所有数据库的名称
@@ -116,10 +120,17 @@ private static bool ValidateFilePath(string path)
/// Read the contents from the file
/// 从文件中读取内容
///
- public void ReadingFile()
+ public void ReadingFile() => _fileContent = Reader.ReadFile(FilePath);
+
+ ///
+ /// Set the database to load
+ /// 设置要加载的数据库
+ ///
+ /// name of the database
数据库名称
+ public void LoadDatabase(string db)
{
- _fileContent = Reader.ReadFile(FilePath);
- _isRead = true;
+ ReadingFile();
+ _databaseContent = database_v1.GetDatabaseContent(_fileContent, db);
}
///
@@ -127,19 +138,10 @@ public void ReadingFile()
/// 设置要加载的数据库
///
/// name of the database
数据库名称
- public async void LoadDatabase(string db)
+ public void LoadDatabase_V2(string db)
{
- switch (_isRead)
- {
- case true:
- _databaseContent = database.GetDatabaseContent(_fileContent, db);
- break;
- default:
- ReadingFile();
- _databaseContent = database.GetDatabaseContent(_fileContent, db);
- break;
- }
- await ParseAsync();
+ ReadingFile();
+ _databaseContent = database_v2.GetDatabaseContent(_fileContent, db);
}
///
@@ -152,7 +154,314 @@ public async void LoadDatabase(string db)
/// Read the names of all databases
/// 读取全部数据库的名称
///
- public void ReadAllDatabaseName() => AllDatabaseName = database.GetDatabaseList(_fileContent);
+ public void ReadAllDatabaseName() => AllDatabaseName = database_v1.GetDatabaseList(_fileContent);
+
+ ///
+ /// Reparse the entire database.
+ /// 重新解析整个数据库。
+ ///
+ public async Task Parse()
+ {
+ // 创建多个任务,并使用 LongRunning 来确保每个任务在独立线程中运行
+
+ // ConcurrentDictionary
+ Task cdStringCacheTask = Task.Factory.StartNew(() => CdString(), TaskCreationOptions.LongRunning);
+ Task cdIntCacheTask = Task.Factory.StartNew(() => CdInt(), TaskCreationOptions.LongRunning);
+ Task cdShortCacheTask = Task.Factory.StartNew(() => CdShort(), TaskCreationOptions.LongRunning);
+ Task cdLongCacheTask = Task.Factory.StartNew(() => CdLong(), TaskCreationOptions.LongRunning);
+ Task cdFloatCacheTask = Task.Factory.StartNew(() => CdFloat(), TaskCreationOptions.LongRunning);
+ Task cdDoubleCacheTask = Task.Factory.StartNew(() => CdDouble(), TaskCreationOptions.LongRunning);
+ Task cdDecimalCacheTask = Task.Factory.StartNew(() => CdDecimal(), TaskCreationOptions.LongRunning);
+ Task cdCharCacheTask = Task.Factory.StartNew(() => CdChar(), TaskCreationOptions.LongRunning);
+ Task cdBoolCacheTask = Task.Factory.StartNew(() => CdBool(), TaskCreationOptions.LongRunning);
+
+ // SemaphoreThreadLock
+ Task stlStringCacheTask = Task.Factory.StartNew(() => StlString(), TaskCreationOptions.LongRunning);
+ Task stlIntCacheTask = Task.Factory.StartNew(() => StlInt(), TaskCreationOptions.LongRunning);
+ Task stlShortCacheTask = Task.Factory.StartNew(() => StlShort(), TaskCreationOptions.LongRunning);
+ Task stlLongCacheTask = Task.Factory.StartNew(() => StlLong(), TaskCreationOptions.LongRunning);
+ Task stlFloatCacheTask = Task.Factory.StartNew(() => StlFloat(), TaskCreationOptions.LongRunning);
+ Task stlDoubleCacheTask = Task.Factory.StartNew(() => StlDouble(), TaskCreationOptions.LongRunning);
+ Task stlDecimalCacheTask = Task.Factory.StartNew(() => StlDecimal(), TaskCreationOptions.LongRunning);
+ Task stlCharCacheTask = Task.Factory.StartNew(() => StlChar(), TaskCreationOptions.LongRunning);
+ Task stlBoolCacheTask = Task.Factory.StartNew(() => StlBool(), TaskCreationOptions.LongRunning);
+
+ // 等待所有任务完成
+ await Task.WhenAll(cdStringCacheTask,
+ cdIntCacheTask,
+ cdShortCacheTask,
+ cdLongCacheTask,
+ cdFloatCacheTask,
+ cdDoubleCacheTask,
+ cdDecimalCacheTask,
+ cdCharCacheTask,
+ cdBoolCacheTask,
+ stlStringCacheTask,
+ stlIntCacheTask,
+ stlShortCacheTask,
+ stlLongCacheTask,
+ stlFloatCacheTask,
+ stlDoubleCacheTask,
+ stlDecimalCacheTask,
+ stlCharCacheTask,
+ stlBoolCacheTask);
+
+ // ConcurrentDictionary
+ void CdString()
+ {
+ var dict = DataParser.ParseString(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdStringDictionary.Set(key, value);
+ }
+ }
+ void CdShort()
+ {
+ var dict = DataParser.ParseShort(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdShortDictionary.Set(key, value);
+ }
+ }
+ void CdLong()
+ {
+ var dict = DataParser.ParseLong(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdLongDictionary.Set(key, value);
+ }
+ }
+ void CdInt()
+ {
+ var dict = DataParser.ParseInt(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdIntegerDictionary.Set(key, value);
+ }
+ }
+ void CdFloat()
+ {
+ var dict = DataParser.ParseFloat(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdFloatDictionary.Set(key, value);
+ }
+ }
+ void CdDouble()
+ {
+ var dict = DataParser.ParseDouble(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdDoubleDictionary.Set(key, value);
+ }
+ }
+ void CdDecimal()
+ {
+ var dict = DataParser.ParseDecimal(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdDecimalDictionary.Set(key, value);
+ }
+ }
+ void CdChar()
+ {
+ var dict = DataParser.ParseChar(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdCharDictionary.Set(key, value);
+ }
+ }
+ void CdBool()
+ {
+ var dict = DataParser.ParseBoolean(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ cdBooleanDictionary.Set(key, value);
+ }
+ }
+
+ // SemaphoreThreadLock
+ void StlString()
+ {
+ var dict = DataParser.ParseString(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlStringDictionary.Set(key, value);
+ }
+ }
+ void StlShort()
+ {
+ var dict = DataParser.ParseShort(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlShortDictionary.Set(key, value);
+ }
+ }
+ void StlLong()
+ {
+ var dict = DataParser.ParseLong(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlLongDictionary.Set(key, value);
+ }
+ }
+ void StlInt()
+ {
+ var dict = DataParser.ParseInt(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlIntegerDictionary.Set(key, value);
+ }
+ }
+ void StlFloat()
+ {
+ var dict = DataParser.ParseFloat(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlFloatDictionary.Set(key, value);
+ }
+ }
+ void StlDouble()
+ {
+ var dict = DataParser.ParseDouble(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlDoubleDictionary.Set(key, value);
+ }
+ }
+ void StlDecimal()
+ {
+ var dict = DataParser.ParseDecimal(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlDecimalDictionary.Set(key, value);
+ }
+ }
+ void StlChar()
+ {
+ var dict = DataParser.ParseChar(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlCharDictionary.Set(key, value);
+ }
+ }
+ void StlBool()
+ {
+ var dict = DataParser.ParseBoolean(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ stlBooleanDictionary.Set(key, value);
+ }
+ }
+ }
///
/// Reparse the entire database.
@@ -161,13 +470,50 @@ public async void LoadDatabase(string db)
public async Task ParseAsync()
{
// 创建多个任务,并使用 LongRunning 来确保每个任务在独立线程中运行
+
+ // ConcurrentDictionary
Task cdStringCacheTask = Task.Factory.StartNew(() => CdString(), TaskCreationOptions.LongRunning);
- //Task cdIntCacheTask = Task.Factory.StartNew(() => CdInt(), TaskCreationOptions.LongRunning);
- //Task cdShortCacheTask = Task.Factory.StartNew(() => CdShort(), TaskCreationOptions.LongRunning);
+ Task cdIntCacheTask = Task.Factory.StartNew(() => CdInt(), TaskCreationOptions.LongRunning);
+ Task cdShortCacheTask = Task.Factory.StartNew(() => CdShort(), TaskCreationOptions.LongRunning);
+ Task cdLongCacheTask = Task.Factory.StartNew(() => CdLong(), TaskCreationOptions.LongRunning);
+ Task cdFloatCacheTask = Task.Factory.StartNew(() => CdFloat(), TaskCreationOptions.LongRunning);
+ Task cdDoubleCacheTask = Task.Factory.StartNew(() => CdDouble(), TaskCreationOptions.LongRunning);
+ Task cdDecimalCacheTask = Task.Factory.StartNew(() => CdDecimal(), TaskCreationOptions.LongRunning);
+ Task cdCharCacheTask = Task.Factory.StartNew(() => CdChar(), TaskCreationOptions.LongRunning);
+ Task cdBoolCacheTask = Task.Factory.StartNew(() => CdBool(), TaskCreationOptions.LongRunning);
+
+ // SemaphoreThreadLock
+ Task stlStringCacheTask = Task.Factory.StartNew(() => StlString(), TaskCreationOptions.LongRunning);
+ Task stlIntCacheTask = Task.Factory.StartNew(() => StlInt(), TaskCreationOptions.LongRunning);
+ Task stlShortCacheTask = Task.Factory.StartNew(() => StlShort(), TaskCreationOptions.LongRunning);
+ Task stlLongCacheTask = Task.Factory.StartNew(() => StlLong(), TaskCreationOptions.LongRunning);
+ Task stlFloatCacheTask = Task.Factory.StartNew(() => StlFloat(), TaskCreationOptions.LongRunning);
+ Task stlDoubleCacheTask = Task.Factory.StartNew(() => StlDouble(), TaskCreationOptions.LongRunning);
+ Task stlDecimalCacheTask = Task.Factory.StartNew(() => StlDecimal(), TaskCreationOptions.LongRunning);
+ Task stlCharCacheTask = Task.Factory.StartNew(() => StlChar(), TaskCreationOptions.LongRunning);
+ Task stlBoolCacheTask = Task.Factory.StartNew(() => StlBool(), TaskCreationOptions.LongRunning);
// 等待所有任务完成
- await Task.WhenAll(cdStringCacheTask);
+ await Task.WhenAll(cdStringCacheTask,
+ cdIntCacheTask,
+ cdShortCacheTask,
+ cdLongCacheTask,
+ cdFloatCacheTask,
+ cdDoubleCacheTask,
+ cdDecimalCacheTask,
+ cdCharCacheTask,
+ cdBoolCacheTask,
+ stlStringCacheTask,
+ stlIntCacheTask,
+ stlShortCacheTask,
+ stlLongCacheTask,
+ stlFloatCacheTask,
+ stlDoubleCacheTask,
+ stlDecimalCacheTask,
+ stlCharCacheTask,
+ stlBoolCacheTask);
+ // ConcurrentDictionary
async void CdString()
{
var dict = DataParser.ParseString(_databaseContent);
@@ -182,6 +528,300 @@ async void CdString()
await cdStringDictionary.SetAsync(key, value);
}
}
+ async void CdShort()
+ {
+ var dict = DataParser.ParseShort(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdShortDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdLong()
+ {
+ var dict = DataParser.ParseLong(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdLongDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdInt()
+ {
+ var dict = DataParser.ParseInt(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdIntegerDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdFloat()
+ {
+ var dict = DataParser.ParseFloat(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdFloatDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdDouble()
+ {
+ var dict = DataParser.ParseDouble(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdDoubleDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdDecimal()
+ {
+ var dict = DataParser.ParseDecimal(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdDecimalDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdChar()
+ {
+ var dict = DataParser.ParseChar(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdCharDictionary.SetAsync(key, value);
+ }
+ }
+ async void CdBool()
+ {
+ var dict = DataParser.ParseBoolean(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await cdBooleanDictionary.SetAsync(key, value);
+ }
+ }
+
+ // SemaphoreThreadLock
+ async void StlString()
+ {
+ var dict = DataParser.ParseString(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlStringDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlShort()
+ {
+ var dict = DataParser.ParseShort(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlShortDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlLong()
+ {
+ var dict = DataParser.ParseLong(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlLongDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlInt()
+ {
+ var dict = DataParser.ParseInt(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlIntegerDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlFloat()
+ {
+ var dict = DataParser.ParseFloat(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlFloatDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlDouble()
+ {
+ var dict = DataParser.ParseDouble(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlDoubleDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlDecimal()
+ {
+ var dict = DataParser.ParseDecimal(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlDecimalDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlChar()
+ {
+ var dict = DataParser.ParseChar(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlCharDictionary.SetAsync(key, value);
+ }
+ }
+ async void StlBool()
+ {
+ var dict = DataParser.ParseBoolean(_databaseContent);
+
+ // 遍历 dict 中的每一项
+ foreach (var kvp in dict)
+ {
+ var key = kvp.Key; // 获取第一个值 (key)
+ var value = kvp.Value; // 获取第二个值 (value)
+
+ // 将 key-value 对存储到缓存
+ await stlBooleanDictionary.SetAsync(key, value);
+ }
+ }
+ }
+
+ ///
+ /// Finds the value associated with a given key from multiple types of concurrent dictionaries and returns all non-empty values as an array of strings.
+ /// 从多个类型的并发词典中查找与给定键相关的值,并将所有非空的值以字符串数组的形式返回。
+ ///
+ /// The key used to find. Method looks up the corresponding value from multiple dictionaries based on this key.
用于查找的键。方法将根据这个键从多个字典中查找对应的值。
+ /// Returns an array of strings containing all non-empty values associated with the given key. If no matching value is found, an empty array is returned.
返回一个字符串数组,其中包含所有非空的、与给定键相关的值。如果没有找到匹配的值,则返回空数组。
+ public string[] AllTypeSearchFromConcurrentDictionary(string key)
+ {
+ // 安全地从字典获取并转换为字符串(对于可能为 null 的值使用 ?.ToString())
+ string cdString = cdStringDictionary.GetByKey(key)?.ToString();
+ string cdShort = cdShortDictionary.GetByKey(key)?.ToString();
+ string cdLong = cdLongDictionary.GetByKey(key)?.ToString();
+ string cdInt = cdIntegerDictionary.GetByKey(key)?.ToString();
+ string cdFloat = cdFloatDictionary.GetByKey(key)?.ToString();
+ string cdDouble = cdDoubleDictionary.GetByKey(key)?.ToString();
+ string cdDecimal = cdDecimalDictionary.GetByKey(key)?.ToString();
+ string cdChar = cdCharDictionary.GetByKey(key)?.ToString();
+ string cdBool = cdBooleanDictionary.GetByKey(key)?.ToString();
+
+ // 使用 LINQ 来过滤非 null 且非空的字符串,并将其转换为数组
+ string[] resultArray = new[] { cdString, cdShort, cdLong, cdInt, cdFloat, cdDouble, cdDecimal, cdChar, cdBool }
+ .Where(s => !string.IsNullOrEmpty(s)) // 只保留非 null 且非空字符串
+ .ToArray();
+
+ return resultArray;
+ }
+
+ ///
+ /// Finds the value associated with the given key from the semaphore thread-lock dictionary and returns all non-empty values as an array of strings.
+ /// 从信号量线程锁字典中查找与给定键相关的值,并将所有非空的值以字符串数组的形式返回。
+ ///
+ /// The key used to find. Method looks up the corresponding value from multiple dictionaries based on this key.
用于查找的键。方法将根据这个键从多个字典中查找对应的值。
+ /// Returns an array of strings containing all non-empty values associated with the given key. If no matching value is found, an empty array is returned.
返回一个字符串数组,其中包含所有非空的、与给定键相关的值。如果没有找到匹配的值,则返回空数组。
+ public string[] AllTypeSearchFromSemaphoreThreadLock(string key)
+ {
+ // 安全地从字典获取并转换为字符串(对于可能为 null 的值使用 ?.ToString())
+ string stlString = stlStringDictionary.GetByKey(key)?.ToString();
+ string stlShort = stlShortDictionary.GetByKey(key)?.ToString();
+ string stlLong = stlLongDictionary.GetByKey(key)?.ToString();
+ string stlInt = stlIntegerDictionary.GetByKey(key)?.ToString();
+ string stlFloat = stlFloatDictionary.GetByKey(key)?.ToString();
+ string stlDouble = stlDoubleDictionary.GetByKey(key)?.ToString();
+ string stlDecimal = stlDecimalDictionary.GetByKey(key)?.ToString();
+ string stlChar = stlCharDictionary.GetByKey(key)?.ToString();
+ string stlBool = stlBooleanDictionary.GetByKey(key)?.ToString();
+
+ // 使用 LINQ 来过滤非 null 且非空的字符串,并将其转换为数组
+ string[] resultArray = new[] { stlString, stlShort, stlLong, stlInt, stlFloat, stlDouble, stlDecimal, stlChar, stlBool }
+ .Where(s => !string.IsNullOrEmpty(s)) // 只保留非 null 且非空字符串
+ .ToArray();
+
+ return resultArray;
}
}
}
diff --git a/TYLDDB/TYLDDB.csproj b/TYLDDB/TYLDDB.csproj
index 3c0d91e..2ccd26d 100644
--- a/TYLDDB/TYLDDB.csproj
+++ b/TYLDDB/TYLDDB.csproj
@@ -4,7 +4,7 @@
netstandard2.1;net6.0;net8.0;net9.0
True
TYLDDB.NET
- 1.0.0-alpha.3p
+ 1.0.0-alpha.4pre1
TYLDDB-Project
LICENSE
True
diff --git a/TYLDDB/Utils/Database/IDatabase.cs b/TYLDDB/Utils/Database/IDatabase.cs
new file mode 100644
index 0000000..c154648
--- /dev/null
+++ b/TYLDDB/Utils/Database/IDatabase.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+
+namespace TYLDDB.Utils.Database
+{
+ ///
+ /// Interfaces for operations on external databases.
+ ///
+ public interface IDatabase
+ {
+ ///
+ /// Gets the names of all databases.
+ /// 获取所有数据库的名称。
+ ///
+ /// Complete database file contents
完整数据库文件内容
+ /// All database names
所有的数据库名称
+ public List GetDatabaseList(string fileContent);
+
+ ///
+ /// Gets the corresponding contents of the entered database.
+ /// 获取输入的数据库的对应内容。
+ ///
+ /// Complete database file contents
完整数据库文件内容
+ /// Name of the database to be read
需读取的数据库名称
+ /// Content about the database to be obtained
需获取的数据库的对应内容
+ public string GetDatabaseContent(string content, string databaseName);
+ }
+}
diff --git a/TYLDDB/Utils/Database.cs b/TYLDDB/Utils/Database/V1.cs
similarity index 95%
rename from TYLDDB/Utils/Database.cs
rename to TYLDDB/Utils/Database/V1.cs
index 66c84d3..b33c9c4 100644
--- a/TYLDDB/Utils/Database.cs
+++ b/TYLDDB/Utils/Database/V1.cs
@@ -2,11 +2,10 @@
using System.Text.RegularExpressions;
using TYLDDB.Basic;
-namespace TYLDDB.Utils
+namespace TYLDDB.Utils.Database
{
- internal class Database
+ internal class Database_V1 : IDatabase
{
-#pragma warning disable CA1822 // 忽略静态提示
public List GetDatabaseList(string fileContent)
{
// 正则表达式:排除 internaldb 和 distributeddb,同时匹配符合规则的数据库名称
diff --git a/TYLDDB/Utils/Database/V2.cs b/TYLDDB/Utils/Database/V2.cs
new file mode 100644
index 0000000..071d07a
--- /dev/null
+++ b/TYLDDB/Utils/Database/V2.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TYLDDB.Utils.Database
+{
+ internal class Database_V2 : IDatabase
+ {
+ public string GetDatabaseContent(string input, string databaseName)
+ {
+ // 定位到指定数据库的开始部分
+ string startMarker = $"{databaseName}::{{";
+ string endMarker = "};";
+
+ // 找到数据库内容的起始位置和结束位置
+ int startIndex = input.IndexOf(startMarker, StringComparison.Ordinal);
+ if (startIndex == -1)
+ {
+ return $"数据库 {databaseName} 未找到。";
+ }
+
+ // 在找到的起始位置之后,定位结束标记
+ int endIndex = input.IndexOf(endMarker, startIndex, StringComparison.Ordinal);
+ if (endIndex == -1)
+ {
+ return $"数据库 {databaseName} 的结束标记未找到。";
+ }
+
+ // 提取数据库内容
+ int contentStartIndex = startIndex + startMarker.Length;
+ string dbContent = input.Substring(contentStartIndex, endIndex - contentStartIndex).Trim();
+
+ // 使用 StringBuilder 高效地处理每行开头的空格
+ var result = new System.Text.StringBuilder();
+
+ // 将数据库内容按行分割
+ string[] lines = dbContent.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
+
+ foreach (var line in lines)
+ {
+ // 使用 TrimStart() 去掉每行开头的空格
+ string trimmedLine = line.TrimStart();
+
+ // 添加处理后的行到结果中
+ result.AppendLine(trimmedLine);
+ }
+
+ // 返回处理后的字符串
+ return result.ToString().TrimEnd(); // 移除结尾的多余换行符
+ }
+
+ public List GetDatabaseList(string fileContent)
+ {
+ throw new System.NotImplementedException();
+ }
+ }
+}
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs
index 9a50a8f..1a43499 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs
@@ -22,10 +22,13 @@ public class CdBooleanDictionary
///
/// Key
键
/// Value
值
- public virtual bool GetByKey(string key)
+ public virtual bool? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual bool GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs
index 9e27136..77c9329 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs
@@ -22,10 +22,13 @@ public class CdCharDictionary
///
/// Key
键
/// Value
值
- public virtual char GetByKey(string key)
+ public virtual char? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual char GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs
index aa0a9d5..e859925 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs
@@ -22,10 +22,13 @@ public class CdDecimalDictionary
///
/// Key
键
/// Value
值
- public virtual decimal GetByKey(string key)
+ public virtual decimal? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual decimal GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs
index c2c09e7..d0ef4aa 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs
@@ -22,10 +22,13 @@ public class CdDoubleDictionary
///
/// Key
键
/// Value
值
- public virtual double GetByKey(string key)
+ public virtual double? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual double GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs
index bed0e42..ab0e5db 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs
@@ -22,10 +22,13 @@ public class CdFloatDictionary
///
/// Key
键
/// Value
值
- public virtual float GetByKey(string key)
+ public virtual float? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual float GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs
index feb3f2f..7b94621 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs
@@ -22,10 +22,13 @@ public class CdIntegerDictionary
///
/// Key
键
/// Value
值
- public virtual int GetByKey(string key)
+ public virtual int? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual int GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs
index 43656d6..ae20445 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs
@@ -22,10 +22,13 @@ public class CdLongDictionary
///
/// Key
键
/// Value
值
- public virtual long GetByKey(string key)
+ public virtual long? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual long GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs
index 8ad8464..706aaa2 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs
@@ -22,10 +22,13 @@ public class CdShortDictionary
///
/// Key
键
/// Value
值
- public virtual short GetByKey(string key)
+ public virtual short? GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
@@ -34,7 +37,7 @@ public virtual short GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
+ public virtual async Task GetByKeyAsync(string key) => await Task.FromResult(GetByKey(key));
///
/// Get a list of keys that correspond to a specific value.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs
index a859eae..141b415 100644
--- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs
+++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs
@@ -24,8 +24,11 @@ public class CdStringDictionary
/// Value
值
public virtual string GetByKey(string key)
{
- _cache.TryGetValue(key, out var value);
- return value;
+ if (_cache.TryGetValue(key, out var value))
+ {
+ return value;
+ }
+ return null;
}
///
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs
index 6e41075..c1a1d65 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs
@@ -32,12 +32,17 @@ public StlBooleanDictionary()
///
/// Key
键
/// Value
值
- public virtual bool GetByKey(string key)
+ public virtual bool? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual bool GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs
index c2695e1..c85d14b 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs
@@ -32,12 +32,17 @@ public StlCharDictionary()
///
/// Key
键
/// Value
值
- public virtual char GetByKey(string key)
+ public virtual char? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual char GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs
index ebd14bd..2719d63 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs
@@ -32,12 +32,17 @@ public StlDecimalDictionary()
///
/// Key
键
/// Value
值
- public virtual decimal GetByKey(string key)
+ public virtual decimal? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual decimal GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs
index a2b624d..2397cef 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs
@@ -32,12 +32,17 @@ public StlDoubleDictionary()
///
/// Key
键
/// Value
值
- public virtual double GetByKey(string key)
+ public virtual double? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual double GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs
index e746d61..d4b25a8 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs
@@ -32,12 +32,17 @@ public StlFloatDictionary()
///
/// Key
键
/// Value
值
- public virtual float GetByKey(string key)
+ public virtual float? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual float GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs
index b2e458d..4d4f234 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs
@@ -32,12 +32,17 @@ public StlIntegerDictionary()
///
/// Key
键
/// Value
值
- public virtual int GetByKey(string key)
+ public virtual int? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual int GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs
index 91e7572..a6c257b 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs
@@ -32,12 +32,17 @@ public StlLongDictionary()
///
/// Key
键
/// Value
值
- public virtual long GetByKey(string key)
+ public virtual long? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual long GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs
index 0e74faf..816d36f 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs
@@ -32,12 +32,17 @@ public StlShortDictionary()
///
/// Key
键
/// Value
值
- public virtual short GetByKey(string key)
+ public virtual short? GetByKey(string key)
{
lock (semaphore)
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
}
@@ -47,13 +52,18 @@ public virtual short GetByKey(string key)
///
/// Key
键
/// Value
值
- public virtual async Task GetByKeyAsync(string key)
+ public virtual async Task GetByKeyAsync(string key)
{
await semaphore.WaitAsync();
try
{
- keyValueDict.TryGetValue(key, out var value);
- return value;
+ // 尝试从字典中获取值,如果键不存在则返回 null
+ if (keyValueDict.TryGetValue(key, out var value))
+ {
+ return value; // 如果找到值,返回该值
+ }
+
+ return null; // 如果没有找到对应的值,返回 null
}
finally
{
diff --git a/TYLDDB/Utils/Writer.cs b/TYLDDB/Utils/Writer.cs
index 2f15b1b..a2eb667 100644
--- a/TYLDDB/Utils/Writer.cs
+++ b/TYLDDB/Utils/Writer.cs
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Text;
-using System.Threading.Tasks;
namespace TYLDDB.Utils
{