Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TYLDDB-CSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Global
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDFD566C-CB13-43EB-970E-0EC0A21E36C0}.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}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{F95CF6BC-2255-47F8-AAB3-B7812BB2894D}.Debug|Any CPU.Build.0 = Release|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
EndGlobalSection
Expand Down
276 changes: 150 additions & 126 deletions TYLDDB.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,157 +1,181 @@
using TimeRecord;
using TYLDDB;

string dbFilePath = "./example.lddb";
List<string> testData = [];

#region 实例化
///////////////////////////////////////////////////////////////////////////////////////////////////////// 实例化
var lddb = new LDDB();
#endregion

#region 读取文件
///////////////////////////////////////////////////////////////////////////////////////////////////////// 读取文件
HighPrecisionTimer readDbTimer = new(); // 从发起读取文件到成功读取的总时间
lddb.FilePath = dbFilePath;
readDbTimer.Start();
lddb.ReadingFile();
readDbTimer.Stop();
WriteTime("从发起读取文件指令到成功读取的总时间为: ", readDbTimer.ElapsedMilliseconds());
#endregion

#region 读取数据库
///////////////////////////////////////////////////////////////////////////////////////////////////////// 读取数据库
HighPrecisionTimer loadDbTimer = new(); // 从发起读取数据库到成功返回读取内容的总时间
loadDbTimer.Start();
lddb.LoadDatabase("database1");
Console.WriteLine(lddb.GetLoadingDatabaseContent()); // 输出database1内容
loadDbTimer.Stop();
WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为(V1): ", loadDbTimer.ElapsedMilliseconds());

HighPrecisionTimer loadDbV2Timer = new(); // 从发起读取数据库到成功返回读取内容的总时间
loadDbV2Timer.Start();
lddb.LoadDatabase_V2("database1");
Console.WriteLine(lddb.GetLoadingDatabaseContent()); // 输出database1内容
loadDbV2Timer.Stop();
WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为(V2): ", loadDbV2Timer.ElapsedMilliseconds());
#endregion

#region 获取所有数据库名称
///////////////////////////////////////////////////////////////////////////////////////////////////////// 获取所有数据库名称
HighPrecisionTimer readAllDbNameTimer = new(); // 从发起读取数据库名称到成功返回读取内容的总时间
readAllDbNameTimer.Start();
lddb.ReadAllDatabaseName();
readAllDbNameTimer.Stop();
if(lddb.AllDatabaseName != null)
internal class Program

Check notice

Code scanning / Sonarscharp (reported by Codacy)

Move 'Program' into a named namespace. Note test

Move 'Program' into a named namespace.

Check notice

Code scanning / Sonarscharp (reported by Codacy)

Add a 'protected' constructor or the 'static' keyword to the class declaration. Note test

Add a 'protected' constructor or the 'static' keyword to the class declaration.
{
foreach (var dbName in lddb.AllDatabaseName)
private static void Main()
{
Console.WriteLine(dbName);
Test test = new();
test.TestMethod();
}

}
WriteTime("从发起读取数据库名称到成功返回读取内容的总时间为: ", readAllDbNameTimer.ElapsedMilliseconds());
#endregion

///////////////////////////////////////////////////////////////////////////////////////////////////////// 数据库解析缓存
HighPrecisionTimer parseDbTimer = new();
parseDbTimer.Start();
await lddb.Parse_V1();
parseDbTimer.Stop();
WriteTime("解析文件并写入缓存V1(同步): ", parseDbTimer.ElapsedMilliseconds());
HighPrecisionTimer parseDbTimerAsync = new();
parseDbTimerAsync.Start();
await lddb.ParseAsync_V1();
parseDbTimerAsync.Stop();
WriteTime("解析文件并写入缓存V1(异步): ", parseDbTimerAsync.ElapsedMilliseconds());

//HighPrecisionTimer parseDbV2Timer = new();
//parseDbV2Timer.Start();
//lddb.Parse_V2();
//parseDbV2Timer.Stop();
//WriteTime("解析文件并写入缓存V1(同步): ", parseDbV2Timer.ElapsedMilliseconds());

///////////////////////////////////////////////////////////////////////////////////////////////////////// 并发词典数据库全类型同步搜寻
HighPrecisionTimer allTypeSearchFromConcurrentDictionaryTimer = new();
allTypeSearchFromConcurrentDictionaryTimer.Start();
string[] AllTypeSearchFromConcurrentDictionaryResult = lddb.AllTypeSearchFromConcurrentDictionary("str_name");
allTypeSearchFromConcurrentDictionaryTimer.Stop();
// 使用 foreach 输出数组的每个元素
foreach (var str in AllTypeSearchFromConcurrentDictionaryResult)
{
Console.WriteLine(str);
}
WriteTime("并发词典数据库全类型同步搜寻: ", allTypeSearchFromConcurrentDictionaryTimer.ElapsedMilliseconds());

///////////////////////////////////////////////////////////////////////////////////////////////////////// 信号量线程锁词典数据库全类型同步搜寻
HighPrecisionTimer allTypeSearchFromSemaphoreThreadLockTimer = new();
allTypeSearchFromSemaphoreThreadLockTimer.Start();
string[] AllTypeSearchFromSemaphoreThreadLockResult = lddb.AllTypeSearchFromSemaphoreThreadLock("str_name");
allTypeSearchFromSemaphoreThreadLockTimer.Stop();
// 使用 foreach 输出数组的每个元素
foreach (var str in AllTypeSearchFromSemaphoreThreadLockResult)
{
Console.WriteLine(str);
}
WriteTime("信号量线程锁词典数据库全类型同步搜寻: ", allTypeSearchFromSemaphoreThreadLockTimer.ElapsedMilliseconds());








class Test

Check notice

Code scanning / Sonarscharp (reported by Codacy)

Move 'Test' into a named namespace. Note test

Move 'Test' into a named namespace.
{
private readonly LDDB lddb = new();
private readonly string dbFilePath = "./example.lddb";
private readonly List<string> testData = [];

public void TestMethod()
{
ReadFile();

ReadDatabase();

GetAllDatabaseName();

ParseDatabaseToTemp();

CdAllTypeSearch();

StlAllTypeSearch();

TripleDictionaryTest();

ExportTestData();
Console.ReadLine();
}

#region Test Method
private void ReadFile()
{
#region 读取文件
///////////////////////////////////////////////////////////////////////////////////////////////////////// 读取文件
HighPrecisionTimer readDbTimer = new(); // 从发起读取文件到成功读取的总时间
lddb.FilePath = dbFilePath;
readDbTimer.Start();
lddb.ReadingFile();
readDbTimer.Stop();
WriteTime("从发起读取文件指令到成功读取的总时间为: ", readDbTimer.ElapsedMilliseconds());
#endregion
}

private void ReadDatabase()
{
#region 读取数据库
///////////////////////////////////////////////////////////////////////////////////////////////////////// 读取数据库
HighPrecisionTimer loadDbTimer = new(); // 从发起读取数据库到成功返回读取内容的总时间
loadDbTimer.Start();
lddb.LoadDatabase("database1");
Console.WriteLine(lddb.GetLoadingDatabaseContent()); // 输出database1内容
loadDbTimer.Stop();
WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为(V1): ", loadDbTimer.ElapsedMilliseconds());

HighPrecisionTimer loadDbV2Timer = new(); // 从发起读取数据库到成功返回读取内容的总时间
loadDbV2Timer.Start();
lddb.LoadDatabase_V2("database1");
Console.WriteLine(lddb.GetLoadingDatabaseContent()); // 输出database1内容
loadDbV2Timer.Stop();
WriteTime("从发起读取数据库指令到成功返回读取内容的总时间为(V2): ", loadDbV2Timer.ElapsedMilliseconds());
#endregion
}

private void GetAllDatabaseName()
{
#region 获取所有数据库名称
///////////////////////////////////////////////////////////////////////////////////////////////////////// 获取所有数据库名称
HighPrecisionTimer readAllDbNameTimer = new(); // 从发起读取数据库名称到成功返回读取内容的总时间
readAllDbNameTimer.Start();
lddb.ReadAllDatabaseName();
readAllDbNameTimer.Stop();
if (lddb.AllDatabaseName != null)
{
foreach (var dbName in lddb.AllDatabaseName)
{
Console.WriteLine(dbName);
}
}
WriteTime("从发起读取数据库名称到成功返回读取内容的总时间为: ", readAllDbNameTimer.ElapsedMilliseconds());
#endregion
}

async void ParseDatabaseToTemp()

Check notice

Code scanning / Sonarscharp (reported by Codacy)

Return 'Task' instead. Note test

Return 'Task' instead.
{
#region 数据库解析缓存
HighPrecisionTimer parseDbTimer = new();
parseDbTimer.Start();
lddb.Parse_V1();
parseDbTimer.Stop();
WriteTime("解析文件并写入缓存V1(同步): ", parseDbTimer.ElapsedMilliseconds());
HighPrecisionTimer parseDbTimerAsync = new();
parseDbTimerAsync.Start();
await lddb.ParseAsync_V1();
parseDbTimerAsync.Stop();
WriteTime("解析文件并写入缓存V1(异步): ", parseDbTimerAsync.ElapsedMilliseconds());
#endregion
}

private void CdAllTypeSearch()
{
#region 并发词典数据库全类型搜寻
HighPrecisionTimer allTypeSearchFromConcurrentDictionaryTimer = new();
allTypeSearchFromConcurrentDictionaryTimer.Start();
string[] AllTypeSearchFromConcurrentDictionaryResult = lddb.AllTypeSearchFromConcurrentDictionary("str_name");
allTypeSearchFromConcurrentDictionaryTimer.Stop();
// 使用 foreach 输出数组的每个元素
foreach (var str in AllTypeSearchFromConcurrentDictionaryResult)
{
Console.WriteLine(str);
}
WriteTime("并发词典数据库全类型同步搜寻: ", allTypeSearchFromConcurrentDictionaryTimer.ElapsedMilliseconds());
#endregion
}

private void StlAllTypeSearch()
{
#region 信号量线程锁词典数据库全类型搜寻
HighPrecisionTimer allTypeSearchFromSemaphoreThreadLockTimer = new();
allTypeSearchFromSemaphoreThreadLockTimer.Start();
string[] AllTypeSearchFromSemaphoreThreadLockResult = lddb.AllTypeSearchFromSemaphoreThreadLock("str_name");

Check warning

Code scanning / Sonarscharp (reported by Codacy)

Add the 'const' modifier to 'directoryPath'. Warning test

Add the 'const' modifier to 'directoryPath'.
allTypeSearchFromSemaphoreThreadLockTimer.Stop();
// 使用 foreach 输出数组的每个元素
foreach (var str in AllTypeSearchFromSemaphoreThreadLockResult)
{
Console.WriteLine(str);
}
WriteTime("信号量线程锁词典数据库全类型搜寻: ", allTypeSearchFromSemaphoreThreadLockTimer.ElapsedMilliseconds());
#endregion
}

ExportTestData();
Console.ReadLine();
private void TripleDictionaryTest()
{
HighPrecisionTimer parse = new();
parse.Start();
lddb.TripleDictParse();
parse.Stop();
WriteTime("三值字典解析并写入(同步): ", parse.ElapsedMilliseconds());
}
#endregion

////////////////////////////////////////////////////////////////////////////////////////////////////////// Test Method
#region 工具
private void WriteTime(string what, double time)
{
string data = what + time + "ms\n";
Console.WriteLine(data);
testData.Add(data);
Console.WriteLine();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////// 工具
void WriteTime(string what, double time)
{
string data = what + time + "ms\n";
Console.WriteLine(data);
AddTestData(data);
Console.WriteLine();
}
private void ExportTestData()
{
// 获取当前日期和时间,格式化为 "yyyy-MM-dd HH-mm"
string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm") + ".txt";

void AddTestData(string data)
{
testData.Add(data);
}
// 指定文件路径
string directoryPath = "./testdata/";
string filePath = Path.Combine(directoryPath, fileName);

void ExportTestData()
{
// 获取当前日期和时间,格式化为 "yyyy-MM-dd HH-mm"
string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm") + ".txt";
// 确保目录存在,如果不存在则创建
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}

// 指定文件路径
string directoryPath = "./testdata/";
string filePath = Path.Combine(directoryPath, fileName);
// 将 List<string> 中的每一行写入文件
File.WriteAllLines(filePath, testData);

// 确保目录存在,如果不存在则创建
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
Console.WriteLine($"数据已成功写入文件: {filePath}");
}

// 将 List<string> 中的每一行写入文件
File.WriteAllLines(filePath, testData);

Console.WriteLine($"数据已成功写入文件: {filePath}");
#endregion
}
10 changes: 5 additions & 5 deletions TYLDDB/TYLDDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0;net9.0;net6.0-windows;net7.0-windows;net8.0-windows;net9.0-windows</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>TYLDDB.NET</Title>
<Version>1.0.0-alpha.4pre2</Version>
<Version>1.0.0-alpha.4</Version>
<Authors>TYLDDB-Project</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/TYLDDB/TYLDDB-CSharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>ttypdb.qingyi-studio.top</PackageProjectUrl>
<PackageProjectUrl>https://tylddb.qingyi-studio.top</PackageProjectUrl>
<Copyright>BSD 3-Clause License (Modified)</Copyright>
<Description>A strongly typed constrained distributed file system that can act as a database.</Description>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageTags>DataBase</PackageTags>
<Company>QingYi-Studio</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>- Optimize error classes: Add more refined error handling and throwing.
- Allows you to customize the buffer size when reading files in blocks.
- Add a three-value dictionary (under test).</PackageReleaseNotes>
<PackageReleaseNotes>· Apply a three-value dictionary.
· Optimizing LDDB.Parse_V1()
· Add more instantiation overloads</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading