swiss ok, needs more benchmark

This commit is contained in:
Youmu Liu
2026-03-06 18:22:30 +08:00
parent 83997f64d0
commit f6e897ed06
70 changed files with 1889 additions and 3371 deletions
+9 -7
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="TestSwiss"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -41,21 +41,23 @@ namespace StgSharp
public static void TestSwiss()
{
SwissTable swiss = SwissTable.Create();
for (int i = 0; i < 10000; i++)
for (int i = 0; i < 5000; i++)
{
Console.Write($"Set {i}: ");
_ = swiss.TryAddOrSet(i, i * 2, out _);
Console.WriteLine($"Set a kvp of ({i},{i * 2})");
}
Random rand = new Random();
for (int i = 0; i < 10000; i++)
for (int i = 0; i < 100; i++)
{
int key = rand.Next(0, 10000);
Console.Write($"Get {i}: ");
int key = rand.Next(4000, 5000);
if (swiss.TryGet(key, out nint value))
{
Console.WriteLine($"Get a kvp of ({key},{value})");
Console.WriteLine($"Success in get a kvp of ({key},{value})");
} else
{
Console.WriteLine($"Failed to get a kvp of ({key},?)");
Console.WriteLine($"Failed to get a kvp of ({key},?)");
}
}
}