CSharpTest.Net
EnumerateRange Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > BTreeDictionary<TKey,TValue> Class : EnumerateRange Method

start
end

Glossary Item Box

Inclusivly enumerates from start key to stop key

Syntax

Visual Basic (Declaration) 
Public Function EnumerateRange( _
   ByVal start As TKey, _
   ByVal end As TKey _
) As IEnumerable(Of KeyValuePair(Of TKey,TValue))
C# 
public IEnumerable<KeyValuePair<TKey,TValue>> EnumerateRange( 
   TKey start,
   TKey end
)

Parameters

start
end

Example

Library/Library.Test/TestBTreeDictionary.cs

C#Copy Code
BTreeDictionary<int, string> data = new BTreeDictionary<int, string>(Comparer);
for (int i = 0; i < 100; i++)
    Assert.IsTrue(data.TryAdd(i, i.ToString()));

int ix = 0;
foreach (KeyValuePair<int, string> kv in data.EnumerateRange(-500, 5000))
    Assert.AreEqual(ix++, kv.Key);
Assert.AreEqual(100, ix);

foreach (
    KeyValuePair<int, int> range in
        new Dictionary<int, int> {{6, 25}, {7, 25}, {8, 25}, {9, 25}, {22, 25}, {28, 28}})
{
    ix = range.Key;
    foreach (KeyValuePair<int, string> kv in data.EnumerateRange(ix, range.Value))
        Assert.AreEqual(ix++, kv.Key);
    Assert.AreEqual(range.Value, ix - 1);
}
VB.NETCopy Code
Dim data As New BTreeDictionary(Of Integer, String)(Comparer)
Dim i As Integer = 0
While i < 100
    Assert.IsTrue(data.TryAdd(i, i.ToString()))
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

Dim ix As Integer = 0
For Each kv As KeyValuePair(Of Integer, String) In data.EnumerateRange(-500, 5000)
    Assert.AreEqual(System.Math.Max(System.Threading.Interlocked.Increment(ix),ix - 1), kv.Key)
Next
Assert.AreEqual(100, ix)

For Each range As KeyValuePair(Of Integer, Integer) In New Dictionary(Of Integer, Integer)() From { _
    {6, 25}, _
    {7, 25}, _
    {8, 25}, _
    {9, 25}, _
    {22, 25}, _
    {28, 28} _
}
    ix = range.Key
    For Each kv As KeyValuePair(Of Integer, String) In data.EnumerateRange(ix, range.Value)
        Assert.AreEqual(System.Math.Max(System.Threading.Interlocked.Increment(ix),ix - 1), kv.Key)
    Next
    Assert.AreEqual(range.Value, ix - 1)
Next

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys