public void Operations_SingleElement() { var key = "oren"; var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add(key, "eini")); Assert.Equal(key, tree.FirstKey()); Assert.Equal(key, tree.LastKey()); Assert.True(tree.Contains(key)); string value; Assert.True(tree.TryGet(key, out value)); // x+ = min{y ? S | y = x} (the successor of x in S) - Page 160 of [1] // Therefore the successor of the key "oren" is greater or equal to "oren" Assert.Equal(key, tree.SuccessorOrDefault(key)); Assert.Null(tree.SuccessorOrDefault("qu")); // x- = max{y ? S | y < x} (the predecessor of x in S) - Page 160 of [1] // Therefore the predecessor of the key "oren" is strictly less than "oren". Assert.Null(tree.PredecessorOrDefault(key)); Assert.Null(tree.PredecessorOrDefault("aq")); Assert.Equal(key, tree.PredecessorOrDefault("pq")); ZFastTrieDebugHelpers.StructuralVerify(tree); }
public void Structure_SingleBranchInsertion() { string lesserKey = "Oren"; string midKey = "aa"; string greaterKey = "oren"; var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add(lesserKey, "eini")); Assert.True(tree.Add(greaterKey, "Eini")); Assert.True(tree.Root.IsInternal); var successor = tree.SuccessorInternal(midKey); Assert.True(successor.IsLeaf); Assert.Null(successor.Next.Key); Assert.NotNull(successor.Previous.Key); Assert.Equal(tree.Tail, successor.Next); var predecessor = tree.PredecessorInternal(midKey); Assert.True(predecessor.IsLeaf); Assert.NotNull(predecessor.Next.Key); Assert.Equal(tree.Head, predecessor.Previous); Assert.Null(predecessor.Previous.Key); Assert.Equal(predecessor.Next, successor); Assert.Equal(successor.Previous, predecessor); ZFastTrieDebugHelpers.StructuralVerify(tree); }
public void Structure_SingleElement() { var key = "oren"; var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add(key, "eini")); var successor = tree.SuccessorInternal(key); Assert.True(successor.IsLeaf); Assert.Null(successor.Next.Key); Assert.Null(successor.Previous.Key); Assert.Equal(tree.Head, successor.Previous); Assert.Equal(tree.Tail, successor.Next); Assert.Equal(key, successor.Key); var predecessor = tree.PredecessorInternal("yy"); Assert.True(predecessor.IsLeaf); Assert.Null(predecessor.Next.Key); Assert.Equal(tree.Head, predecessor.Previous); Assert.Equal(tree.Tail, predecessor.Next); Assert.Null(predecessor.Previous.Key); Assert.Equal(key, predecessor.Key); Assert.Equal(predecessor, successor); Assert.Equal(tree.Root, predecessor); ZFastTrieDebugHelpers.StructuralVerify(tree); }
public void Addition_FailureToPass_QuickPath() { var tree = new ZFastTrieSortedSet <string, string>(binarize); tree.Add("lJCn3J", string.Empty); tree.Add("4wLolJ", string.Empty); tree.Add("FZt4Dp", string.Empty); tree.Add("8NSagc", string.Empty); tree.Add("9eI05C", string.Empty); tree.Add("C4gnS4", string.Empty); tree.Add("PRjxjs", string.Empty); tree.Add("3M7Oxy", string.Empty); tree.Add("boKWpa", string.Empty); tree.Add("FLnjoZ", string.Empty); tree.Add("AE1Jlq", string.Empty); tree.Add("mbHypw", string.Empty); tree.Add("FLnjhT", string.Empty); tree.Add("fvrTYR", string.Empty); tree.Add("2pOGiH", string.Empty); tree.Add("RpmKwf", string.Empty); tree.Add("1ulQmV", string.Empty); tree.Add("rn8YRe", string.Empty); tree.Add("wfnTE2", string.Empty); tree.Add("rqqjR5", string.Empty); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(20, tree.Count); }
public void Construction() { var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.Equal(0, tree.Count); Assert.Null(tree.FirstKeyOrDefault()); Assert.Null(tree.LastKeyOrDefault()); ZFastTrieDebugHelpers.StructuralVerify(tree); }
public void Structure_MultipleBranchInsertion() { var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add("8Jp3", "8Jp")); Assert.True(tree.Add("GX37", "GX3")); Assert.True(tree.Add("f04o", "f04")); Assert.True(tree.Add("KmGx", "KmG")); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(4, tree.Count); }
public void Structure_RandomTester() { int count = 1000; int size = 5; for (int i = 0; i < 1; i++) { var keys = new string[count]; var tree = new ZFastTrieSortedSet <string, string>(binarize); var insertedKeys = new HashSet <string>(); var generator = new Random(i + size); for (int j = 0; j < count; j++) { string key = GenerateRandomString(generator, size); if (!tree.Contains(key)) { tree.Add(key, key); } keys[j] = key; insertedKeys.Add(key); } ZFastTrieDebugHelpers.StructuralVerify(tree); generator = new Random(i + size + 1); for (int j = 0; j < count; j++) { string key = GenerateRandomString(generator, size); if (!insertedKeys.Contains(key)) { Assert.False(tree.Remove(key)); } } generator = new Random(i + size); for (int j = 0; j < count; j++) { string key = GenerateRandomString(generator, size); bool removed = tree.Remove(key); Assert.True(removed); } Assert.Equal(0, tree.Count); } }
public void Structure_MultipleBranch_OrderPreservation() { var tree = new ZFastTrieSortedSet <string, string>(binarize); tree.Add("8Jp3", "8Jp3"); tree.Add("V6sl", "V6sl"); tree.Add("GX37", "GX37"); tree.Add("f04o", "f04o"); tree.Add("KmGx", "KmGx"); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(5, tree.Count); }
public void Structure_MultipleBranch_InternalExtent2() { var tree = new ZFastTrieSortedSet <string, string>(binarize); tree.Add("i", "8Jp3"); tree.Add("4", "V6sl"); tree.Add("j", "GX37"); tree.Add("P", "f04o"); tree.Add("8", "KmGx"); tree.Add("3", "KmG3"); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(6, tree.Count); }
public void Structure_NodesTable_FailedTableVerify() { var tree = new ZFastTrieSortedSet <string, string>(binarize); tree.Add("R", "1q"); tree.Add("F", "3n"); tree.Add("O", "6e"); tree.Add("E", "Fs"); tree.Add("Lr", "LD"); tree.Add("L5", "MU"); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(6, tree.Count); }
public void Structure_MultipleBranch_Simple() { var tree = new ZFastTrieSortedSet <string, string>(binarize); tree.Add("a", "8Jp3"); tree.Add("c", "V6sl"); tree.Add("h", "GX37"); tree.Add("b", "KmGx"); ZFastTrieDebugHelpers.DumpTree(tree); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(4, tree.Count); }
public void Structure_MultipleBranchDeletion3() { var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add("0tA", "0A")); Assert.True(tree.Add("UUa", "Ua")); Assert.True(tree.Add("0b5", "05")); Assert.True(tree.Add("8ll", "8l")); ZFastTrieDebugHelpers.DumpTree(tree); Assert.True(tree.Remove("0tA")); ZFastTrieDebugHelpers.DumpTree(tree); ZFastTrieDebugHelpers.StructuralVerify(tree); }
public void Structure_SingleBranchDeletion() { string lesserKey = "Oren"; string greaterKey = "oren"; var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add(lesserKey, "eini")); Assert.True(tree.Add(greaterKey, "Eini")); Assert.True(tree.Remove(lesserKey)); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.True(tree.Remove(greaterKey)); ZFastTrieDebugHelpers.StructuralVerify(tree); }
public void Structure_MultipleBranchDeletion2() { var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add("CDb", "8J3")); Assert.True(tree.Add("tCK", "GX7")); Assert.True(tree.Add("B25", "f0o")); Assert.True(tree.Add("2mW", "Kmx")); Assert.True(tree.Add("gov", string.Empty)); ZFastTrieDebugHelpers.DumpTree(tree); Assert.True(tree.Remove("CDb")); ZFastTrieDebugHelpers.DumpTree(tree); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(4, tree.Count); }
public void Structure_MultipleBranch_InternalExtent() { var tree = new ZFastTrieSortedSet <string, string>(binarize); tree.Add("8Jp3V6sl", "8Jp3"); ZFastTrieDebugHelpers.DumpTree(tree); tree.Add("VJ7hXe8d", "V6sl"); ZFastTrieDebugHelpers.DumpTree(tree); tree.Add("39XCGX37", "GX37"); ZFastTrieDebugHelpers.DumpTree(tree); tree.Add("f04oKmGx", "f04o"); ZFastTrieDebugHelpers.DumpTree(tree); tree.Add("feiF1gdt", "KmGx"); ZFastTrieDebugHelpers.DumpTree(tree); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(5, tree.Count); }
public void Operations_SingleBranchInsertion() { string smallestKey = "Ar"; string lesserKey = "Oren"; string greaterKey = "oren"; string greatestKey = "zz"; var tree = new ZFastTrieSortedSet <string, string>(binarize); Assert.True(tree.Add(lesserKey, "eini")); ZFastTrieDebugHelpers.DumpTree(tree); Assert.True(tree.Add(greaterKey, "Eini")); ZFastTrieDebugHelpers.DumpTree(tree); ZFastTrieDebugHelpers.StructuralVerify(tree); Assert.Equal(lesserKey, tree.FirstKey()); Assert.Equal(greaterKey, tree.LastKey()); Assert.True(tree.Contains(greaterKey)); Assert.True(tree.Contains(lesserKey)); string value; Assert.True(tree.TryGet(lesserKey, out value)); Assert.True(tree.TryGet(greaterKey, out value)); Assert.False(tree.TryGet(greaterKey + "1", out value)); Assert.False(tree.TryGet("1", out value)); // x+ = min{y ? S | y = x} (the successor of x in S) - Page 160 of [1] // Therefore the successor of the key "oren" is greater or equal to "oren" Assert.Equal(lesserKey, tree.SuccessorOrDefault(lesserKey)); Assert.Equal(greaterKey, tree.SuccessorOrDefault(greaterKey)); Assert.Equal(greaterKey, tree.SuccessorOrDefault(lesserKey + "1")); Assert.Null(tree.SuccessorOrDefault(greatestKey)); // x- = max{y ? S | y < x} (the predecessor of x in S) - Page 160 of [1] // Therefore the predecessor of the key "oren" is strictly less than "oren". Assert.Equal(lesserKey, tree.PredecessorOrDefault(greaterKey)); Assert.Null(tree.PredecessorOrDefault(lesserKey)); Assert.Null(tree.PredecessorOrDefault(smallestKey)); }
public void Structure_CappedSizeInsertion(int seed, int size, int count) { var generator = new Random(seed); var tree = new ZFastTrieSortedSet <string, string>(binarize); var keys = new string[count]; for (int i = 0; i < count; i++) { string key = GenerateRandomString(generator, size); if (!tree.Contains(key)) { tree.Add(key, key); } keys[i] = key; } ZFastTrieDebugHelpers.StructuralVerify(tree); }