From 7db30e4e024e9eddacd79aeb0dc3b55b3eb44e7d Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 15:25:31 +0800 Subject: [PATCH 01/17] test: delete test proj --- TYLDDB.Parser.Test/Program.cs | 33 ----------------- TYLDDB.Parser.Test/TYLDDB.Parser.Test.csproj | 15 -------- TYLDDB.Utils.Writer.Test/Program.cs | 37 ------------------- .../TYLDDB.Utils.Writer.Test.csproj | 15 -------- 4 files changed, 100 deletions(-) delete mode 100644 TYLDDB.Parser.Test/Program.cs delete mode 100644 TYLDDB.Parser.Test/TYLDDB.Parser.Test.csproj delete mode 100644 TYLDDB.Utils.Writer.Test/Program.cs delete mode 100644 TYLDDB.Utils.Writer.Test/TYLDDB.Utils.Writer.Test.csproj 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.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 - - - - - - - - From f42cea0e11cd16980aa7fa88c4bf01fa8e208ff0 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 16:07:59 +0800 Subject: [PATCH 02/17] feat: Concurrent dictionary parser --- .editorconfig | 110 ++++++++++++++++++++++++++++++++++++ TYLDDB/TYLDDB.cs | 141 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 248 insertions(+), 3 deletions(-) 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/TYLDDB.cs b/TYLDDB/TYLDDB.cs index 5370b06..e508b0f 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -90,6 +90,7 @@ public string FilePath } } } + /// /// Names of all databases in the current file
/// 当前文件内所有数据库的名称 @@ -162,11 +163,25 @@ public async Task ParseAsync() { // 创建多个任务,并使用 LongRunning 来确保每个任务在独立线程中运行 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); // 等待所有任务完成 - await Task.WhenAll(cdStringCacheTask); + await Task.WhenAll(cdStringCacheTask, + cdIntCacheTask, + cdShortCacheTask, + cdLongCacheTask, + cdFloatCacheTask, + cdDoubleCacheTask, + cdDecimalCacheTask, + cdCharCacheTask, + cdBoolCacheTask); async void CdString() { @@ -182,6 +197,126 @@ 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); + } + } } } } From 43f9c4a121978c26af0d7a0adea7cf04ad55cc8a Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 16:22:28 +0800 Subject: [PATCH 03/17] feat: Semaphore thread lock parser --- TYLDDB/TYLDDB.cs | 163 ++++++++++++++++++++++++++++++++++++++++--- TYLDDB/TYLDDB.csproj | 2 +- 2 files changed, 154 insertions(+), 11 deletions(-) diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs index e508b0f..e4e3e9f 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -162,6 +162,8 @@ 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); @@ -172,6 +174,17 @@ public async Task ParseAsync() 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, @@ -181,8 +194,18 @@ await Task.WhenAll(cdStringCacheTask, cdDoubleCacheTask, cdDecimalCacheTask, cdCharCacheTask, - cdBoolCacheTask); - + cdBoolCacheTask, + stlStringCacheTask, + stlIntCacheTask, + stlShortCacheTask, + stlLongCacheTask, + stlFloatCacheTask, + stlDoubleCacheTask, + stlDecimalCacheTask, + stlCharCacheTask, + stlBoolCacheTask); + + // ConcurrentDictionary async void CdString() { var dict = DataParser.ParseString(_databaseContent); @@ -197,7 +220,6 @@ async void CdString() await cdStringDictionary.SetAsync(key, value); } } - async void CdShort() { var dict = DataParser.ParseShort(_databaseContent); @@ -212,7 +234,6 @@ async void CdShort() await cdShortDictionary.SetAsync(key, value); } } - async void CdLong() { var dict = DataParser.ParseLong(_databaseContent); @@ -227,7 +248,6 @@ async void CdLong() await cdLongDictionary.SetAsync(key, value); } } - async void CdInt() { var dict = DataParser.ParseInt(_databaseContent); @@ -242,7 +262,6 @@ async void CdInt() await cdIntegerDictionary.SetAsync(key, value); } } - async void CdFloat() { var dict = DataParser.ParseFloat(_databaseContent); @@ -257,7 +276,6 @@ async void CdFloat() await cdFloatDictionary.SetAsync(key, value); } } - async void CdDouble() { var dict = DataParser.ParseDouble(_databaseContent); @@ -272,7 +290,6 @@ async void CdDouble() await cdDoubleDictionary.SetAsync(key, value); } } - async void CdDecimal() { var dict = DataParser.ParseDecimal(_databaseContent); @@ -287,7 +304,6 @@ async void CdDecimal() await cdDecimalDictionary.SetAsync(key, value); } } - async void CdChar() { var dict = DataParser.ParseChar(_databaseContent); @@ -302,7 +318,6 @@ async void CdChar() await cdCharDictionary.SetAsync(key, value); } } - async void CdBool() { var dict = DataParser.ParseBoolean(_databaseContent); @@ -317,6 +332,134 @@ async void CdBool() 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); + } + } } } } 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 From 0ccc738735a58be8db8a8ce3260d9c7380f74c7a Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 16:41:31 +0800 Subject: [PATCH 04/17] feat: Read data from cd --- TYLDDB/TYLDDB.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs index e4e3e9f..9f9e3fe 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using TYLDDB.Basic; using TYLDDB.Parser; @@ -461,5 +462,24 @@ async void StlBool() } } } + + public string[] Read(string key) + { + string cdString = cdStringDictionary.GetByKey(key); + 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 => s != null) // 只保留非 null 的字符串 + .ToArray(); + return resultArray; + } } } From 271b7e2190584cffeb0e2b71e9c016d77746150f Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 20:02:07 +0800 Subject: [PATCH 05/17] test: all type search test code --- TYLDDB.Test/Program.cs | 15 +++++++++++---- TYLDDB/TYLDDB.cs | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs index 9158a16..29d876e 100644 --- a/TYLDDB.Test/Program.cs +++ b/TYLDDB.Test/Program.cs @@ -43,10 +43,17 @@ parseDbTimer.Stop(); WriteTime("从发起解析文件到成功解析并写入缓存的总时间: ", parseDbTimer.ElapsedMilliseconds()); - - - - +///////////////////////////////////////////////////////////////////////////////////////////////////////// 数据库全类型搜寻 +HighPrecisionTimer allTypeSearchTimer = new(); +allTypeSearchTimer.Start(); +string[] AllTypeSearchResult = lddb.AllTypeSearch("str_name"); +allTypeSearchTimer.Stop(); +// 使用 foreach 输出数组的每个元素 +foreach (var str in AllTypeSearchResult) +{ + Console.WriteLine(str); +} +WriteTime("数据库全类型搜寻时间: ", parseDbTimer.ElapsedMilliseconds()); diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs index 9f9e3fe..0c6f577 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -463,7 +463,7 @@ async void StlBool() } } - public string[] Read(string key) + public string[] AllTypeSearch(string key) { string cdString = cdStringDictionary.GetByKey(key); string cdShort = cdShortDictionary.GetByKey(key).ToString(); From ffaa5e96f8c6eedbcc33a26b1fe362088f367285 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 20:15:11 +0800 Subject: [PATCH 06/17] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E5=86=99=E5=85=A5=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E9=9A=9C=E7=A2=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB.Test/example.lddb | 6 ++-- TYLDDB/Parser/Parser.cs | 65 +++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/TYLDDB.Test/example.lddb b/TYLDDB.Test/example.lddb index d895a31..7da3aab 100644 --- a/TYLDDB.Test/example.lddb +++ b/TYLDDB.Test/example.lddb @@ -3,11 +3,11 @@ 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"; + char::"char_value"="A"; + decimal::decima_value = 19.99"; internaldb::"db_name"={}; distributeddb::"distributed_db_name"="./example.lddb"; }; diff --git a/TYLDDB/Parser/Parser.cs b/TYLDDB/Parser/Parser.cs index 02c995b..ebcc65c 100644 --- a/TYLDDB/Parser/Parser.cs +++ b/TYLDDB/Parser/Parser.cs @@ -11,7 +11,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 +32,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; @@ -66,11 +67,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)) @@ -108,11 +110,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)) @@ -150,11 +153,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)) @@ -192,11 +196,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)) @@ -234,11 +239,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)) @@ -276,11 +282,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)) @@ -318,11 +325,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)) @@ -360,11 +368,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)) From 75f79e8a80f907e5934a006560b7522b69381f63 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 21:16:45 +0800 Subject: [PATCH 07/17] =?UTF-8?q?feat:=20=E8=A7=A3=E6=9E=90=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB/Parser/Parser.cs | 73 +++++++++++++++++++ TYLDDB/TYLDDB.cs | 26 ++++--- .../CdBooleanDictionary.cs | 11 ++- .../ConcurrentDictionary/CdCharDictionary.cs | 11 ++- .../CdDecimalDictionary.cs | 11 ++- .../CdDoubleDictionary.cs | 11 ++- .../ConcurrentDictionary/CdFloatDictionary.cs | 11 ++- .../CdIntegerDictionary.cs | 11 ++- .../ConcurrentDictionary/CdLongDictionary.cs | 11 ++- .../ConcurrentDictionary/CdShortDictionary.cs | 11 ++- .../CdStringDictionary.cs | 7 +- 11 files changed, 148 insertions(+), 46 deletions(-) diff --git a/TYLDDB/Parser/Parser.cs b/TYLDDB/Parser/Parser.cs index ebcc65c..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 { @@ -48,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -91,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -134,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -177,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -220,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -263,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -306,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -349,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.
/// 解析给定的内容并查找所有匹配的键值对。 @@ -391,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 0c6f577..fab4f60 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -465,20 +465,22 @@ async void StlBool() public string[] AllTypeSearch(string key) { - string cdString = cdStringDictionary.GetByKey(key); - 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 的项并将其转换为数组 + // 安全地从字典获取并转换为字符串(对于可能为 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 => s != null) // 只保留非 null 的字符串 + .Where(s => !string.IsNullOrEmpty(s)) // 只保留非 null 且非空字符串 .ToArray(); + return resultArray; } } 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; } /// From 19c5a2f17cd7064f1f8098069fa74848dfe5cae5 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Mon, 6 Jan 2025 21:22:21 +0800 Subject: [PATCH 08/17] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0XML=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB.Test/Program.cs | 6 +++--- TYLDDB/TYLDDB.cs | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs index 29d876e..e8b207e 100644 --- a/TYLDDB.Test/Program.cs +++ b/TYLDDB.Test/Program.cs @@ -43,17 +43,17 @@ parseDbTimer.Stop(); WriteTime("从发起解析文件到成功解析并写入缓存的总时间: ", parseDbTimer.ElapsedMilliseconds()); -///////////////////////////////////////////////////////////////////////////////////////////////////////// 数据库全类型搜寻 +///////////////////////////////////////////////////////////////////////////////////////////////////////// 并发词典数据库全类型异步搜寻 HighPrecisionTimer allTypeSearchTimer = new(); allTypeSearchTimer.Start(); -string[] AllTypeSearchResult = lddb.AllTypeSearch("str_name"); +string[] AllTypeSearchResult = lddb.AllTypeSearchFromConcurrentDictionary("str_name"); allTypeSearchTimer.Stop(); // 使用 foreach 输出数组的每个元素 foreach (var str in AllTypeSearchResult) { Console.WriteLine(str); } -WriteTime("数据库全类型搜寻时间: ", parseDbTimer.ElapsedMilliseconds()); +WriteTime("并发词典数据库全类型异步搜寻: ", parseDbTimer.ElapsedMilliseconds()); diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs index fab4f60..70e3a0c 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -463,7 +463,13 @@ async void StlBool() } } - public string[] AllTypeSearch(string key) + /// + /// 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(); From edae6f2148d1886c3741a8bcd68ea1a7213ca4b1 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Tue, 7 Jan 2025 15:18:30 +0800 Subject: [PATCH 09/17] =?UTF-8?q?bug:=20=E4=BC=98=E5=8C=96=E4=BF=A1?= =?UTF-8?q?=E5=8F=B7=E8=AF=8D=E5=85=B8=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB.Test/Program.cs | 43 +++++++++++++--- TYLDDB.Test/TYLDDB.Test.csproj | 2 + TYLDDB/TYLDDB.cs | 49 ++++++++++++------- .../StlBooleanDictionary.cs | 22 ++++++--- .../SemaphoreThreadLock/StlCharDictionary.cs | 22 ++++++--- .../StlDecimalDictionary.cs | 22 ++++++--- .../StlDoubleDictionary.cs | 22 ++++++--- .../SemaphoreThreadLock/StlFloatDictionary.cs | 22 ++++++--- .../StlIntegerDictionary.cs | 22 ++++++--- .../SemaphoreThreadLock/StlLongDictionary.cs | 22 ++++++--- .../SemaphoreThreadLock/StlShortDictionary.cs | 22 ++++++--- 11 files changed, 197 insertions(+), 73 deletions(-) diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs index e8b207e..bfdc8ae 100644 --- a/TYLDDB.Test/Program.cs +++ b/TYLDDB.Test/Program.cs @@ -43,17 +43,46 @@ parseDbTimer.Stop(); WriteTime("从发起解析文件到成功解析并写入缓存的总时间: ", parseDbTimer.ElapsedMilliseconds()); -///////////////////////////////////////////////////////////////////////////////////////////////////////// 并发词典数据库全类型异步搜寻 -HighPrecisionTimer allTypeSearchTimer = new(); -allTypeSearchTimer.Start(); -string[] AllTypeSearchResult = lddb.AllTypeSearchFromConcurrentDictionary("str_name"); -allTypeSearchTimer.Stop(); +///////////////////////////////////////////////////////////////////////////////////////////////////////// 并发词典数据库全类型同步搜寻 +HighPrecisionTimer allTypeSearchFromConcurrentDictionaryTimer = new(); +allTypeSearchFromConcurrentDictionaryTimer.Start(); +string[] AllTypeSearchFromConcurrentDictionaryResult = lddb.AllTypeSearchFromConcurrentDictionary("str_name"); +allTypeSearchFromConcurrentDictionaryTimer.Stop(); // 使用 foreach 输出数组的每个元素 -foreach (var str in AllTypeSearchResult) +foreach (var str in AllTypeSearchFromConcurrentDictionaryResult) { Console.WriteLine(str); } -WriteTime("并发词典数据库全类型异步搜寻: ", parseDbTimer.ElapsedMilliseconds()); +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()); + + + + + + + + + + + + + + + + + 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/TYLDDB.cs b/TYLDDB/TYLDDB.cs index 70e3a0c..99b9976 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -51,7 +51,6 @@ public LDDB() private string _fileContent; // 存储文件内容 private string _database; // 存储正在访问的数据库 private string _databaseContent; // 存储数据库内容 - private bool _isRead = false; // 是否已调用读取文件 private Database database; private CdStringDictionary cdStringDictionary; private CdShortDictionary cdShortDictionary; @@ -118,30 +117,17 @@ private static bool ValidateFilePath(string path) /// Read the contents from the file
/// 从文件中读取内容 ///
- public void ReadingFile() - { - _fileContent = Reader.ReadFile(FilePath); - _isRead = true; - } + public void ReadingFile() => _fileContent = Reader.ReadFile(FilePath); /// /// Set the database to load
/// 设置要加载的数据库 ///
/// name of the database
数据库名称 - public async void LoadDatabase(string db) + public void LoadDatabase(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.GetDatabaseContent(_fileContent, db); } /// @@ -489,5 +475,32 @@ public string[] AllTypeSearchFromConcurrentDictionary(string key) 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/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 { From d9e7824896230b7f554e391a8d8b54dfb3e42312 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 00:32:29 +0800 Subject: [PATCH 10/17] feat: add parse sync version --- TYLDDB/TYLDDB.cs | 307 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 307 insertions(+) diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs index 99b9976..bf5a784 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -142,6 +142,313 @@ public void LoadDatabase(string db) /// public void ReadAllDatabaseName() => AllDatabaseName = database.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.
/// 重新解析整个数据库。 From ada2955167ee1b8cefb4cc4a1a20aa9a3f4fecb0 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 00:32:54 +0800 Subject: [PATCH 11/17] test: add export test data method --- TYLDDB.Test/Program.cs | 46 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs index bfdc8ae..67bd4b4 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(); @@ -37,11 +38,16 @@ 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(); @@ -89,14 +95,42 @@ - +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}"); +} From 7985340d100d9766cf7c63d80dbe246a6f104602 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 00:37:45 +0800 Subject: [PATCH 12/17] =?UTF-8?q?refactor:=20=E6=B7=BB=E5=8A=A0abstract?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs | 2 +- TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs | 2 +- TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs | 2 +- TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs | 2 +- TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs index 1a43499..22fd3be 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdBooleanDictionary + public abstract class CdBooleanDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs index 77c9329..1e2a05b 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdCharDictionary + public abstract class CdCharDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs index e859925..d9a9a3f 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdDecimalDictionary + public abstract class CdDecimalDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs index d0ef4aa..23ff277 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdDoubleDictionary + public abstract class CdDoubleDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs index ab0e5db..b30ce6e 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdFloatDictionary + public abstract class CdFloatDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs index 7b94621..545d66b 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdIntegerDictionary + public abstract class CdIntegerDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs index ae20445..74acefb 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdLongDictionary + public abstract class CdLongDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs index 706aaa2..d38980c 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdShortDictionary + public abstract class CdShortDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs index 141b415..56192da 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public class CdStringDictionary + public abstract class CdStringDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs index c1a1d65..5cae6dd 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 ///
- public class StlBooleanDictionary + public abstract class StlBooleanDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs index c85d14b..42e116d 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlCharDictionary + public abstract class StlCharDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs index 2719d63..dedf66b 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlDecimalDictionary + public abstract class StlDecimalDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs index 2397cef..822467d 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlDoubleDictionary + public abstract class StlDoubleDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs index d4b25a8..10adaef 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlFloatDictionary + public abstract class StlFloatDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs index 4d4f234..5eda230 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlIntegerDictionary + public abstract class StlIntegerDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs index a6c257b..b3fd0ef 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlLongDictionary + public abstract class StlLongDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs index 816d36f..5e0ff2b 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlShortDictionary + public abstract class StlShortDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs index 09bc308..9910745 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public class StlStringDictionary + public abstract class StlStringDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 From 07fcbefda7aaff15905d58636b9f8b46c66350a3 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 00:39:52 +0800 Subject: [PATCH 13/17] =?UTF-8?q?Revert=20"refactor:=20=E6=B7=BB=E5=8A=A0a?= =?UTF-8?q?bstract=E5=85=B3=E9=94=AE=E5=AD=97"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7985340d100d9766cf7c63d80dbe246a6f104602. --- .../Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs | 2 +- TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs | 2 +- TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs | 2 +- .../Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs | 2 +- TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs | 2 +- TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs | 2 +- .../Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs index 22fd3be..1a43499 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdBooleanDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 /// - public abstract class CdBooleanDictionary + public class CdBooleanDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs index 1e2a05b..77c9329 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdCharDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdCharDictionary + public class CdCharDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs index d9a9a3f..e859925 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDecimalDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdDecimalDictionary + public class CdDecimalDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs index 23ff277..d0ef4aa 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdDoubleDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdDoubleDictionary + public class CdDoubleDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs index b30ce6e..ab0e5db 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdFloatDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdFloatDictionary + public class CdFloatDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs index 545d66b..7b94621 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdIntegerDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdIntegerDictionary + public class CdIntegerDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs index 74acefb..ae20445 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdLongDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdLongDictionary + public class CdLongDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs index d38980c..706aaa2 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdShortDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdShortDictionary + public class CdShortDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs index 56192da..141b415 100644 --- a/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs +++ b/TYLDDB/Utils/FastCache/ConcurrentDictionary/CdStringDictionary.cs @@ -8,7 +8,7 @@ namespace TYLDDB.Utils.FastCache.ConcurrentDictionary /// Use concurrent dictionaries to achieve high concurrency stability.
/// 使用并发词典来实现高并发的稳定性。 ///
- public abstract class CdStringDictionary + public class CdStringDictionary { /// /// Thread-safe dictionary to store cache data.
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs index 5cae6dd..c1a1d65 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlBooleanDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 ///
- public abstract class StlBooleanDictionary + public class StlBooleanDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs index 42e116d..c85d14b 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlCharDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlCharDictionary + public class StlCharDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs index dedf66b..2719d63 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDecimalDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlDecimalDictionary + public class StlDecimalDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs index 822467d..2397cef 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlDoubleDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlDoubleDictionary + public class StlDoubleDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs index 10adaef..d4b25a8 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlFloatDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlFloatDictionary + public class StlFloatDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs index 5eda230..4d4f234 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlIntegerDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlIntegerDictionary + public class StlIntegerDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs index b3fd0ef..a6c257b 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlLongDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlLongDictionary + public class StlLongDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs index 5e0ff2b..816d36f 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlShortDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlShortDictionary + public class StlShortDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs index 9910745..09bc308 100644 --- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs +++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock/StlStringDictionary.cs @@ -9,7 +9,7 @@ namespace TYLDDB.Utils.FastCache.SemaphoreThreadLock /// Use semaphore based thread locks to achieve high concurrency stability.
/// 使用基于信号量的线程锁来实现高并发的稳定性。 /// - public abstract class StlStringDictionary + public class StlStringDictionary { private readonly Dictionary keyValueDict; // 存储键->值映射 private readonly Dictionary> valueKeyDict; // 存储值->键的映射 From f9626730e51d9302343a3bca7d891a4c43bed648 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 00:40:20 +0800 Subject: [PATCH 14/17] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84using?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB/Utils/Writer.cs | 1 - 1 file changed, 1 deletion(-) 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 { From b174c2779d57a20467ae8c5b0ecfc6979fbd2703 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 01:02:15 +0800 Subject: [PATCH 15/17] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=93=8D=E4=BD=9C=E7=B1=BB=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB/Utils/Database.cs | 60 ---------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 TYLDDB/Utils/Database.cs diff --git a/TYLDDB/Utils/Database.cs b/TYLDDB/Utils/Database.cs deleted file mode 100644 index 66c84d3..0000000 --- a/TYLDDB/Utils/Database.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Collections.Generic; -using System.Text.RegularExpressions; -using TYLDDB.Basic; - -namespace TYLDDB.Utils -{ - internal class Database - { -#pragma warning disable CA1822 // 忽略静态提示 - public List GetDatabaseList(string fileContent) - { - // 正则表达式:排除 internaldb 和 distributeddb,同时匹配符合规则的数据库名称 - string pattern = @"(?!internaldb$|distributeddb$)[a-zA-Z0-9_]+(?=::\{)"; - - // 使用正则表达式提取所有数据库名称 - MatchCollection matches = Regex.Matches(fileContent, pattern); - - // 创建一个List来存储数据库名称 - List databaseNames = new List(); - - // 遍历匹配结果并加入到List中 - foreach (Match match in matches) - { - if (match.Success) - { - // 提取数据库名称 - string databaseName = match.Value; - databaseNames.Add(databaseName); - } - } - - return databaseNames; - } - - public string GetDatabaseContent(string content, string databaseName) - { - // 更新的正则表达式,用于匹配指定数据库的内容,包括处理大括号的嵌套结构 - string pattern = $@"{databaseName}\s*::\s*\{{([^{{}}]*(?:{{[^{{}}]*}}[^{{}}]*)*)\}};"; - - // 执行正则匹配 - Match match = Regex.Match(content, pattern, RegexOptions.Singleline); - - if (match.Success) - { - // 获取匹配的数据库内容 - string databaseContent = match.Groups[1].Value; - - // 替换多余的空格和换行符,保持引号内的空格 - string cleanedContent = Regex.Replace(databaseContent, @"\s*(?=\S)", ""); - - return databaseContent; - } - else - { - // 如果未找到匹配项,抛出自定义异常 - throw new GetDatabaseContentErrorException($"未找到数据库 '{databaseName}' 的内容。"); - } - } - } -} From dcbe2751c0b8adfbfb227f4a02ebe5ca64663523 Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 01:03:34 +0800 Subject: [PATCH 16/17] =?UTF-8?q?feat:=20=E6=B0=B8=E4=B9=85=E7=A7=BB?= =?UTF-8?q?=E9=99=A4internaldb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB.Test/example.lddb | 1 - 1 file changed, 1 deletion(-) diff --git a/TYLDDB.Test/example.lddb b/TYLDDB.Test/example.lddb index 7da3aab..54838dc 100644 --- a/TYLDDB.Test/example.lddb +++ b/TYLDDB.Test/example.lddb @@ -8,7 +8,6 @@ boolean::"bool"="true"; char::"char_value"="A"; decimal::decima_value = 19.99"; - internaldb::"db_name"={}; distributeddb::"distributed_db_name"="./example.lddb"; }; database2::{ From c2a1ff9862a08f572dc4fb9df196e36937f816ef Mon Sep 17 00:00:00 2001 From: Grey Wind Date: Thu, 9 Jan 2025 01:27:01 +0800 Subject: [PATCH 17/17] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=95=B0=E6=8D=AE=E5=BA=93=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TYLDDB.Test/Program.cs | 9 ++++- TYLDDB.Test/example.lddb | 6 +-- TYLDDB/TYLDDB.cs | 24 +++++++++--- TYLDDB/Utils/Database/IDatabase.cs | 27 ++++++++++++++ TYLDDB/Utils/Database/V1.cs | 59 ++++++++++++++++++++++++++++++ TYLDDB/Utils/Database/V2.cs | 57 +++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 9 deletions(-) create mode 100644 TYLDDB/Utils/Database/IDatabase.cs create mode 100644 TYLDDB/Utils/Database/V1.cs create mode 100644 TYLDDB/Utils/Database/V2.cs diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs index 67bd4b4..ada0a5c 100644 --- a/TYLDDB.Test/Program.cs +++ b/TYLDDB.Test/Program.cs @@ -21,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(); // 从发起读取数据库名称到成功返回读取内容的总时间 diff --git a/TYLDDB.Test/example.lddb b/TYLDDB.Test/example.lddb index 54838dc..0f79eeb 100644 --- a/TYLDDB.Test/example.lddb +++ b/TYLDDB.Test/example.lddb @@ -1,5 +1,5 @@ database1::{ - string::"str_name"="name1"; + string::"str_name"="name1 space test"; int::"int_value"="123"; short::"short_value"="32767"; long::"long_value"="2147483647"; @@ -7,7 +7,7 @@ double::"double_value"="3.141592653589793"; boolean::"bool"="true"; char::"char_value"="A"; - decimal::decima_value = 19.99"; + decimal::decimal_value = 19.99"; distributeddb::"distributed_db_name"="./example.lddb"; }; database2::{ @@ -19,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/TYLDDB.cs b/TYLDDB/TYLDDB.cs index bf5a784..e04cf39 100644 --- a/TYLDDB/TYLDDB.cs +++ b/TYLDDB/TYLDDB.cs @@ -4,6 +4,7 @@ using TYLDDB.Basic; using TYLDDB.Parser; using TYLDDB.Utils; +using TYLDDB.Utils.Database; using TYLDDB.Utils.FastCache.ConcurrentDictionary; using TYLDDB.Utils.FastCache.SemaphoreThreadLock; @@ -21,7 +22,9 @@ public class LDDB /// public LDDB() { - database = new Database(); // 实例化数据库操作类 + // 实例化数据库操作类 + database_v1 = new Database_V1(); + database_v2 = new Database_V2(); // 实例化并发词典 cdStringDictionary = new CdStringDictionary(); @@ -49,9 +52,9 @@ public LDDB() ///////////////////////////////////////////////////// 私有字段 private string _filePath; // 存储文件路径 private string _fileContent; // 存储文件内容 - private string _database; // 存储正在访问的数据库 private string _databaseContent; // 存储数据库内容 - private Database database; + private Database_V1 database_v1; + private Database_V2 database_v2; private CdStringDictionary cdStringDictionary; private CdShortDictionary cdShortDictionary; private CdLongDictionary cdLongDictionary; @@ -127,7 +130,18 @@ private static bool ValidateFilePath(string path) public void LoadDatabase(string db) { ReadingFile(); - _databaseContent = database.GetDatabaseContent(_fileContent, db); + _databaseContent = database_v1.GetDatabaseContent(_fileContent, db); + } + + /// + /// Set the database to load
+ /// 设置要加载的数据库 + ///
+ /// name of the database
数据库名称 + public void LoadDatabase_V2(string db) + { + ReadingFile(); + _databaseContent = database_v2.GetDatabaseContent(_fileContent, db); } /// @@ -140,7 +154,7 @@ public 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.
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/V1.cs b/TYLDDB/Utils/Database/V1.cs new file mode 100644 index 0000000..b33c9c4 --- /dev/null +++ b/TYLDDB/Utils/Database/V1.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; +using TYLDDB.Basic; + +namespace TYLDDB.Utils.Database +{ + internal class Database_V1 : IDatabase + { + public List GetDatabaseList(string fileContent) + { + // 正则表达式:排除 internaldb 和 distributeddb,同时匹配符合规则的数据库名称 + string pattern = @"(?!internaldb$|distributeddb$)[a-zA-Z0-9_]+(?=::\{)"; + + // 使用正则表达式提取所有数据库名称 + MatchCollection matches = Regex.Matches(fileContent, pattern); + + // 创建一个List来存储数据库名称 + List databaseNames = new List(); + + // 遍历匹配结果并加入到List中 + foreach (Match match in matches) + { + if (match.Success) + { + // 提取数据库名称 + string databaseName = match.Value; + databaseNames.Add(databaseName); + } + } + + return databaseNames; + } + + public string GetDatabaseContent(string content, string databaseName) + { + // 更新的正则表达式,用于匹配指定数据库的内容,包括处理大括号的嵌套结构 + string pattern = $@"{databaseName}\s*::\s*\{{([^{{}}]*(?:{{[^{{}}]*}}[^{{}}]*)*)\}};"; + + // 执行正则匹配 + Match match = Regex.Match(content, pattern, RegexOptions.Singleline); + + if (match.Success) + { + // 获取匹配的数据库内容 + string databaseContent = match.Groups[1].Value; + + // 替换多余的空格和换行符,保持引号内的空格 + string cleanedContent = Regex.Replace(databaseContent, @"\s*(?=\S)", ""); + + return databaseContent; + } + else + { + // 如果未找到匹配项,抛出自定义异常 + throw new GetDatabaseContentErrorException($"未找到数据库 '{databaseName}' 的内容。"); + } + } + } +} 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(); + } + } +}