diff --git a/LICENSE b/LICENSE
index 9fa3e69..4faacbe 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,18 +1,15 @@
-BSD 3-Clause License
+BSD 3-Clause License (Modified)
Copyright (c) 2024, Tsing Yi Local Distributed Database
-Redistribution and use in source and binary forms, with or without
+Redistribution and use in binary forms, with or without
modification, are permitted provided that the following conditions are met:
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright notice,
+1. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-3. Neither the name of the copyright holder nor the names of its
+2. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
diff --git a/LICENSE_CN b/LICENSE_CN
new file mode 100644
index 0000000..295e1a1
--- /dev/null
+++ b/LICENSE_CN
@@ -0,0 +1,48 @@
+BSD 3-Clause License (修改版)
+
+Copyright (c) 2024, Tsing Yi Local Distributed Database
+
+在满足以下条件的情况下,允许以二进制形式重新分发和使用,无论是否进行修改:
+
+1. 以二进制形式重新分发必须在文件和/或随分发提供的其他材料中复制上述版权声明、本
+ 条件列表和以下免责声明。
+
+2. 未经事先书面许可,不得使用版权所有者的名字或贡献者的名字来支持或推广源自本软件
+ 的产品。
+
+3. 以下子条件针对所有中国大陆公司,内部所有国家均指中国大陆:
+
+ 3.1 不得将本软件用于任何与国家法律、法规和政策相抵触的活动。
+
+ 3.2 不得将本软件用于任何可能损害国家安全、社会公共利益或他人合法权益的活动。
+
+ 3.3 不得将本软件用于任何可能侵犯他人知识产权的活动。
+
+ 3.4 不得将本软件用于任何可能违反国家法律法规的活动。
+
+ 3.5 不得将本软件用于任何可能损害国家信息安全的活动。
+
+ 3.6 不得将本软件用于任何可能损害国家政治稳定的活动。
+
+ 3.7 不得将本软件用于任何可能损害国家经济利益的活动。
+
+ 3.8 不得将本软件用于任何可能损害国家文化利益的活动。
+
+ 3.9 不得将本软件用于任何可能损害国家形象的活动。
+
+ 3.10 不得将本软件用于任何可能损害国家荣誉的活动。
+
+ 3.11 不得将本软件用于任何可能损害国家尊严的活动。
+
+ 3.12 不得在未经书面许可的情况下将该程序商用。
+
+ 3.13 由于该程序造成的损失本程序作者与团队概不负责。
+
+ 3.14 未经书面许可禁止将本项目代码商用。
+
+本软件由版权持有人和贡献者“按原样”提供,不承担任何明示或暗示的保证,包括但不限于对
+适销性和适合特定目的的暗示保证。在任何情况下,版权持有人或贡献者均不对任何直接、间
+接、附带、特殊、惩戒性或后果性损害(包括但不限于,购买替代商品或服务;损失:失去使用
+、数据或利润;(或业务中断),无论如何造成的,以及根据任何责任理论,无论是合同责任,
+严格责任,还是侵权行为(包括疏忽或其他),即使被告知该等损害的可能性,也会因使用本
+软件而以任何方式产生。
diff --git a/TYLDDB-CSharp.sln b/TYLDDB-CSharp.sln
index 9ed67ba..d409f8a 100644
--- a/TYLDDB-CSharp.sln
+++ b/TYLDDB-CSharp.sln
@@ -16,6 +16,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Utils.FastCache.Test
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Utils.Writer.Test", "TYLDDB.Utils.Writer.Test\TYLDDB.Utils.Writer.Test.csproj", "{1BA4CC53-078F-4943-B8EF-A522DA9E5060}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeRecord", "TimeRecord\TimeRecord.csproj", "{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TYLDDB.Parser.Test", "TYLDDB.Parser.Test\TYLDDB.Parser.Test.csproj", "{0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -34,6 +40,18 @@ Global
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1BA4CC53-078F-4943-B8EF-A522DA9E5060}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0B96CCF3-16C7-4B18-9D07-A19D5D8E9641}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -41,6 +59,9 @@ Global
GlobalSection(NestedProjects) = preSolution
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
{A58C0A6B-9BD4-4B29-9B5F-5FDFB849D23B} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
+ {1BA4CC53-078F-4943-B8EF-A522DA9E5060} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
+ {F95CF6BC-2255-47F8-AAB3-B7812BB2894D} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
+ {0B96CCF3-16C7-4B18-9D07-A19D5D8E9641} = {95BC8FAF-AB03-44A3-A7E7-8E42FA7138E3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {19390089-354C-41AD-AF7D-9FB3998A88EA}
diff --git a/TYLDDB.Parser.Test/Program.cs b/TYLDDB.Parser.Test/Program.cs
new file mode 100644
index 0000000..fc62551
--- /dev/null
+++ b/TYLDDB.Parser.Test/Program.cs
@@ -0,0 +1,33 @@
+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
new file mode 100644
index 0000000..700866e
--- /dev/null
+++ b/TYLDDB.Parser.Test/TYLDDB.Parser.Test.csproj
@@ -0,0 +1,15 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/TYLDDB.Test/Program.cs b/TYLDDB.Test/Program.cs
index b4583a7..f727e38 100644
--- a/TYLDDB.Test/Program.cs
+++ b/TYLDDB.Test/Program.cs
@@ -1,10 +1,10 @@
-using TYLDDB;
-using TYLDDB.Test;
+using TimeRecord;
+using TYLDDB;
string dbFilePath = "./example.lddb";
///////////////////////////////////////////////////////////////////////////////////////////////////////// 实例化
-LDDB lddb = new LDDB();
+var lddb = new LDDB();
///////////////////////////////////////////////////////////////////////////////////////////////////////// 读取文件
HighPrecisionTimer readDbTimer = new(); // 从发起读取文件到成功读取的总时间
diff --git a/TYLDDB.Test/TYLDDB.Test.csproj b/TYLDDB.Test/TYLDDB.Test.csproj
index 8afa4b0..1f5fc44 100644
--- a/TYLDDB.Test/TYLDDB.Test.csproj
+++ b/TYLDDB.Test/TYLDDB.Test.csproj
@@ -8,6 +8,7 @@
+
diff --git a/TYLDDB.Test/example.lddb b/TYLDDB.Test/example.lddb
index 6f6b19e..d895a31 100644
--- a/TYLDDB.Test/example.lddb
+++ b/TYLDDB.Test/example.lddb
@@ -1,13 +1,13 @@
database1::{
string::"str_name"="name1";
- int::"int_value"="123"
- short::"short_value"="32767"
+ 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"
+ 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"={};
distributeddb::"distributed_db_name"="./example.lddb";
};
diff --git a/TYLDDB.Utils.FastCache.Test/HighPrecisionTimer.cs b/TYLDDB.Utils.FastCache.Test/HighPrecisionTimer.cs
deleted file mode 100644
index 7856bfe..0000000
--- a/TYLDDB.Utils.FastCache.Test/HighPrecisionTimer.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System.Diagnostics;
-
-namespace TYLDDB.Utils.FastCache.Test
-{
- internal class HighPrecisionTimer
- {
- private Stopwatch stopwatch;
-
- public HighPrecisionTimer()
- {
- stopwatch = new Stopwatch();
- }
-
- // 启动计时器
- public void Start()
- {
- stopwatch.Start();
- }
-
- // 停止计时器
- public void Stop()
- {
- stopwatch.Stop();
- }
-
- // 重置计时器
- public void Reset()
- {
- stopwatch.Reset();
- }
-
- // 获取已用时间(毫秒)
- public double ElapsedMilliseconds()
- {
- return stopwatch.Elapsed.TotalMilliseconds;
- }
-
- // 获取已用时间(秒)
- public double ElapsedSeconds()
- {
- return stopwatch.Elapsed.TotalSeconds;
- }
- }
-}
diff --git a/TYLDDB.Utils.FastCache.Test/Program.cs b/TYLDDB.Utils.FastCache.Test/Program.cs
index 1b06543..5172226 100644
--- a/TYLDDB.Utils.FastCache.Test/Program.cs
+++ b/TYLDDB.Utils.FastCache.Test/Program.cs
@@ -1,5 +1,5 @@
+using TimeRecord;
using TYLDDB.Utils.FastCache;
-using TYLDDB.Utils.FastCache.Test;
Console.WriteLine("基于信号量的缓存读写运行");
SemaphoreSlimDefault();
@@ -21,7 +21,7 @@ static async void SemaphoreSlimDefault()
var getAllCacheTime = new HighPrecisionTimer();
var getAllCacheAsyncTime = new HighPrecisionTimer();
- ICache cache = new SemaphoreThreadLock();
+ var cache = new SemaphoreThreadLock();
setTime.Start();
cache.Set("TESTKEY1", "TESTVALUE1");
@@ -91,7 +91,7 @@ static async void ConcurrentDictionary()
var getAllCacheTime = new HighPrecisionTimer();
var getAllCacheAsyncTime = new HighPrecisionTimer();
- ICache cache = new ConcurrentDictionary();
+ var cache = new ConcurrentDictionary();
setTime.Start();
cache.Set("TESTKEY1", "TESTVALUE1");
diff --git a/TYLDDB.Utils.FastCache.Test/TYLDDB.Utils.FastCache.Test.csproj b/TYLDDB.Utils.FastCache.Test/TYLDDB.Utils.FastCache.Test.csproj
index bb48fc4..700866e 100644
--- a/TYLDDB.Utils.FastCache.Test/TYLDDB.Utils.FastCache.Test.csproj
+++ b/TYLDDB.Utils.FastCache.Test/TYLDDB.Utils.FastCache.Test.csproj
@@ -8,6 +8,7 @@
+
diff --git a/TYLDDB.Utils.Writer.Test/Program.cs b/TYLDDB.Utils.Writer.Test/Program.cs
new file mode 100644
index 0000000..2e269e1
--- /dev/null
+++ b/TYLDDB.Utils.Writer.Test/Program.cs
@@ -0,0 +1,37 @@
+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
new file mode 100644
index 0000000..700866e
--- /dev/null
+++ b/TYLDDB.Utils.Writer.Test/TYLDDB.Utils.Writer.Test.csproj
@@ -0,0 +1,15 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/TYLDDB/LICENSE b/TYLDDB/LICENSE
new file mode 100644
index 0000000..4faacbe
--- /dev/null
+++ b/TYLDDB/LICENSE
@@ -0,0 +1,25 @@
+BSD 3-Clause License (Modified)
+
+Copyright (c) 2024, Tsing Yi Local Distributed Database
+
+Redistribution and use in binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+2. Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/TYLDDB/LICENSE_CN b/TYLDDB/LICENSE_CN
new file mode 100644
index 0000000..295e1a1
--- /dev/null
+++ b/TYLDDB/LICENSE_CN
@@ -0,0 +1,48 @@
+BSD 3-Clause License (修改版)
+
+Copyright (c) 2024, Tsing Yi Local Distributed Database
+
+在满足以下条件的情况下,允许以二进制形式重新分发和使用,无论是否进行修改:
+
+1. 以二进制形式重新分发必须在文件和/或随分发提供的其他材料中复制上述版权声明、本
+ 条件列表和以下免责声明。
+
+2. 未经事先书面许可,不得使用版权所有者的名字或贡献者的名字来支持或推广源自本软件
+ 的产品。
+
+3. 以下子条件针对所有中国大陆公司,内部所有国家均指中国大陆:
+
+ 3.1 不得将本软件用于任何与国家法律、法规和政策相抵触的活动。
+
+ 3.2 不得将本软件用于任何可能损害国家安全、社会公共利益或他人合法权益的活动。
+
+ 3.3 不得将本软件用于任何可能侵犯他人知识产权的活动。
+
+ 3.4 不得将本软件用于任何可能违反国家法律法规的活动。
+
+ 3.5 不得将本软件用于任何可能损害国家信息安全的活动。
+
+ 3.6 不得将本软件用于任何可能损害国家政治稳定的活动。
+
+ 3.7 不得将本软件用于任何可能损害国家经济利益的活动。
+
+ 3.8 不得将本软件用于任何可能损害国家文化利益的活动。
+
+ 3.9 不得将本软件用于任何可能损害国家形象的活动。
+
+ 3.10 不得将本软件用于任何可能损害国家荣誉的活动。
+
+ 3.11 不得将本软件用于任何可能损害国家尊严的活动。
+
+ 3.12 不得在未经书面许可的情况下将该程序商用。
+
+ 3.13 由于该程序造成的损失本程序作者与团队概不负责。
+
+ 3.14 未经书面许可禁止将本项目代码商用。
+
+本软件由版权持有人和贡献者“按原样”提供,不承担任何明示或暗示的保证,包括但不限于对
+适销性和适合特定目的的暗示保证。在任何情况下,版权持有人或贡献者均不对任何直接、间
+接、附带、特殊、惩戒性或后果性损害(包括但不限于,购买替代商品或服务;损失:失去使用
+、数据或利润;(或业务中断),无论如何造成的,以及根据任何责任理论,无论是合同责任,
+严格责任,还是侵权行为(包括疏忽或其他),即使被告知该等损害的可能性,也会因使用本
+软件而以任何方式产生。
diff --git a/TYLDDB/Parser/Parser.cs b/TYLDDB/Parser/Parser.cs
new file mode 100644
index 0000000..326f561
--- /dev/null
+++ b/TYLDDB/Parser/Parser.cs
@@ -0,0 +1,386 @@
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
+namespace TYLDDB.Parser
+{
+ ///
+ /// Data type parser.
+ /// 数据类型解析器。
+ ///
+ public class Parser
+ {
+ // 定义正则表达式来匹配键值对(类型::"key"="value")
+ private readonly static string pattern = @"(?<=^|\s)(\w+)\s*::\s*""([^""]+)""";
+
+ ///
+ /// 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 Dictionary ParseString(string content)
+ {
+ string type = "string";
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配,加入到结果字典
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = matchedValue;
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseInt(string content)
+ {
+ string type = "int"; // 目标类型是 int
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 int 类型
+ if (int.TryParse(matchedValue, out int intValue))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = intValue;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 int。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseShort(string content)
+ {
+ string type = "short"; // 目标类型是 short
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 short 类型
+ if (short.TryParse(matchedValue, out short shortValue))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = shortValue;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 short。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseLong(string content)
+ {
+ string type = "long"; // 目标类型是 long
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 long 类型
+ if (long.TryParse(matchedValue, out long longValue))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = longValue;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 long。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseFloat(string content)
+ {
+ string type = "float"; // 目标类型是 float
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 short 类型
+ if (float.TryParse(matchedValue, out float floatValue))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = floatValue;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 float。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseDouble(string content)
+ {
+ string type = "double"; // 目标类型是 double
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 short 类型
+ if (double.TryParse(matchedValue, out double Value))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = Value;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 double。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseBoolean(string content)
+ {
+ string type = "boolean"; // 目标类型是 float
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 short 类型
+ if (bool.TryParse(matchedValue, out bool Value))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = Value;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 bool。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseChar(string content)
+ {
+ string type = "char"; // 目标类型是 float
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 short 类型
+ if (char.TryParse(matchedValue, out char Value))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = Value;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 char。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ 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 Dictionary ParseDecimal(string content)
+ {
+ string type = "decimal"; // 目标类型是 float
+
+ // 创建一个字典来存储找到的所有键值对
+ var result = new Dictionary();
+
+ // 匹配整个内容中的所有键值对
+ var matches = Regex.Matches(content, pattern);
+
+ // 遍历所有的匹配项
+ foreach (Match match in matches)
+ {
+ string matchedKey = match.Groups[1].Value;
+ string matchedValue = match.Groups[2].Value;
+
+ // 如果提供的类型与键的类型匹配
+ if (string.Equals(type, matchedKey, StringComparison.OrdinalIgnoreCase))
+ {
+ // 尝试将值转换为 short 类型
+ if (decimal.TryParse(matchedValue, out decimal Value))
+ {
+ // 将匹配的键值对添加到字典中
+ result[matchedKey] = Value;
+ }
+ else
+ {
+ throw new Exception($"无法将值 \"{matchedValue}\" 转换为 decimal。");
+ }
+ }
+ }
+
+ // 返回结果字典,若没有匹配项则返回空字典
+ return result;
+ }
+ }
+}
diff --git a/TYLDDB/TYLDDB.cs b/TYLDDB/TYLDDB.cs
index 359ce37..c268361 100644
--- a/TYLDDB/TYLDDB.cs
+++ b/TYLDDB/TYLDDB.cs
@@ -2,11 +2,13 @@
using System.Collections.Generic;
using TYLDDB.Basic;
using TYLDDB.Utils;
+using TYLDDB.Utils.FastCache;
namespace TYLDDB
{
///
- /// The core class of the database.
+ /// The core class of the database.
+ /// 数据库的核心类。
///
public class LDDB
{
@@ -16,7 +18,7 @@ public class LDDB
///
public LDDB()
{
- // TODO
+ // NOTHING HERE!
}
///////////////////////////////////////////////////// 私有字段
@@ -27,6 +29,8 @@ public LDDB()
private bool _isRead = false; // 是否已调用读取文件
private event Action OnFileReadComplete;
private Database database = new Database();
+ private Cache cdCache = new ConcurrentDictionary();
+ private Cache stlCache = new SemaphoreThreadLock();
///////////////////////////////////////////////////// 公开字段
///
diff --git a/TYLDDB/TYLDDB.csproj b/TYLDDB/TYLDDB.csproj
index cd2e836..a8a6ed5 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.2r
+ 1.0.0-alpha.3
TYLDDB-Project
LICENSE
True
@@ -12,20 +12,22 @@
https://github.com/TYLDDB/TYLDDB-CSharp
git
ttypdb.qingyi-studio.top
- BSD 3-Clause License
+ BSD 3-Clause License (Modified)
A strongly typed constrained distributed file system that can act as a database.
True
True
DataBase
QingYi-Studio
README.md
- Remove support for .netstandard 2.0.
-Remove direct inheritance/derivation of the ICache interface and instead use abstract class relays, using virtual methods to trim asynchronous code in part of the concurrent dictionary.
+ Add a database parser (data type only, internal and distributed databases are not available).
+Fast cache underlying interface optimization.
+
+
@@ -34,21 +36,18 @@ Remove direct inheritance/derivation of the ICache interface and instead use abs
True
\
+
+ True
+ \
+
+
-
- True
- \
-
True
\
-
-
-
-
diff --git a/TYLDDB/Utils/FastCache/ICache.cs b/TYLDDB/Utils/FastCache/ICache.cs
index 76561be..ea3ecce 100644
--- a/TYLDDB/Utils/FastCache/ICache.cs
+++ b/TYLDDB/Utils/FastCache/ICache.cs
@@ -42,44 +42,49 @@ public interface ICache
Task> GetKeysByValueAsync(string value);
///
- /// 同步方法:设置一个键值对。
+ /// Set a key-value pair.
+ /// 设置一个键值对。
///
- ///
- ///
- ///
+ /// Key
键
+ /// Value
值
+ /// Whether the Settings are successful.
是否设置成功。
bool Set(string key, string value);
///
- /// 异步方法:设置一个键值对。
+ /// Set a key-value pair.
+ /// 设置一个键值对。
///
- ///
- ///
- ///
+ /// Key
键
+ /// Value
值
+ /// Whether the Settings are successful.
是否设置成功。
Task SetAsync(string key, string value);
///
- /// 同步方法:移除一个键值对。
+ /// Remove a key-value pair.
+ /// 移除一个键值对。
///
- ///
- ///
+ /// Key
键
+ /// Whether the removal was successful or not.
是否移除成功。
bool RemoveByKey(string key);
///
- /// 异步方法:移除一个键值对。
+ /// Remove a key-value pair.
+ /// 移除一个键值对。
///
- ///
- ///
+ /// Key
键
+ /// Whether the removal was successful or not.
是否移除成功。
Task RemoveByKeyAsync(string key);
///
- /// 同步方法:清空缓存。
+ /// Clear the cache.
+ /// 清空缓存。
///
void Clear();
///
- /// 异步方法:清空缓存。
+ /// Clear the cache.
+ /// 清空缓存。
///
- ///
Task ClearAsync();
///
diff --git a/TYLDDB/Utils/FastCache/SemaphoreThreadLock.cs b/TYLDDB/Utils/FastCache/SemaphoreThreadLock.cs
index 20c9e8f..c7ff0a5 100644
--- a/TYLDDB/Utils/FastCache/SemaphoreThreadLock.cs
+++ b/TYLDDB/Utils/FastCache/SemaphoreThreadLock.cs
@@ -103,11 +103,12 @@ public override async Task> GetKeysByValueAsync(string value)
}
///
- /// 同步方法:设置一个键值对。
+ /// Set a key-value pair.
+ /// 设置一个键值对。
///
- ///
- ///
- ///
+ /// Key
键
+ /// Value
值
+ /// Whether the Settings are successful.
是否设置成功
public override bool Set(string key, string value)
{
lock (semaphore)
@@ -129,11 +130,12 @@ public override bool Set(string key, string value)
}
///
- /// 异步方法:设置一个键值对。
+ /// Set a key-value pair.
+ /// 设置一个键值对。
///
- ///
- ///
- ///
+ /// Key
键
+ /// Value
值
+ /// Whether the Settings are successful.
是否设置成功
public override async Task SetAsync(string key, string value)
{
await semaphore.WaitAsync();
diff --git a/TYLDDB/Utils/Writer.cs b/TYLDDB/Utils/Writer.cs
index 75e8674..2f15b1b 100644
--- a/TYLDDB/Utils/Writer.cs
+++ b/TYLDDB/Utils/Writer.cs
@@ -1,10 +1,114 @@
-namespace TYLDDB.Utils
+using System;
+using System.IO;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TYLDDB.Utils
{
///
- /// A class used to write contents into the file
- /// 用于写入文件的类
+ /// A class used to write contents into the file.
+ /// Suitable for writing to slower hard drives, such as mechanical hard drives.
+ /// Suitable for asynchronously writing to slow hard drives, such as mechanical hard drives.
+ /// Ideal for writing to fast hard drives, such as solid state drives.
+ /// Ideal for asynchronously writing content in faster hard drives, such as solid state drives.
+ /// 用于写入文件的类。
+ /// 适用于在较慢的硬盘中写入内容,如机械硬盘。
+ /// 适用于在较慢的硬盘中异步写入内容,如机械硬盘。
+ /// 适用于在较快的硬盘中写入内容,如固态硬盘。
+ /// 适用于在较快的硬盘中异步写入内容,如固态硬盘。
///
- public class Writer
+ public struct Writer
{
+ ///
+ /// Write large strings to a file synchronously.
+ /// 同步写入大字符串到文件。
+ ///
+ /// File path
文件路径
+ /// Written content
写入的内容
+ public static void WriteStringToFile(string filePath, string content)
+ {
+ // 使用64KB的缓冲区
+ int bufferSize = 64 * 1024; // 64KB 缓冲区
+
+ // 使用FileStream打开文件,确保文件完全覆盖而不是追加
+ using FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize);
+ using StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, bufferSize);
+ // 写入内容
+ writer.Write(content);
+ }
+
+ ///
+ /// Asynchronously writes large strings to a file.
+ /// 异步写入大字符串到文件。
+ ///
+ /// File path
文件路径
+ /// Written content
写入的内容
+ public static async void WriteStringToFileAsync(string filePath, string content)
+ {
+ // 使用64KB的缓冲区
+ int bufferSize = 64 * 1024; // 64KB 缓冲区
+
+ // 使用FileStream打开文件,确保文件完全覆盖而不是追加
+ using FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize);
+ using StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, bufferSize);
+ // 异步写入内容
+ await writer.WriteAsync(content);
+ }
+
+ ///
+ /// Write large strings to the file in blocks.
+ /// 分块写入大字符串到文件。
+ ///
+ /// File path
文件路径
+ /// Written content
写入的内容
+ /// Block size
分块大小
+ public static void WriteStringToFileInChunks(string filePath, string content, int chunkSize = 64 * 1024)
+ {
+
+ // 将字符串转换为字节数组
+ byte[] contentBytes = Encoding.UTF8.GetBytes(content);
+
+ using FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, chunkSize);
+ using StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, chunkSize);
+ int totalLength = contentBytes.Length;
+ int offset = 0;
+
+ while (offset < totalLength)
+ {
+ int length = Math.Min(chunkSize, totalLength - offset);
+ writer.Write(Encoding.UTF8.GetString(contentBytes, offset, length));
+ offset += length;
+ }
+ }
+
+ ///
+ /// Asynchronously blocks large strings to a file.
+ /// 异步分块写入大字符串到文件。
+ ///
+ /// File path
文件路径
+ /// Written content
写入的内容
+ /// Block size
分块大小
+ public static async void WriteStringToFileInChunksAsync(string filePath, string content, int chunkSize = 64 * 1024)
+ {
+ // 将字符串转换为字节数组
+ byte[] contentBytes = Encoding.UTF8.GetBytes(content);
+
+ using FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, chunkSize);
+ using StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, chunkSize);
+ int totalLength = contentBytes.Length;
+ int offset = 0;
+
+ while (offset < totalLength)
+ {
+ int length = Math.Min(chunkSize, totalLength - offset);
+ string chunk = Encoding.UTF8.GetString(contentBytes, offset, length);
+
+ // 异步写入当前块
+ await writer.WriteAsync(chunk);
+
+ // 更新偏移量
+ offset += length;
+ }
+ }
}
}
diff --git a/TYLDDB.Test/HighPrecisionTimer.cs b/TimeRecord/HighPrecisionTimer.cs
similarity index 55%
rename from TYLDDB.Test/HighPrecisionTimer.cs
rename to TimeRecord/HighPrecisionTimer.cs
index 820804a..352b977 100644
--- a/TYLDDB.Test/HighPrecisionTimer.cs
+++ b/TimeRecord/HighPrecisionTimer.cs
@@ -1,8 +1,8 @@
using System.Diagnostics;
-namespace TYLDDB.Test
+namespace TimeRecord
{
- internal class HighPrecisionTimer
+ public class HighPrecisionTimer
{
private Stopwatch stopwatch;
@@ -11,31 +11,43 @@ public HighPrecisionTimer()
stopwatch = new Stopwatch();
}
- // 启动计时器
+ ///
+ /// 启动计时器
+ ///
public void Start()
{
stopwatch.Start();
}
- // 停止计时器
+ ///
+ /// 停止计时器
+ ///
public void Stop()
{
stopwatch.Stop();
}
- // 重置计时器
+ ///
+ /// 重置计时器
+ ///
public void Reset()
{
stopwatch.Reset();
}
- // 获取已用时间(毫秒)
+ ///
+ /// 获取已用时间(毫秒)
+ ///
+ ///
public double ElapsedMilliseconds()
{
return stopwatch.Elapsed.TotalMilliseconds;
}
- // 获取已用时间(秒)
+ ///
+ /// 获取已用时间(秒)
+ ///
+ ///
public double ElapsedSeconds()
{
return stopwatch.Elapsed.TotalSeconds;
diff --git a/TimeRecord/TimeRecord.csproj b/TimeRecord/TimeRecord.csproj
new file mode 100644
index 0000000..fa71b7a
--- /dev/null
+++ b/TimeRecord/TimeRecord.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+