• 大小: 266KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: C#
  • 标签: c#  

资源简介

一个C#版的B+树实现,大家可以不太去关注算法本身(算法本省我也不是本人所写),可以把它认为是一个高效的持久hashtable。这个Prototype是我在遇到一个key-value问题时候,压力测试的雏形。

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Web.Security;
using RINP.Services.Common.BPlusTree;

namespace BPlusTreeTest
{
    class Program
    {
        private const string TreeDataDir = @“D:\tmp“;
        private const int DefaultNodeSize = 32;
        private const int DefaultKeyLength = 32;
        private static BplusTreeLong _treeProperty;
        private const string SmsContent = “数字签名可以保证信息的原始性、完整性。因此,数字签名可以解决否认、伪造、篡改及冒充等问题。具体要求:发送:昔事后不能否认发送的报文签名、接收者能够核实发送者发送的报文签名、接收者不能伪造发送者的报文签名、接收者不能对发送者的报文进行部分篡改、网络中的某一用户不能冒充另一用户作为发送者或接收者。数字签名的应用范围十分广泛,在保障电子数据交换(EDI)的安全性上是一个突破性的进展,凡是需要对用户的身份进行判断的情况都可以使用数字签名,比如加密信件、商务信函、定货购买系统、远程金融交易、电子政务、自动模式处理等等。 “;
        private const int StatCount = 10000;
        private static readonly int LcId = System.Globalization.CultureInfo.InvariantCulture.LCID;

        static void Main(string[] args)
        {
            if (!Directory.Exists(TreeDataDir))
            {
                Directory.CreateDirectory(TreeDataDir);
            }

            Process();
        }

        private static void Process()
        {
            var stopwatch = new System.Diagnostics.Stopwatch();
            var index = 1;
            var batchIndex = 1;
            for (int i = 0; i < 1000000; i++)
            {
                if (index == 1)
                {
                    stopwatch.Start();
                }

                var key = FormsAuthentication.HashPasswordForStoringInConfigFile(SmsContent + i “MD5“);
                if (!TreeProperty.ContainsKey(key))
                {
                    try
                    {
                        TreeProperty[key] = i;
                        TreeProperty.Commit();
                    }
                    catch (Exception ex)
                    {
                        TreeProperty.Shutdown();
                        _treeProperty = null;
                        var keyFile = Path.Combine(TreeDataDir TreeFileName);
                        if(File.Exists(keyFile))
                        {
                            File.Delete(keyFile);
                            Console.WriteLine(“Delete The Bad Key File Done!“);
                        }

                        TreeProperty[key] = i;
                        TreeProperty.Commit();
                    }

                }
                else
                {
                    Console.WriteLine(“ContainsKey:“ + key);
                }

                index++;

                if (index == StatCount)
                {
                    stopwatch.Stop();
                    var spendSeconds = stopwatch.Elapsed.TotalSeconds;
                    var speed = StatCount / spendSeconds;
                    Console.WriteLine(batchIndex + “.Speed:“ + speed.ToString(“0.00“) + “/s“);
                    stopwatch.Reset();
                    index = 1;
                    batchIndex++;
                }
            }

            TreeProp

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      59392  2011-08-05 09:26  RINP.Services.Common.BPlusTree\bin\Debug\RINP.Services.Common.BPlusTree.dll

     文件     185856  2011-08-05 09:26  RINP.Services.Common.BPlusTree\bin\Debug\RINP.Services.Common.BPlusTree.pdb

    ......R      7052  2011-07-19 11:53  RINP.Services.Common.BPlusTree\BplusTree.cs

    ......R     11595  2011-07-19 11:53  RINP.Services.Common.BPlusTree\BplusTreeBytes.cs

    ......R     95005  2011-07-19 11:53  RINP.Services.Common.BPlusTree\BplusTreeLong.cs

    ......R     10330  2011-07-19 11:53  RINP.Services.Common.BPlusTree\BufferFile.cs

    ......R      3372  2011-07-19 11:53  RINP.Services.Common.BPlusTree\HBplusTree.cs

    ......R      7190  2011-07-19 11:53  RINP.Services.Common.BPlusTree\HBplusTreeBytes.cs

    ......R      4475  2011-07-19 11:53  RINP.Services.Common.BPlusTree\ITreeIndex.cs

    ......R     19143  2011-07-19 11:53  RINP.Services.Common.BPlusTree\linkedFile.cs

     文件        556  2011-06-28 10:13  RINP.Services.Common.BPlusTree\obj\Debug\RINP.Services.Common.BPlusTree.csproj.FileListAbsolute.txt

     文件      59392  2011-08-05 09:26  RINP.Services.Common.BPlusTree\obj\Debug\RINP.Services.Common.BPlusTree.dll

     文件     185856  2011-08-05 09:26  RINP.Services.Common.BPlusTree\obj\Debug\RINP.Services.Common.BPlusTree.pdb

    ......R      1472  2011-07-19 11:53  RINP.Services.Common.BPlusTree\Properties\AssemblyInfo.cs

    ......R      3120  2011-07-19 11:53  RINP.Services.Common.BPlusTree\RINP.Services.Common.BPlusTree.csproj

     文件        168  2011-06-22 09:22  RINP.Services.Common.BPlusTree\RINP.Services.Common.BPlusTree.csproj.user

    ......R       257  2011-07-19 11:53  RINP.Services.Common.BPlusTree\RINP.Services.Common.BPlusTree.csproj.vspscc

    ......R      2698  2011-07-19 11:53  RINP.Services.Common.BPlusTree\SerializedTree.cs

    ......R      3250  2011-07-19 11:53  RINP.Services.Common.BPlusTree\XBplusTree.cs

    ......R     16814  2011-07-19 11:53  RINP.Services.Common.BPlusTree\XBplusTreeBytes.cs

     文件       9716  2011-09-06 17:13  BPlusTree.5.0.ReSharper.user

    ......R      2049  2011-07-19 11:53  BPlusTree.sln

    ..A..H.     30208  2011-09-06 17:13  BPlusTree.suo

    ......R       256  2011-07-19 11:53  BPlusTree.vssscc

     文件          4  2013-02-17 10:31  _ReSharper.BPlusTree\BuildscriptCache\.crc

     文件          4  2013-02-17 10:31  _ReSharper.BPlusTree\BuildscriptCache\.version

     文件        185  2013-02-17 10:31  _ReSharper.BPlusTree\BuildscriptCache\4\56ba96d6.dat

     文件         58  2011-06-27 14:44  _ReSharper.BPlusTree\DecompilerCache\metadata\mscorlib-69b6\Assembly.Location.txt

     文件       4295  2011-06-27 14:44  _ReSharper.BPlusTree\DecompilerCache\metadata\mscorlib-69b6\System.Collections.Hashtable.cs

     文件        936  2011-06-27 14:44  _ReSharper.BPlusTree\DecompilerCache\metadata\mscorlib-69b6\System.Collections.Hashtable.cs.flags

............此处省略72个文件信息

评论

共有 条评论