Dim test As String
Using data As BPlusTree(Of Integer, String) = Create(Options)
data.Add(2, "v2")
data.Add(1, "v1")
Dim i As Integer = 0
While i < 8
data.TryAdd(i, "v" + i)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
i = 16
While i >= 8
data.TryAdd(i, "v" + i)
System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1)
End While
data.TryAdd(13, "v" + i)
i = 0
While i <= 16
If Not data.TryGetValue(i, test) Then
Throw New ApplicationException()
End If
Assert.AreEqual("v" + i, test)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
data.Remove(1)
data.Remove(3)
Dim e As IEnumerator(Of KeyValuePair(Of Integer, String)) = data.GetEnumerator()
Assert.IsTrue(e.MoveNext())
Assert.AreEqual(0, e.Current.Key)
data.Add(1, "v1")
Assert.IsTrue(e.MoveNext())
data.Add(3, "v3")
Assert.IsTrue(e.MoveNext())
data.Remove(8)
Assert.IsTrue(e.MoveNext())
e.Dispose()
data.Add(8, "v8")
i = 0
For Each pair As KeyValuePair(Of Integer, String) In data
Assert.AreEqual(pair.Key, System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1))
Next
i = 0
While i <= 16
Assert.IsTrue(data.Remove(i) AndAlso data.TryAdd(i, "v" + i))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
i = 6
While i <= 12
Assert.IsTrue(data.Remove(i))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
i = 6
While i <= 12
Assert.IsFalse(data.TryGetValue(i, test))
Assert.IsNull(test)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
i = 0
While i <= 5
Assert.IsTrue(data.TryGetValue(i, test))
Assert.AreEqual("v" + i, test)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
i = 13
While i <= 16
Assert.IsTrue(data.TryGetValue(i, test))
Assert.AreEqual("v" + i, test)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
i = 0
While i <= 16
Assert.AreEqual(i < 6 OrElse i > 12, data.Remove(i))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
End Using |