public static void TestOmnitree1() { #region construction Omnitree.Locate <TestObject, double> locate = (TestObject record) => { return((int i) => { switch (i) { case 0: return record.X; case 1: return record.Y; case 2: return record.Z; default: throw new System.Exception(); } }); }; Compute <double> .Compare(0, 0); Omnitree <TestObject, double> omnitree = new OmnitreeLinked <TestObject, double>( new double[] { 0, 0, 0 }, new double[] { 1, 1, 1 }, locate, Compute <double> .Compare, (double a, double b) => { return((a + b) / 2); }); #endregion #region random generation Console.WriteLine("Generating random data..."); Random random = new Random(0); int count = 100; TestObject[] records = new TestObject[count]; for (int i = 0; i < count; i++) { records[i] = new TestObject(i, random.NextDouble(), random.NextDouble(), random.NextDouble()); } Console.WriteLine("Generated random data."); #endregion #region adding Console.WriteLine("Building Omnitree..."); for (int i = 0; i < count; i++) { omnitree.Add(records[i]); if (i % (count / 10) == 0) { Console.WriteLine(((double)i / (double)count * 100D) + "%"); } } Console.WriteLine("OmniTree.Count: " + omnitree.Count); //Console.WriteLine("OmniTree._top.Count: " + (omnitree as OmnitreeLinked<TestObject, double>)._top.Count); int test_count = 0; omnitree.Stepper((TestObject record) => { test_count++; }); Console.WriteLine("OmniTree Stepper Count: " + test_count); #endregion #region validation SetHashArray <TestObject> setHash = new SetHashArray <TestObject>( (TestObject a, TestObject b) => { return(a.Id == b.Id); }, (TestObject a) => { return(a.Id.GetHashCode()); }); for (int i = 0; i < count; i++) { setHash.Add(records[i]); } bool validated = true; omnitree.Stepper((TestObject record) => { if (!setHash.Contains(record)) { validated = false; } }); if (validated) { Console.WriteLine("Values Validated."); } else { Console.WriteLine("Values INVALID."); } #endregion #region querying Console.WriteLine("Value Querying: "); bool query_test = false; for (int i = 0; i < count; i++) { query_test = false; omnitree[locate(records[i])]((TestObject record) => { query_test = true; }); if (query_test == false) { Console.WriteLine("Querying INVALID on value: " + i); break; } if (i % (count / 10) == 0) { Console.WriteLine(((double)i / (double)count * 100D) + "%"); } } if (query_test == true) { Console.WriteLine("Querying Validated."); } else { Console.WriteLine("Querying INVALID."); } #endregion #region dynamic values (re-randomizing) Console.WriteLine("Moving randomized data..."); foreach (TestObject record in records) { record.X += Math.Max(0d, Math.Min(1d, (random.NextDouble() / 100D) - .5D)); record.Y += Math.Max(0d, Math.Min(1d, (random.NextDouble() / 100D) - .5D)); record.Z += Math.Max(0d, Math.Min(1d, (random.NextDouble() / 100D) - .5D)); } Console.WriteLine("Randomized data moved."); #endregion #region Updating Console.WriteLine("Updating Tree Positions..."); //// Update Method #1 omnitree.Update(); //// Update Method #2 //omnitree.Update(omnitree.Min, omnitree.Max); Console.WriteLine("Tree Positions Updated."); #endregion #region removal Console.WriteLine("Removing Values: "); for (int i = 0; i < count; i++) { //// Removal Method #1 omnitree.Remove(records[i]); //// Removal Method #2 //omnitree.Remove(locate(records[i]), locate(records[i])); //// Removal Method #3 //omnitree.Remove(locate(records[i]), locate(records[i]), (omnitree_record step) => { return records[i].Id == step.Id; }); //// Removal Method #4 //double[] location = new double[] { locate(records[i])(0), locate(records[i])(1), locate(records[i])(2) }; //omnitree.Remove(location, location); //// Removal Method #5 //double[] location = new double[] { locate(records[i])(0), locate(records[i])(1), locate(records[i])(2) }; //omnitree.Remove(location, location, (omnitree_record step) => { return records[i].Id == step.Id; }); if (omnitree.Count != count - (i + 1)) { throw new System.Exception(); } if (i % (count / 10) == 0) { Console.WriteLine(((double)i / (double)count * 100D) + "%"); } } Console.WriteLine("Values Removed: "); Console.WriteLine("OmniTree.Count: " + omnitree.Count); //Console.WriteLine("OmniTree._top.Count: " + (omnitree as OmnitreeLinked<TestObject, double>)._top.Count); test_count = 0; omnitree.Stepper((TestObject record) => { test_count++; }); Console.WriteLine("OmniTree Stepper Count: " + test_count); #endregion Console.WriteLine(); Console.WriteLine("TEST COMPLETE"); }
static void Main(string[] args) { Random random = new Random(); int test = 10; Console.WriteLine("Welcome To SevenFramework! :)"); Console.WriteLine(); Console.WriteLine("You are runnning the Data Structures example."); Console.WriteLine("======================================================"); Console.WriteLine(); #region Link Console.WriteLine(" Testing Link-------------------------------"); Console.WriteLine(" Size: 6"); Link link = new Link <int, int, int, int, int, int>(0, 1, 2, 3, 4, 5); Console.Write(" Traversal: "); link.Stepper((dynamic current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string linklink_file = "link." + ToExtension(link.GetType()); //Console.WriteLine(" File: \"" + linklink_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(linklink_file, link)); //Link<int, int, int, int, int, int> deserialized_linklink; //Console.WriteLine(" Deserialized: " + Deserialize(linklink_file, out deserialized_linklink)); Console.WriteLine(); #endregion #region Array Console.WriteLine(" Testing Array_Array<int>-------------------"); Array <int> array = new ArrayArray <int>(test); for (int i = 0; i < test; i++) { array[i] = i; } Console.Write(" Traversal: "); array.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string arrayarray_file = "array." + ToExtension(array.GetType()); //Console.WriteLine(" File: \"" + arrayarray_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(arrayarray_file, array)); //ArrayArray<int> deserialized_arrayarray; //Console.WriteLine(" Deserialized: " + Deserialize(arrayarray_file, out deserialized_arrayarray)); Console.WriteLine(); #endregion #region List Console.WriteLine(" Testing List_Array<int>--------------------"); List <int> list_array = new ListArray <int>(test); for (int i = 0; i < test; i++) { list_array.Add(i); } Console.Write(" Traversal: "); list_array.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string listarray_file = "list_array." + ToExtension(list_array.GetType()); //Console.WriteLine(" File: \"" + listarray_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(listarray_file, list_array)); //ListArray<int> deserialized_listarray; //Console.WriteLine(" Deserialized: " + Deserialize(listarray_file, out deserialized_listarray)); Console.WriteLine(); Console.WriteLine(" Testing List_Linked<int>-------------------"); List <int> list_linked = new ListLinked <int>(); for (int i = 0; i < test; i++) { list_linked.Add(i); } Console.Write(" Traversal: "); list_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string listlinked_file = "list_linked." + ToExtension(list_linked.GetType()); //Console.WriteLine(" File: \"" + listlinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(listlinked_file, list_linked)); //ListLinked<int> deserialized_listlinked; //Console.WriteLine(" Deserialized: " + Deserialize(listlinked_file, out deserialized_listlinked)); Console.WriteLine(); #endregion #region Stack Console.WriteLine(" Testing Stack_Linked<int>------------------"); Stack <int> stack_linked = new StackLinked <int>(); for (int i = 0; i < test; i++) { stack_linked.Push(i); } Console.Write(" Traversal: "); stack_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string stacklinked_file = "stack_linked." + ToExtension(stack_linked.GetType()); //Console.WriteLine(" File: \"" + stacklinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(stacklinked_file, stack_linked)); //StackLinked<int> deserialized_stacklinked; //Console.WriteLine(" Deserialized: " + Deserialize(stacklinked_file, out deserialized_stacklinked)); Console.WriteLine(); #endregion #region Queue Console.WriteLine(" Testing Queue_Linked<int>------------------"); Queue <int> queue_linked = new QueueLinked <int>(); for (int i = 0; i < test; i++) { queue_linked.Enqueue(i); } Console.Write(" Traversal: "); queue_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string queuelinked_file = "queue_linked." + ToExtension(queue_linked.GetType()); //Console.WriteLine(" File: \"" + queuelinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(queuelinked_file, queue_linked)); //QueueLinked<int> deserialized_queuelinked; //Console.WriteLine(" Deserialized: " + Deserialize(queuelinked_file, out deserialized_queuelinked)); Console.WriteLine(); #endregion #region Heap Console.WriteLine(" Testing Heap_Array<int>--------------------"); Heap <int> heap_array = new HeapArray <int>(Compute <int> .Compare); for (int i = 0; i < test; i++) { heap_array.Enqueue(i); } Console.Write(" Delegate: "); heap_array.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string heaplinked_file = "heap_array." + ToExtension(heap_array.GetType()); //Console.WriteLine(" File: \"" + heaplinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(heaplinked_file, heap_array)); //HeapArray<int> deserialized_heaplinked; //Console.WriteLine(" Deserialized: " + Deserialize(heaplinked_file, out deserialized_heaplinked)); Console.WriteLine(); #endregion #region Tree Console.WriteLine(" Testing Tree_Map<int>----------------------"); Tree <int> tree_Map = new TreeMap <int>(0, Compute <int> .Equate, Hash.Default); for (int i = 1; i < test; i++) { tree_Map.Add(i, i / (int)System.Math.Sqrt(test)); } Console.Write(" Children of 0 (root): "); tree_Map.Children(0, (int i) => { Console.Write(i + " "); }); Console.WriteLine(); Console.Write(" Children of " + ((int)System.Math.Sqrt(test) - 1) + " (root): "); tree_Map.Children(((int)System.Math.Sqrt(test) - 1), (int i) => { Console.Write(i + " "); }); Console.WriteLine(); Console.Write(" Traversal: "); tree_Map.Stepper((int i) => { Console.Write(i + " "); }); Console.WriteLine(); // Saving to a file //string treelinked_file = "tree_Map." + ToExtension(tree_Map.GetType()); //Console.WriteLine(" File: \"" + treelinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(treelinked_file, tree_Map)); //TreeMap<int> deserialized_treelinked; //Console.WriteLine(" Deserialized: " + Deserialize(treelinked_file, out deserialized_treelinked)); Console.WriteLine(); #endregion #region AVL Tree //Console.WriteLine(" Testing AvlTree_Linked<int>----------------"); //// Construction //AvlTree<int> avlTree_linked = new AvlTree_Linked<int>(Logic.compare); //// Adding Items //Console.Write(" Adding (0-" + test + ")..."); //for (int i = 0; i < test; i++) // avlTree_linked.Add(i); //Console.WriteLine(); //// Iteration //Console.Write(" Traversal: "); //avlTree_linked.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //// Removal //int avl_tree_linked_removal = random.Next(0, test); //avlTree_linked.Remove(avl_tree_linked_removal); //Console.Write(" Remove(" + avl_tree_linked_removal + "): "); //avlTree_linked.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //// Look Up Items //int avl_tree_linked_lookup = random.Next(0, test); //while (avl_tree_linked_lookup == avl_tree_linked_removal) // avl_tree_linked_lookup = random.Next(0, test); //Console.WriteLine(" Look Up (" + avl_tree_linked_lookup + "): " + avlTree_linked.TryGet(avl_tree_linked_lookup, Logic.compare, out temp)); //Console.WriteLine(" Look Up (" + avl_tree_linked_removal + "): " + avlTree_linked.TryGet(avl_tree_linked_removal, Logic.compare, out temp)); //avlTree_linked.Get(avl_tree_linked_lookup, Logic.compare); //// Current Min-Max Values //Console.WriteLine(" Least: " + avlTree_linked.CurrentLeast + " Greatest: " + avlTree_linked.CurrentGreatest); //// Saving to a file //string avltreelinked_file = "avlTree_linked." + ToExtension(avlTree_linked.GetType()); //Console.WriteLine(" File: \"" + avltreelinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(avltreelinked_file, avlTree_linked)); //AvlTree_Linked<int> deserialized_avltreelinked; //Console.WriteLine(" Deserialized: " + Deserialize(avltreelinked_file, out deserialized_avltreelinked)); //Console.WriteLine(); #endregion #region Red-Black Tree Console.WriteLine(" Testing RedBlack_Linked<int>---------------"); RedBlackTree <int> redBlackTree_linked = new RedBlackTreeLinked <int>(Compute <int> .Compare); for (int i = 0; i < test; i++) { redBlackTree_linked.Add(i); } Console.Write(" Traversal: "); redBlackTree_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Saving to a file //string redblacktreelinked_file = "redBlackTree_linked." + ToExtension(redBlackTree_linked.GetType()); //Console.WriteLine(" File: \"" + redblacktreelinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(redblacktreelinked_file, redBlackTree_linked)); //RedBlackTreeLinked<int> deserialized_redblacktreelinked; //Console.WriteLine(" Deserialized: " + Deserialize(redblacktreelinked_file, out deserialized_redblacktreelinked)); Console.WriteLine(); #endregion #region BTree //Console.WriteLine(" Testing BTree_LinkedArray<int>-------------"); //BTree<int> btree_linked = new BTree_LinkedArray<int>(Logic.compare, 3); //for (int i = 0; i < test; i++) // btree_linked.Add(i); //Console.Write(" Delegate: "); //btree_linked.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //Console.Write(" IEnumerator: "); //foreach (int current in btree_linked) // Console.Write(current); //Console.WriteLine(); //Console.WriteLine(" Press Enter to continue..."); //string maplinked_file = "maplinked.quad"; //Console.WriteLine(" File: \"" + maplinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(maplinked_file, hashTable_linked)); //Omnitree_LinkedLinkedLists<int, double> deserialized_maplinked; //Console.WriteLine(" Deserialized: " + Deserialize(maplinked_file, out deserialized_maplinked)); //Console.ReadLine(); //Console.WriteLine(); #endregion #region Set Console.WriteLine(" Testing Set_Hash<int>----------------------"); Set <int> set_linked = new SetHashList <int>(Compute <int> .Equate, Hash.Default); for (int i = 0; i < test; i++) { set_linked.Add(i); } // Traversal Console.Write(" Traversal: "); set_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); Console.Write(" Table Size: " + (set_linked as SetHashList <int>).TableSize); Console.WriteLine(); Console.WriteLine(); #endregion #region Map Console.WriteLine(" Testing MapHashList<int, int>--------------"); Map <int, int> map_sethash = new MapHashLinked <int, int>(Compute <int> .Equate, Hash.Default); for (int i = 0; i < test; i++) { map_sethash.Add(i, i); } Console.Write(" Look Ups: "); for (int i = 0; i < test; i++) { Console.Write(map_sethash[i]); } Console.WriteLine(); // Traversal Console.Write(" Traversal: "); map_sethash.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); Console.Write(" Table Size: " + (map_sethash as MapHashLinked <int, int>).TableSize); Console.WriteLine(); Console.WriteLine(); #endregion #region Quad-Tree //Console.WriteLine(" Testing Quadtree_Array<int, double>--------"); //// Construction //Quadtree<int, double> quadtree_array = new Quadtree_Array<int, double>( // -test - 1, -test - 1, // minimum dimensions of the quadtree // test + 1, test + 1, // maximum dimensions of the quadtree // (int i, out double x, out double y) => { x = i; y = i; }, // 2D location function // Logic.compare, // axis comparison function // Statistics.Mean); // axis average function //// Adding //for (int i = 0; i < test; i++) // quadtree_array.Add(i); //// Proper Traversal //Console.Write(" Traversal: "); //quadtree_array.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //// Saving to a file //string quadtreearray_file = "quadtree_array." + ToExtension(quadtree_array.GetType()); //Console.WriteLine(" File: \"" + quadtreearray_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(quadtreearray_file, quadtree_array)); //Quadtree_Array<int, double> deserialized_quadtreearray; //Console.WriteLine(" Deserialized: " + Deserialize(quadtreearray_file, out deserialized_quadtreearray)); //Console.WriteLine(); //Console.WriteLine(" Testing Quadtree_Linked<int, double>-------"); //// Construction //Quadtree<int, double> quadtree_linked = new Quadtree_Linked<int, double>( // -test - 1, -test - 1, // minimum dimensions of the quadtree // test + 1, test + 1, // maximum dimensions of the quadtree // (int i, out double x, out double y) => { x = i; y = i; }, // 2D location function // Logic.compare, // axis comparison function // (Quadtree.Average<double>)Statistics.Mean<double>); // axis average function //// Adding //for (int i = 0; i < test; i++) // quadtree_linked.Add(i); //// Proper Traversal //Console.Write(" Traversal: "); //quadtree_linked.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //// Saving to a file //string quadtreelinked_file = "quadtree_linked." + ToExtension(quadtree_linked.GetType()); //Console.WriteLine(" File: \"" + quadtreelinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(quadtreelinked_file, quadtree_linked)); //Quadtree_Linked<int, double> deserialized_quadtreelinked; //Console.WriteLine(" Deserialized: " + Deserialize(quadtreelinked_file, out deserialized_quadtreelinked)); //Console.WriteLine(); #endregion #region Oct-Tree //Console.WriteLine(" Testing Octree_Linked<int, double>---------"); //// Construction //Octree<int, double> octree_linked = new Octree_Linked<int, double>( // -test - 1, -test - 1, -test - 1, // minimum dimensions of the octree // test + 1, test + 1, test + 1, // maximum dimensions of the octree // (int i, out double x, out double y, out double z) => { x = i; y = i; z = i; }, // 3D location function // Logic.compare, // axis comparison function // Statistics.Mean); // axis average function //// Addition //for (int i = 0; i < test; i++) // octree_linked.Add(i); //// Proper Traversal //Console.Write(" Traversal: "); //octree_linked.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //// Saving to a file //string octree_file = "octree_linked." + ToExtension(octree_linked.GetType()); //Console.WriteLine(" File: \"" + octree_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(octree_file, octree_linked)); //Octree_Linked<int, double> deserialized_octree; //Console.WriteLine(" Deserialized: " + Deserialize(octree_file, out deserialized_octree)); //Console.WriteLine(); #endregion #region Omnitree Console.WriteLine(" Testing OmnitreeLinkedLinked<int, double>-------"); // Construction Omnitree <int, double> omnitree_linked = new OmnitreeLinked <int, double>( new double[] { -test - 1, -test - 1, -test - 1 }, // minimum dimensions of the omnitree new double[] { test + 1, test + 1, test + 1 }, // maximum dimensions of the omnitree (int index) => { return(Accessor.Get(new double[] { index, index, index })); }, // "N-D" location function Compute <double> .Compare, // axis comparison function (double a, double b) => { return((a + b) / 2); }); // axis average function // Properties Console.WriteLine(" Origin: [" + omnitree_linked.Origin(0) + ", " + omnitree_linked.Origin(1) + ", " + omnitree_linked.Origin(2) + "]"); Console.WriteLine(" Minimum: [" + omnitree_linked.Min(0) + ", " + omnitree_linked.Min(1) + ", " + omnitree_linked.Min(2) + "]"); Console.WriteLine(" Maximum: [" + omnitree_linked.Max(0) + ", " + omnitree_linked.Max(1) + ", " + omnitree_linked.Max(2) + "]"); Console.WriteLine(" Dimensions: " + omnitree_linked.Dimensions); Console.WriteLine(" Count: " + omnitree_linked.Count); // Addition Console.Write(" Adding 0-" + test + ": "); for (int i = 0; i < test; i++) { omnitree_linked.Add(i); } omnitree_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); Console.WriteLine(" Count: " + omnitree_linked.Count); // Traversal Console.Write(" Traversal [ALL]: "); omnitree_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); // Look Up 1 Console.Write(" Traversal [(" + (test / 2) + ", " + (test / 2) + ", " + (test / 2) + ")->(" + test + ", " + test + ", " + test + ")]: "); omnitree_linked.Stepper((int current) => { Console.Write(current); }, new double[] { test / 2, test / 2, test / 2 }, new double[] { test, test, test }); Console.WriteLine(); // Look Up 2 Console.Write(" Look Up [" + (test / 3) + ", " + (test / 3) + ", " + (test / 3) + "]: "); omnitree_linked[(test / 3), (test / 3), (test / 3)]((int current) => { Console.Write(current); }); Console.WriteLine(); // Removal Console.Write(" Remove 0-" + test / 3 + ": "); omnitree_linked.Remove( new double[] { 0, 0, 0 }, new double[] { test / 3, test / 3, test / 3 }); omnitree_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); Console.WriteLine(" Count: " + omnitree_linked.Count); // Clear Console.Write(" Clear: "); omnitree_linked.Clear(); omnitree_linked.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); Console.WriteLine(" Count: " + omnitree_linked.Count); // Saving to a file //string omnitreelinked_file = "omnitree_linkedlinkedlists." + ToExtension(omnitree_linked.GetType()); //Console.WriteLine(" File: \"" + omnitreelinked_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(omnitreelinked_file, omnitree_linked)); //OmnitreeLinkedLinkedLists<int, double> deserialized_omnitreeLinked; //Console.WriteLine(" Deserialized: " + Deserialize(omnitreelinked_file, out deserialized_omnitreeLinked)); Console.WriteLine(); //Console.WriteLine(" Testing Omnitree_LinkedArrayLists<int, double>--------"); //// Construction //Omnitree<int, double> omnitree_array = new OmnitreeLinkedArray<int, double>( // new double[] { -test - 1, -test - 1, -test - 1 }, // minimum dimensions of the omnitree // new double[] { test + 1, test + 1, test + 1 }, // maximum dimensions of the omnitree // (int index) => { return Accessor.Get(new double[] { index, index, index }); }, // "N-D" location function // Compute<double>.Compare, // comparison function // (double a, double b) => { return (a + b) / 2; }); // average function //// Properties //Console.WriteLine(" Origin: [" + omnitree_array.Origin(0) + ", " + omnitree_array.Origin(1) + ", " + omnitree_array.Origin(2) + "]"); //Console.WriteLine(" Minimum: [" + omnitree_array.Min(0) + ", " + omnitree_array.Min(1) + ", " + omnitree_array.Min(2) + "]"); //Console.WriteLine(" Maximum: [" + omnitree_array.Max(0) + ", " + omnitree_array.Max(1) + ", " + omnitree_array.Max(2) + "]"); //Console.WriteLine(" Dimensions: " + omnitree_array.Dimensions); //Console.WriteLine(" Count: " + omnitree_array.Count); //// Addition //Console.Write(" Adding 0-" + test + ": "); //for (int i = 0; i < test; i++) // omnitree_array.Add(i); //omnitree_array.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //Console.WriteLine(" Count: " + omnitree_array.Count); //// Traversal //Console.Write(" Traversal [ALL]: "); // omnitree_array.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //// Look Up //Console.Write(" Traversal [" + (test / 2) + "-" + test + "]: "); // omnitree_array.Stepper((int current) => { Console.Write(current); }, // new double[] { test / 2, test / 2, test / 2 }, // new double[] { test, test, test }); //Console.WriteLine(); //// Removal //Console.Write(" Remove 0-" + test / 3 + ": "); //omnitree_array.Remove( // new double[] { 0, 0, 0 }, // new double[] { test / 3, test / 3, test / 3 }); //omnitree_array.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //Console.WriteLine(" Count: " + omnitree_array.Count); //// Clear //Console.Write(" Clear: "); //omnitree_array.Clear(); // omnitree_array.Stepper((int current) => { Console.Write(current); }); //Console.WriteLine(); //Console.WriteLine(" Count: " + omnitree_array.Count); //// Saving to a file ////string omnitreearray_file = "omnitree_linkedarraylists." + ToExtension(omnitree_array.GetType()); ////Console.WriteLine(" File: \"" + omnitreearray_file + "\""); ////Console.WriteLine(" Serialized: " + Serialize(omnitreearray_file, omnitree_array)); ////OmnitreeLinkedLinkedLists<int, double> deserialized_omnitreearray; ////Console.WriteLine(" Deserialized: " + Deserialize(omnitreearray_file, out deserialized_omnitreearray)); //Console.WriteLine(); #endregion #region KD Tree ////List<KdTreeNode<float, string>> testNodes = new List_Linked<KdTreeNode<float, string>>(); //KdTree_Linked<string, float> tree = new KdTree_Linked<string, float>( // 2, // Logic.compare, // float.MinValue, // float.MaxValue, // 0, // Arithmetic.Add, // Arithmetic.Subtract, // Arithmetic.Multiply); //List<KdTree_Linked<string, float>.Node> testNodes = // new List_Linked<KdTree_Linked<string, float>.Node> //{ // new KdTree_Linked<string, float>.Node(new float[] { 5, 5 }, "Root"), // new KdTree_Linked<string, float>.Node(new float[] { 2.5f, 2.5f }, "Root-Left"), // new KdTree_Linked<string, float>.Node(new float[] { 7.5f, 7.5f }, "Root-Right"), // new KdTree_Linked<string, float>.Node(new float[] { 1, 10 }, "Root-Left-Left"), // new KdTree_Linked<string, float>.Node(new float[] { 10, 10 }, "Root-Right-Right") //}; //foreach (var node in testNodes) // if (!tree.Add(node.Point, node.Value)) // throw new Exception("Failed to add node to tree"); //var nodesToRemove = new KdTreeNode<float, string>[] { // testNodes[1], // Root-Left // testNodes[0] // Root //}; //foreach (var nodeToRemove in nodesToRemove) //{ // tree.RemoveAt(nodeToRemove.Point); // testNodes.Remove(nodeToRemove); // Assert.IsNull(tree.FindValue(nodeToRemove.Value)); // Assert.IsNull(tree.FindValueAt(nodeToRemove.Point)); // foreach (var testNode in testNodes) // { // Assert.AreEqual(testNode.Value, tree.FindValueAt(testNode.Point)); // Assert.AreEqual(testNode.Point, tree.FindValue(testNode.Value)); // } // Assert.AreEqual(testNodes.Count, tree.Count); //} #endregion #region Graph Console.WriteLine(" Testing Graph_SetOmnitree<int>-------------"); Graph <int> graph = new GraphSetOmnitree <int>(Compute <int> .Equate, Compute <int> .Compare, Hash.Default, 0, test, (int a, int b) => { return((a + b) / 2); }); // add nodes for (int i = 0; i < test; i++) { graph.Add(i); } // add edges for (int i = 0; i < test - 1; i++) { graph.Add(i, i + 1); } Console.Write(" Traversal: "); graph.Stepper((int current) => { Console.Write(current); }); Console.WriteLine(); Console.WriteLine(" Edges: "); //((Graph_SetQuadtree<int>)graph)._edges.Foreach((Graph_SetQuadtree<int>.Edge e) => { Console.WriteLine(" " + e.Start + " " + e.End); }); graph.Stepper( (int current) => { Console.Write(" " + current + ": "); graph.Neighbors(current, (int a) => { Console.Write(a); }); Console.WriteLine(); }); // Saving to a file //string graph_file = "graph." + ToExtension(graph.GetType()); //Console.WriteLine(" File: \"" + graph_file + "\""); //Console.WriteLine(" Serialized: " + Serialize(graph_file, graph)); //GraphSetOmnitree<int> deserialized_graph; //Console.WriteLine(" Deserialized: " + Deserialize(graph_file, out deserialized_graph)); Console.WriteLine(); #endregion Console.WriteLine("============================================"); Console.WriteLine("Examples Complete..."); Console.ReadLine(); }
static void Main(string[] args) { #region Delegate //Action test1 = () => { Console.WriteLine("test 1"); }; //Action test2 = () => { Console.WriteLine("test 2"); }; //Action action = test1; ////foreach (byte b in test1.Method.GetMethodBody().GetILAsByteArray()) //// Console.WriteLine(b); //// ////foreach (System.Reflection.FieldInfo field in typeof(Action).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public)) //// Console.WriteLine(field); //action(); ////Console.WriteLine(typeof(Action).GetField("_target", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(action)); //IntPtr methodPtr = (IntPtr)typeof(Action).GetField("_methodPtr", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2); //IntPtr methodPtrAux = (IntPtr)typeof(Action).GetField("_methodPtrAux", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2); //object target = typeof(Action).GetField("_target", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2); //object methodBase = typeof(Action).GetField("_methodBase", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2); ////typeof(Action).GetField("_methodPtr", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(action, methodPtr); ////typeof(Action).GetField("_methodPtrAux", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(action, methodPtrAux); ////typeof(Action).GetField("_target", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(action, target); ////typeof(Action).GetField("_methodBase", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(action, methodBase); //byte[] array = test1.Method.GetMethodBody().GetILAsByteArray(); //System.Runtime.InteropServices.GCHandle pinnedArray = System.Runtime.InteropServices.GCHandle.Alloc(array, System.Runtime.InteropServices.GCHandleType.Pinned); //IntPtr pointer = pinnedArray.AddrOfPinnedObject(); //typeof(Action).GetField("_methodPtrAux", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(action, pointer); //pinnedArray.Free(); //action(); ////Console.WriteLine(typeof(Action).GetField("_target", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(action)); //System.Action<System.String, System.Int32, System.Double> //System.Action`3[System.String, System.Int32, System.Double] //int i = 0; //foreach (string s in "Action<int, double, decimal>".Split('<', '>')) // Console.WriteLine(i++ + " "+ s); //Console.WriteLine(string.IsNullOrWhiteSpace("Action<int, double, decimal>".Split('<', '>')["Action<int, double, decimal>".Split('<', '>').Length - 1])); //Console.WriteLine(Type.GetType("System.Action`3[System.String, System.Int32, System.Double]")); //Console.WriteLine(Type.GetType("Action<int>")); //Console.WriteLine(typeof(Action<int>).Name); //Console.WriteLine(typeof(Action<float>).Name); //Console.WriteLine(typeof(Action<double>).Name); //Console.WriteLine(typeof(Action<decimal>).Name); //Console.WriteLine(typeof(System.Collections.Generic.List<int>).Name); //Console.WriteLine(typeof(System.Collections.Generic.List<float>).Name); //Console.WriteLine(typeof(System.Collections.Generic.List<double>).Name); //Console.WriteLine(typeof(System.Collections.Generic.List<decimal>).Name); //Console.WriteLine(Type.GetType("List'1")); //Action test2 = Test; //Console.WriteLine(typeof(Action).GetField("_methodPtr", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2)); //Console.WriteLine(typeof(Action).GetField("_methodPtrAux", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2)); //Console.WriteLine(typeof(Action).GetField("_target", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2)); //Console.WriteLine(typeof(Action).GetField("_methodBase", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(test2)); //Console.WriteLine(test2.Truncate().Target); //Console.WriteLine(test2.Truncate().Method.DeclaringType.Name); //Action d = (Action)Delegate.CreateDelegate(typeof(Action), test2.Method); //114 //1 //0 //0 //112 //40 //22 //0 //0 //10 //42 //System.Object _target //System.Object _methodBase //IntPtr _methodPtr //IntPtr _methodPtrAux #endregion #region Random Generators //int iterationsperrandom = 3; //Action<Random> testrandom = (Random random) => // { // for (int i = 0; i < iterationsperrandom; i++) // Console.WriteLine(i + ": " + random.Next()); // Console.WriteLine(); // }; //Arbitrary mcg_2pow59_13pow13 = Arbitrary.MultiplicativeCongruentGenerator_Modulus2power59_Multiplier13power13(); //Console.WriteLine("mcg_2pow59_13pow13 randoms:"); //testrandom(mcg_2pow59_13pow13); //Arbitrary mcg_2pow31m1_1132489760 = Arbitrary.MultiplicativeCongruentGenerator_Modulus2power31minus1_Multiplier1132489760(); //Console.WriteLine("mcg_2pow31m1_1132489760 randoms:"); //testrandom(mcg_2pow31m1_1132489760); //Arbitrary mersenneTwister = Arbitrary.MersenneTwister(); //Console.WriteLine("mersenneTwister randoms:"); //testrandom(mersenneTwister); //Arbitrary cmr32_c2_o3 = Arbitrary.CombinedMultipleRecursiveGenerator32bit_components2_order3(); //Console.WriteLine("mersenneTwister randoms:"); //testrandom(cmr32_c2_o3); //Arbitrary wh1982cmcg = Arbitrary.WichmannHills1982_CombinedMultiplicativeCongruentialGenerator(); //Console.WriteLine("mersenneTwister randoms:"); //testrandom(wh1982cmcg); //Arbitrary wh2006cmcg = Arbitrary.WichmannHills2006_CombinedMultiplicativeCongruentialGenerator(); //Console.WriteLine("mersenneTwister randoms:"); //testrandom(wh2006cmcg); //Arbitrary mwcxorsg = Arbitrary.MultiplyWithCarryXorshiftGenerator(); //Console.WriteLine("mwcxorsg randoms:"); //testrandom(mwcxorsg); #endregion #region Set Tests //{ // int iterations = int.MaxValue / 1000; // HashSet<int> validation = new HashSet<int>(); // //for (int i = 0; i < interations; i++) // // validation.Add(i); // { // HashSet<int> set0 = new HashSet<int>(); // SetHashList<int> set1 = new SetHashList<int>(); // SetHashArray<int> set2 = new SetHashArray<int>(); // for (int i = 0; i < iterations; i++) set0.Add(i); // for (int i = 0; i < iterations; i++) set1.Add(i); // for (int i = 0; i < iterations; i++) set2.Add(i); // for (int i = 0; i < iterations; i++) // validation.Add(i); // foreach (int i in set0) { validation.Remove(i); } // for (int i = 0; i < iterations; i++) // validation.Add(i); // set1.Stepper((int i) => { validation.Remove(i); }); // for (int i = 0; i < iterations; i++) // validation.Add(i); // set2.Stepper((int i) => { validation.Remove(i); }); // for (int i = 0; i < iterations; i++) set0.Contains(i); // for (int i = 0; i < iterations; i++) set1.Contains(i); // for (int i = 0; i < iterations; i++) set2.Contains(i); // for (int i = 0; i < iterations; i++) set0.Remove(i); // for (int i = 0; i < iterations; i++) set1.Remove(i); // for (int i = 0; i < iterations; i++) set2.Remove(i); // Console.WriteLine("Adding HashSet: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = 0; i < iterations; i++) set0.Add(i); })); // Console.WriteLine("Adding Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = 0; i < iterations; i++) set1.Add(i); })); // Console.WriteLine("Adding SetHash: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = 0; i < iterations; i++) set2.Add(i); })); // for (int i = 0; i < iterations; i++) // validation.Add(i); // foreach (int i in set0) { validation.Remove(i); } // Console.WriteLine("Validate HashSet: " + (validation.Count == 0)); // for (int i = 0; i < iterations; i++) // validation.Add(i); // set1.Stepper((int i) => { validation.Remove(i); }); // Console.WriteLine("Validate Set_HashLinkedList: " + (validation.Count == 0)); // for (int i = 0; i < iterations; i++) // validation.Add(i); // set2.Stepper((int i) => { validation.Remove(i); }); // Console.WriteLine("Validate SetHas: " + (validation.Count == 0)); // Console.WriteLine("Size HashSet: " + (typeof(HashSet<int>).GetField("m_buckets", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(set0) as int[]).Length); // Console.WriteLine("Size Set_HashLinkedList: " + set1.TableSize); // Console.WriteLine("Size SetHash: " + set2.TableSize); // Console.WriteLine("Constains HashSet: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = 0; i < iterations; i++) set0.Contains(i); })); // Console.WriteLine("Constains Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = 0; i < iterations; i++) set1.Contains(i); })); // Console.WriteLine("Constains SetHash: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = 0; i < iterations; i++) set2.Contains(i); })); // //Console.WriteLine("Removed HashSet: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) set0.Remove(i); })); // //Console.WriteLine("Removed Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) set1.Remove(i); })); // //Console.WriteLine("Remove SetHash: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) set2.Remove(i); })); // Console.WriteLine("Removed HashSet: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = iterations - 1; i >= 0; i--) set0.Remove(i); })); // Console.WriteLine("Removed Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = iterations - 1; i >= 0; i--) set1.Remove(i); })); // Console.WriteLine("Remove SetHash: " + Seven.Diagnostics.Performance.Time_DateTimNow(() => { for (int i = iterations - 1; i >= 0; i--) set2.Remove(i); })); // Console.WriteLine("Size HashSet: " + (typeof(HashSet<int>).GetField("m_buckets", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(set0) as int[]).Length); // Console.WriteLine("Size Set_HashLinkedList: " + set1.TableSize); // Console.WriteLine("Size SetHash: " + set2.TableSize); // } // Console.WriteLine(); // { // HashSet<int> set0 = new HashSet<int>(); // SetHashList<int> set1 = new SetHashList<int>(); // SetHashArray<int> set2 = new SetHashArray<int>(); // for (int i = 0; i < iterations; i++) set0.Add(i); // for (int i = 0; i < iterations; i++) set1.Add(i); // for (int i = 0; i < iterations; i++) set2.Add(i); // for (int i = 0; i < iterations; i++) // validation.Add(i); // foreach (int i in set0) { validation.Remove(i); } // for (int i = 0; i < iterations; i++) // validation.Add(i); // set1.Stepper((int i) => { validation.Remove(i); }); // for (int i = 0; i < iterations; i++) // validation.Add(i); // set2.Stepper((int i) => { validation.Remove(i); }); // for (int i = 0; i < iterations; i++) set0.Contains(i); // for (int i = 0; i < iterations; i++) set1.Contains(i); // for (int i = 0; i < iterations; i++) set2.Contains(i); // for (int i = 0; i < iterations; i++) set0.Remove(i); // for (int i = 0; i < iterations; i++) set1.Remove(i); // for (int i = 0; i < iterations; i++) set2.Remove(i); // Console.WriteLine("Adding HashSet: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < iterations; i++) set0.Add(i); })); // Console.WriteLine("Adding Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < iterations; i++) set1.Add(i); })); // Console.WriteLine("Adding SetHash: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < iterations; i++) set2.Add(i); })); // for (int i = 0; i < iterations; i++) // validation.Add(i); // foreach (int i in set0) { validation.Remove(i); } // Console.WriteLine("Validate HashSet: " + (validation.Count == 0)); // for (int i = 0; i < iterations; i++) // validation.Add(i); // set1.Stepper((int i) => { validation.Remove(i); }); // Console.WriteLine("Validate Set_HashLinkedList: " + (validation.Count == 0)); // for (int i = 0; i < iterations; i++) // validation.Add(i); // set2.Stepper((int i) => { validation.Remove(i); }); // Console.WriteLine("Validate SetHas: " + (validation.Count == 0)); // Console.WriteLine("Size HashSet: " + (typeof(HashSet<int>).GetField("m_buckets", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(set0) as int[]).Length); // Console.WriteLine("Size Set_HashLinkedList: " + set1.TableSize); // Console.WriteLine("Size SetHash: " + set2.TableSize); // Console.WriteLine("Constains HashSet: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < iterations; i++) set0.Contains(i); })); // Console.WriteLine("Constains Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < iterations; i++) set1.Contains(i); })); // Console.WriteLine("Constains SetHash: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < iterations; i++) set2.Contains(i); })); // //Console.WriteLine("Removed HashSet: " + Seven.Diagnostics.Performance.Time2(() => { for (int i = 0; i < iterations; i++) set0.Remove(i); })); // //Console.WriteLine("Removed Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time2(() => { for (int i = 0; i < iterations; i++) set1.Remove(i); })); // //Console.WriteLine("Remove SetHash: " + Seven.Diagnostics.Performance.Time2(() => { for (int i = 0; i < iterations; i++) set2.Remove(i); })); // Console.WriteLine("Removed HashSet: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = iterations - 1; i >= 0; i--) set0.Remove(i); })); // Console.WriteLine("Removed Set_HashLinkedList: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = iterations - 1; i >= 0; i--) set1.Remove(i); })); // Console.WriteLine("Remove SetHash: " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = iterations - 1; i >= 0; i--) set2.Remove(i); })); // Console.WriteLine("Size HashSet: " + (typeof(HashSet<int>).GetField("m_buckets", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(set0) as int[]).Length); // Console.WriteLine("Size Set_HashLinkedList: " + set1.TableSize); // Console.WriteLine("Size SetHash: " + set2.TableSize); // } // Console.WriteLine(); //} #endregion #region Map/Dictionary //{ // int iterations = int.MaxValue / 10000; // HashSet<int> validation = new HashSet<int>(); // //for (int i = 0; i < interations; i++) // // validation.Add(i); // { // Dictionary<int, int> map0 = new Dictionary<int, int>(); // //MapSetHashList<int, int> map1 = new MapSetHashList<int, int>(); // MapHashLinked<int, int> map2 = new MapHashLinked<int, int>(); // MapHashArray<int, int> map3 = new MapHashArray<int, int>(); // Console.WriteLine("Adding 0: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map0.Add(i, i); })); // //Console.WriteLine("Adding 1: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map1.Add(i, i); })); // Console.WriteLine("Adding 2: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map2.Add(i, i); })); // Console.WriteLine("Adding 3: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map3.Add(i, i); })); // for (int i = 0; i < iterations; i++) // validation.Add(i); // foreach (KeyValuePair<int, int> i in map0) { validation.Remove(i.Key); } // Console.WriteLine("Validate 0: " + (validation.Count == 0)); // //for (int i = 0; i < iterations; i++) // // validation.Add(i); // ////foreach (int i in map1) { validation.Remove(i); } // //map1.Stepper((int i) => { validation.Remove(i); }); // //Console.WriteLine("Validate 1: " + (validation.Count == 0)); // for (int i = 0; i < iterations; i++) // validation.Add(i); // //foreach (int i in map1) { validation.Remove(i); } // map2.Stepper((int i) => { validation.Remove(i); }); // Console.WriteLine("Validate 2: " + (validation.Count == 0)); // for (int i = 0; i < iterations; i++) // validation.Add(i); // //foreach (int i in map1) { validation.Remove(i); } // map3.Stepper((int i) => { validation.Remove(i); }); // Console.WriteLine("Validate 3: " + (validation.Count == 0)); // int temp; // Console.WriteLine("Get 0: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) temp = map0[i]; })); // //Console.WriteLine("Get 1: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) temp = map1[i]; })); // Console.WriteLine("Get 2: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) temp = map2[i]; })); // Console.WriteLine("Get 3: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) temp = map3[i]; })); // Console.WriteLine("Removed 0: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map0.Remove(i); })); // //Console.WriteLine("Removed 1: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map1.Remove(i); })); // Console.WriteLine("Removed 2: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map2.Remove(i); })); // Console.WriteLine("Removed 3: " + Seven.Diagnostics.Performance.Time(() => { for (int i = 0; i < iterations; i++) map3.Remove(i); })); // } //} #endregion #region Vector Test //Console.WriteLine(); //Console.WriteLine("Vector Testing-------------------------------------"); //Random random = new Random(); //const int vector_size = 4; //const int vector_iterations = int.MaxValue / 100; //Vector<double> vector_a = new Vector<double>(vector_size); //Vector<double> vector_b = new Vector<double>(vector_size); //Vector<double> vector_c; //for (int i = 0; i < vector_size; i++) //{ // vector_a[i] = random.Next(); // vector_b[i] = random.Next(); //} //Console.WriteLine("Compile 1: " + Seven.Diagnostics.Performance.Time(() => { vector_c = Vector<double>.Vector_Add(vector_a, vector_b); })); //Console.WriteLine("Compile 2: " + Seven.Diagnostics.Performance.Time(() => { vector_c = Vector<double>.Vector_Add2(vector_a, vector_b); })); //Console.WriteLine("Compile 3: " + Seven.Diagnostics.Performance.Time(() => { vector_c = Vector<double>.Vector_Add3(vector_a, vector_b); })); //Console.WriteLine("Compile 4: " + Seven.Diagnostics.Performance.Time(() => { vector_c = Vector<double>.Vector_Add4(vector_a, vector_b); })); //Console.WriteLine("Test 1: " + Seven.Diagnostics.Performance.Time(() => { // for (int i = 0; i < vector_iterations; i++) // vector_c = Vector<double>.Vector_Add(vector_a, vector_b); //})); //Console.WriteLine("Test 2: " + Seven.Diagnostics.Performance.Time(() => //{ // for (int i = 0; i < vector_iterations; i++) // vector_c = Vector<double>.Vector_Add2(vector_a, vector_b); //})); //Console.WriteLine("Test 3: " + Seven.Diagnostics.Performance.Time(() => //{ // for (int i = 0; i < vector_iterations; i++) // vector_c = Vector<double>.Vector_Add3(vector_a, vector_b); //})); //Console.WriteLine("Test 4: " + Seven.Diagnostics.Performance.Time(() => //{ // for (int i = 0; i < vector_iterations; i++) // vector_c = Vector<double>.Vector_Add4(vector_a, vector_b); //})); #endregion #region Sorting Speed //{ // int size = int.MaxValue / 1000000; // int[] dataSet = new int[size]; // for (int i = 0; i < size; i++) // dataSet[i] = i; // Console.WriteLine("Sorting Algorithms----------------------"); // Console.WriteLine(); // //Sort<int>.Shuffle(dataSet); // //Console.Write("Bubble: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.Bubble(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("Selection: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.Selection(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("Insertion: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.Insertion(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("Quick: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.Quick(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("Merge: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.Merge(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("Heap: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.Heap(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("OddEven: " + Seven.Diagnostics.Performance.Time(() => { Sort<int>.OddEven(dataSet); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("IEnumerable: " + Seven.Diagnostics.Performance.Time(() => { dataSet.OrderBy(item => item); })); // Sort<int>.Shuffle(dataSet); // Console.WriteLine("Array.Sort: " + Seven.Diagnostics.Performance.Time(() => { Array.Sort(dataSet); })); //} #endregion #region Matrix Test //Random random = new Random(); //const int matrix_rows = 4; //const int matrix_columns = 4; //const int matrix_iterations = int.MaxValue / 100; //{ // Seven.Mathematics.Matrix<double> matrix_a = new Seven.Mathematics.Matrix<double>(matrix_rows, matrix_columns); // Seven.Mathematics.Matrix<double> matrix_b = new Seven.Mathematics.Matrix<double>(matrix_rows, matrix_columns); // Seven.Mathematics.Matrix<double> matrix_c; // matrix_c = matrix_a + matrix_b; // matrix_c = matrix_b + matrix_a; // //matrix_a = matrix_b + matrix_c; // //matrix_a = matrix_c + matrix_b; // for (int i = 0; i < matrix_rows; i++) // for (int j = 0; j < matrix_columns; j++) // { // matrix_a[i, j] = random.Next(); // matrix_b[i, j] = random.Next(); // } // Console.WriteLine("Test 1: " + Seven.Diagnostics.Performance.Time(() => // { // for (int i = 0; i < matrix_iterations; i++) // matrix_c = matrix_a + matrix_b; // })); //matrix_c = Matrix<double>.Matrix_Negate2(matrix_a); //Console.WriteLine("Test 2: " + Seven.Diagnostics.Performance.Time(() => //{ // for (int i = 0; i < matrix_iterations; i++) // matrix_c = Matrix<double>.Matrix_Negate2(matrix_a); //})); //Console.WriteLine("Test 2: " + Seven.Diagnostics.Performance.Time(() => //{ // for (int i = 0; i < matrix_iterations; i++) // Matrix<double>.Matrix_IsSymetric2(matrix_a); //})); //Console.WriteLine("Compile 1: " + Seven.Diagnostics.Performance.Time(() => { matrix_c = matrix_a + matrix_b; })); //Console.WriteLine("Test 1: " + Seven.Diagnostics.Performance.Time(() => //{ // for (int i = 0; i < matrix_iterations; i++) // matrix_c = matrix_a + matrix_b; //})); //} #endregion #region Omnitree Omnitree.Locate <TestObject, double> locate = (TestObject record) => { return((int i) => { switch (i) { case 0: return record.X; case 1: return record.Y; case 2: return record.Z; default: throw new System.Exception(); } }); }; Compute <double> .Compare(0, 0); Omnitree <TestObject, double> omnitree = new OmnitreeLinked <TestObject, double>( 3, Accessor.Get(new double[] { 0, 0, 0 }), Accessor.Get(new double[] { 1, 1, 1 }), locate, (double a, double b) => { return(a == b); }, Equate.Default, Compute <double> .Compare, (double a, double b) => { return((a + b) / 2); }); System.Collections.Generic.List <TestObject> list = new System.Collections.Generic.List <TestObject>(); System.Collections.Generic.LinkedList <TestObject> linkedlist = new System.Collections.Generic.LinkedList <TestObject>(); Random random = new Random(7); int count = 10000; TestObject[] records = new TestObject[count]; for (int i = 0; i < count; i++) { records[i] = new TestObject(i, random.NextDouble(), random.NextDouble(), random.NextDouble()); } Console.WriteLine("Testing with " + count + " records..."); Console.WriteLine(); Console.WriteLine("Adding (Omnitree): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < count; i++) { omnitree.Add(records[i]); } })); Console.WriteLine("Adding (List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < count; i++) { list.Add(records[i]); } })); Console.WriteLine("Adding (L-List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < count; i++) { linkedlist.AddLast(records[i]); } })); Console.WriteLine(); Sort <TestObject> .Shuffle(random, Accessor.Get(records), Accessor.Assign(records), 0, records.Length); Console.WriteLine("Querying Single (Omnitree): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { bool query_test; for (int i = 0; i < count; i++) { query_test = false; omnitree[locate(records[i])]((TestObject record) => { query_test = true; }); //omnitree[records[i].X, records[i].Y, records[i].Z]((TestObject record) => { query_test = true; }); if (query_test == false) { throw new System.Exception(); } } })); Console.WriteLine("Querying Single (List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { bool query_test = false; for (int i = 0; i < count; i++) { foreach (TestObject record in list) { if (record.X == records[i].X && record.Y == records[i].Y && record.Z == records[i].Z) { query_test = true; break; } } if (query_test == false) { throw new System.Exception(); } } })); Console.WriteLine("Querying Single (L-List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { bool query_test = false; for (int i = 0; i < count; i++) { foreach (TestObject record in linkedlist) { if (record.X == records[i].X && record.Y == records[i].Y && record.Z == records[i].Z) { query_test = true; break; } } if (query_test == false) { throw new System.Exception(); } } })); Console.WriteLine(); int random_query_count = count / 100; double[][] random_mins = new double[random_query_count][]; for (int i = 0; i < random_query_count; i++) { random_mins[i] = new double[] { random.NextDouble(), random.NextDouble(), random.NextDouble(), } } ; double[][] random_maxes = new double[random_query_count][]; for (int i = 0; i < random_query_count; i++) { random_maxes[i] = new double[] { random.NextDouble() *((1 - random_mins[i][0]) + random_mins[i][0]), random.NextDouble() * ((1 - random_mins[i][1]) + random_mins[i][1]), random.NextDouble() * ((1 - random_mins[i][2]) + random_mins[i][2]) } } ; Console.WriteLine(random_query_count + " random range queries..."); int[] query_count_omnitree = new int[random_query_count]; int[] query_count_list = new int[random_query_count]; int[] query_count_linkedlist = new int[random_query_count]; Console.WriteLine("Querying Range (Omnitree): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < random_query_count; i++) { omnitree.Stepper((TestObject record) => { query_count_omnitree[i]++; }, random_mins[i], random_maxes[i]); } })); Console.WriteLine("Querying Range (List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < random_query_count; i++) { foreach (TestObject record in list) { if (record.X >= random_mins[i][0] && record.X <= random_maxes[i][0] && record.Y >= random_mins[i][1] && record.Y <= random_maxes[i][1] && record.Z >= random_mins[i][2] && record.Z <= random_maxes[i][2]) { query_count_list[i]++; } } } })); Console.WriteLine("Querying Range (L-List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < random_query_count; i++) { foreach (TestObject record in linkedlist) { if (record.X >= random_mins[i][0] && record.X <= random_maxes[i][0] && record.Y >= random_mins[i][1] && record.Y <= random_maxes[i][1] && record.Z >= random_mins[i][2] && record.Z <= random_maxes[i][2]) { query_count_linkedlist[i]++; } } } })); for (int i = 0; i < random_query_count; i++) { if (query_count_omnitree[i] != query_count_list[i] || query_count_list[i] != query_count_linkedlist[i]) { throw new System.Exception(); } } Console.WriteLine(); foreach (TestObject record in records) { record.X += Math.Max(0d, Math.Min(1d, (random.NextDouble() / 100D) - .5D)); record.Y += Math.Max(0d, Math.Min(1d, (random.NextDouble() / 100D) - .5D)); record.Z += Math.Max(0d, Math.Min(1d, (random.NextDouble() / 100D) - .5D)); } Console.WriteLine("Updating (Omnitree): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { omnitree.Update(); })); Console.WriteLine(); Console.WriteLine("Removing Single (Omnitree): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < count; i++) { //// Removal Method #1 omnitree.Remove(records[i]); //// Removal Method #2 //omnitree.Remove(locate(records[i]), locate(records[i])); //// Removal Method #3 //omnitree.Remove(locate(records[i]), locate(records[i]), (TestObject step) => { return records[i].Id == step.Id; }); //// Removal Method #4 //double[] location = new double[] { locate(records[i])(0), locate(records[i])(1), locate(records[i])(2) }; //omnitree.Remove(location, location); //// Removal Method #5 //double[] location = new double[] { locate(records[i])(0), locate(records[i])(1), locate(records[i])(2) }; //omnitree.Remove(location, location, (omnitree_record step) => { return records[i].Id == step.Id; }); } })); Console.WriteLine("Removing Single (List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < count; i++) { //list.Remove(records[i]); for (int j = 0; j < list.Count; j++) { if (list[j].X == records[i].X && list[j].Y == records[i].Y && list[j].Z == records[i].Z) { list.RemoveAt(j); break; } } } })); Console.WriteLine("Removing Single (L-List): " + Seven.Diagnostics.Performance.Time_StopWatch(() => { for (int i = 0; i < count; i++) { //linkedlist.Remove(records[i]); LinkedList <TestObject> temp = new LinkedList <TestObject>(); foreach (TestObject record in linkedlist) { if (record.X == records[i].X && record.Y == records[i].Y && record.Z == records[i].Z) { temp.AddLast(record); break; } } foreach (TestObject record in temp) { linkedlist.Remove(record); } } })); for (int i = 0; i < count; i++) { omnitree.Add(records[i]); list.Add(records[i]); linkedlist.AddLast(records[i]); } Console.WriteLine(); TimeSpan omnitree_remove_span = TimeSpan.Zero; for (int i = 0; i < random_query_count; i++) { System.Collections.Generic.List <TestObject> temp = new System.Collections.Generic.List <TestObject>(); omnitree[locate(records[i])]((TestObject record) => { temp.Add(record); }); omnitree_remove_span += Seven.Diagnostics.Performance.Time_StopWatch(() => { omnitree.Remove(random_mins[i], random_maxes[i]); }); foreach (TestObject record in temp) { omnitree.Add(record); } } Console.WriteLine("Removing Range (Omnitree): " + omnitree_remove_span); TimeSpan list_remove_span = TimeSpan.Zero; for (int i = 0; i < random_query_count; i++) { System.Collections.Generic.List <TestObject> temp = new System.Collections.Generic.List <TestObject>(); foreach (TestObject record in list) { if (record.X >= random_mins[i][0] && record.X <= random_maxes[i][0] && record.Y >= random_mins[i][1] && record.Y <= random_maxes[i][1] && record.Z >= random_mins[i][2] && record.Z <= random_maxes[i][2]) { temp.Add(record); } } list_remove_span += Seven.Diagnostics.Performance.Time_StopWatch(() => { list.RemoveAll((TestObject record) => { return(record.X >= random_mins[i][0] && record.X <= random_maxes[i][0] && record.Y >= random_mins[i][1] && record.Y <= random_maxes[i][1] && record.Z >= random_mins[i][2] && record.Z <= random_maxes[i][2]); }); //for (int j = 0; j < list.Count; j++) //{ // if (list[j].X >= random_mins[i][0] && list[j].X <= random_maxes[i][0] && // list[j].Y >= random_mins[i][1] && list[j].Y <= random_maxes[i][1] && // list[j].Z >= random_mins[i][2] && list[j].Z <= random_maxes[i][2]) // { // list.RemoveAll.RemoveAt(i); // } //} }); foreach (TestObject record in temp) { list.Add(record); } } Console.WriteLine("Removing Range (List): " + list_remove_span); TimeSpan linkedlist_remove_span = TimeSpan.Zero; for (int i = 0; i < random_query_count; i++) { System.Collections.Generic.List <TestObject> temp = new System.Collections.Generic.List <TestObject>(); foreach (TestObject record in linkedlist) { if (record.X >= random_mins[i][0] && record.X <= random_maxes[i][0] && record.Y >= random_mins[i][1] && record.Y <= random_maxes[i][1] && record.Z >= random_mins[i][2] && record.Z <= random_maxes[i][2]) { temp.Add(record); } } linkedlist_remove_span += Seven.Diagnostics.Performance.Time_StopWatch(() => { System.Collections.Generic.List <TestObject> temp2 = new System.Collections.Generic.List <TestObject>(); foreach (TestObject record in linkedlist) { if (record.X >= random_mins[i][0] && record.X <= random_maxes[i][0] && record.Y >= random_mins[i][1] && record.Y <= random_maxes[i][1] && record.Z >= random_mins[i][2] && record.Z <= random_maxes[i][2]) { temp2.Add(record); } } foreach (TestObject record in temp2) { linkedlist.Remove(record); } }); foreach (TestObject record in temp) { list.Add(record); } } Console.WriteLine("Removing Range (L-List): " + linkedlist_remove_span); #endregion Console.WriteLine(); Console.WriteLine("Done..."); Console.ReadLine(); } } }