using System; using System.Diagnostics.Contracts; namespace DataStructures.BPlusTreeSpace { public partial class BPlusTree where TKey : IComparable { [Serializable] private class LeafNode : INode where TKey : IComparable { private readonly TValue[] _values; private readonly int _numberOfValues; public LeafNode(int numberOfValues) { Contract.Requires(numberOfValues > 0); _numberOfValues = numberOfValues; _values = new TValue[numberOfValues]; } private int GetChildIndex(TKey key) { Contract.Requires(key != null); Contract.Ensures(Contract.Result() >= 0); Contract.Ensures(Contract.Result() <= _numberOfValues); // Simple linear search. Faster for small values of N or M, binary search would be faster for larger M / N for (int i = 0; i < _numberOfValues; i++) { if (_values[i].Equals(key)) { return i; } } return _numberOfValues; } public TValue GetChild(TKey key) { Contract.Requires(key != null); return _values[GetChildIndex(key)]; } public int GetLocation(TKey key) { throw new NotImplementedException(); } } } }