CSharpTest.Net
CalcBTreeOrder Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > BPlusTree.Options<TKey,TValue> Class : CalcBTreeOrder Method

avgKeySizeBytes
avgValueSizeBytes

Glossary Item Box

Calculates default node-threasholds based upon the average number of bytes in key and value

Syntax

Visual Basic (Declaration) 
Public Shadows Function CalcBTreeOrder( _
   ByVal avgKeySizeBytes As Integer, _
   ByVal avgValueSizeBytes As Integer _
) As BPlusTree(Of TKey,TValue)
C# 
public new BPlusTree<TKey,TValue> CalcBTreeOrder( 
   int avgKeySizeBytes,
   int avgValueSizeBytes
)

Parameters

avgKeySizeBytes
avgValueSizeBytes

Example

BPlusTree/BPlusTree.Test/ThreadedBTreeTest.cs

C#Copy Code
BPlusTree<KeyInfo, DataValue>.Options options = new BPlusTree<KeyInfo, DataValue>.Options(
    new KeyInfoSerializer(), new DataValueSerializer(), new KeyInfoComparer());
options.CalcBTreeOrder(32, 300);
options.FileName = TempFile.TempPath;
options.CreateFile = CreatePolicy.Always;

using (TempFile copy = new TempFile())
{
    copy.Delete();
    int minRecordCreated = StartAndAbortWriters(options, copy);

    using (TempFile.Attach(copy.TempPath + ".recovered")) //used to create the new copy
    using (TempFile.Attach(copy.TempPath + ".deleted"))  //renamed existing file
    {
        options.CreateFile = CreatePolicy.Never;
        int recoveredRecords = BPlusTree<KeyInfo, DataValue>.RecoverFile(options);
        if (recoveredRecords < RecordsCreated)
            Assert.Fail("Unable to recover records, recieved ({0} of {1}).", recoveredRecords, RecordsCreated);

        options.FileName = copy.TempPath;
        recoveredRecords = BPlusTree<KeyInfo, DataValue>.RecoverFile(options);
        Assert.IsTrue(recoveredRecords >= minRecordCreated, "Expected at least " + minRecordCreated + " found " + recoveredRecords);

        using (BPlusTree<KeyInfo, DataValue> dictionary = new BPlusTree<KeyInfo, DataValue>(options))
        {
            dictionary.EnableCount();
            Assert.AreEqual(recoveredRecords, dictionary.Count);

            foreach (KeyValuePair<KeyInfo, DataValue> kv in dictionary)
            {
                Assert.AreEqual(kv.Key.UID, kv.Value.Key.UID);
                dictionary.Remove(kv.Key);
            }

            Assert.AreEqual(0, dictionary.Count);
        }
    }
}
VB.NETCopy Code
Dim options As New BPlusTree(Of KeyInfo, DataValue).Options(New KeyInfoSerializer(), New DataValueSerializer(), New KeyInfoComparer())
options.CalcBTreeOrder(32, 300)
options.FileName = TempFile.TempPath
options.CreateFile = CreatePolicy.Always

Using copy As New TempFile()
    copy.Delete()
    Dim minRecordCreated As Integer = StartAndAbortWriters(options, copy)

    Using TempFile.Attach(copy.TempPath + ".recovered")
        'used to create the new copy
        Using TempFile.Attach(copy.TempPath + ".deleted")
            'renamed existing file
            options.CreateFile = CreatePolicy.Never
            Dim recoveredRecords As Integer = BPlusTree(Of KeyInfo, DataValue).RecoverFile(options)
            If recoveredRecords < RecordsCreated Then
                Assert.Fail("Unable to recover records, recieved ({0} of {1}).", recoveredRecords, RecordsCreated)
            End If

            options.FileName = copy.TempPath
            recoveredRecords = BPlusTree(Of KeyInfo, DataValue).RecoverFile(options)
            Assert.IsTrue(recoveredRecords >= minRecordCreated, "Expected at least " + minRecordCreated + " found " + recoveredRecords)

            Using dictionary As New BPlusTree(Of KeyInfo, DataValue)(options)
                dictionary.EnableCount()
                Assert.AreEqual(recoveredRecords, dictionary.Count)

                For Each kv As KeyValuePair(Of KeyInfo, DataValue) In dictionary
                    Assert.AreEqual(kv.Key.UID, kv.Value.Key.UID)
                    dictionary.Remove(kv.Key)
                Next

                Assert.AreEqual(0, dictionary.Count)
            End Using
        End Using
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys