/// <summary> /// Sets the capacity to the following number of levels. /// </summary> /// <param name="count">the number of levels to include.</param> private void SetCapacity(int count) { m_nodes = new SortedTreeNodeBase <TKey, SnapUInt32> [count]; for (int x = 0; x < m_nodes.Length; x++) { m_nodes[x] = m_initializer.Clone((byte)(x + 1)); m_nodes[x].Initialize(m_stream, m_blockSize, m_getNextNewNodeIndex, this); } }
internal static void TestSpeed <TKey, TValue>(SortedTreeNodeBase <TKey, TValue> nodeInitializer, TreeNodeRandomizerBase <TKey, TValue> randomizer, int count, int pageSize) where TKey : SnapTypeBase <TKey>, new() where TValue : SnapTypeBase <TValue>, new() { int Max = count; uint nextKeyIndex = 2; Func <uint> getNextKey = () => { nextKeyIndex++; return(nextKeyIndex - 1); }; using (BinaryStream bs = new BinaryStream()) { randomizer.Reset(Max); for (int x = 0; x < Max; x++) { randomizer.Next(); } TKey key = new TKey(); TValue value = new TValue(); SortedTreeNodeBase <TKey, TValue> node = null; System.Console.WriteLine(StepTimer.Time(count, (sw) => { nextKeyIndex = 2; node = nodeInitializer.Clone(0); SparseIndex <TKey> sparse = new SparseIndex <TKey>(); sparse.Initialize(bs, pageSize, getNextKey, 0, 1); node.Initialize(bs, pageSize, getNextKey, sparse); node.CreateEmptyNode(1); sw.Start(); for (int x = 0; x < Max; x++) { //Add the next point randomizer.GetRandom(x, key, value); if (!node.TryInsert(key, value)) { throw new Exception(); } } sw.Stop(); })); System.Console.WriteLine(StepTimer.Time(count, () => { for (int x = 0; x < Max; x++) { //Add the next point randomizer.GetRandom(x, key, value); if (!node.TryGet(key, value)) { throw new Exception(); } } })); System.Console.WriteLine(StepTimer.Time(count, () => { SortedTreeScannerBase <TKey, TValue> scanner = node.CreateTreeScanner(); scanner.SeekToStart(); while (scanner.Read(key, value)) { ; } })); node = node; } }