diff --git a/SystemExtensions/Collections/AVLTree.cs b/SystemExtensions/Collections/AVLTree.cs index 50fdf15..7c8f127 100644 --- a/SystemExtensions/Collections/AVLTree.cs +++ b/SystemExtensions/Collections/AVLTree.cs @@ -13,7 +13,7 @@ namespace SystemExtensions.Collections /// Read on https://simpledevcode.wordpress.com/2014/09/16/avl-tree-in-c/ /// /// Provided type. - public class AVLTree : ICollection + public class AVLTree : ICollection where T : IComparable { #region Fields private class AVLNode @@ -27,7 +27,6 @@ namespace SystemExtensions.Collections } } AVLNode root; - private Comparison comparator; private int count = 0; private bool isReadOnly = false; #endregion @@ -51,9 +50,9 @@ namespace SystemExtensions.Collections /// Initializes a new instance of an AVLTree collection. /// /// - public AVLTree(Comparison comparator) + public AVLTree() { - this.comparator = comparator; + } #endregion #region Public Methods @@ -86,7 +85,7 @@ namespace SystemExtensions.Collections { return false; } - if (comparator(node.Value, value) == 0) + if (node.Value.CompareTo(value) == 0) { return true; } @@ -181,12 +180,12 @@ namespace SystemExtensions.Collections current = n; return current; } - else if (comparator.Invoke(n.Value, current.Value) < 0) + else if (n.Value.CompareTo(current.Value) < 0) { current.Left = RecursiveInsertion(current.Left, n); current = BalanceTree(current); } - else if (comparator.Invoke(n.Value, current.Value) > 0) + else if (n.Value.CompareTo(current.Value) > 0) { current.Right = RecursiveInsertion(current.Right, n); current = BalanceTree(current); @@ -228,7 +227,7 @@ namespace SystemExtensions.Collections else { //left subtree - if (comparator.Invoke(target, current.Value) < 0) + if (target.CompareTo(current.Value) < 0) { current.Left = Delete(current.Left, target); if (BalanceFactor(current) == -2)//here @@ -244,7 +243,7 @@ namespace SystemExtensions.Collections } } //right subtree - else if (comparator.Invoke(target, current.Value) > 0) + else if (target.CompareTo(current.Value) > 0) { current.Right = Delete(current.Right, target); if (BalanceFactor(current) == 2) @@ -296,9 +295,9 @@ namespace SystemExtensions.Collections { return null; } - if (comparator.Invoke(target, current.Value) < 0) + if (target.CompareTo(current.Value) < 0) { - if (comparator.Invoke(target, current.Value) == 0) + if (target.CompareTo(current.Value) == 0) { return current; } @@ -307,7 +306,7 @@ namespace SystemExtensions.Collections } else { - if (comparator.Invoke(target, current.Value) == 0) + if (target.CompareTo(current.Value) == 0) { return current; } diff --git a/SystemExtensions/Collections/BinaryHeap.cs b/SystemExtensions/Collections/BinaryHeap.cs index d55b2cf..cc7cb2d 100644 --- a/SystemExtensions/Collections/BinaryHeap.cs +++ b/SystemExtensions/Collections/BinaryHeap.cs @@ -11,11 +11,10 @@ namespace SystemExtensions.Collections /// Binary heap implementation. /// /// Provided type. - public class BinaryHeap : IEnumerable + public class BinaryHeap : IEnumerable where T : IComparable { #region Fields T[] items; - Comparison comparator; int capacity, count, initialCapacity; #endregion #region Properties @@ -62,24 +61,22 @@ namespace SystemExtensions.Collections /// Constructor for a binary heap data structure. /// /// Function used to compare the elements. - public BinaryHeap(Comparison comparator) + public BinaryHeap() { capacity = 10; initialCapacity = capacity; items = new T[capacity]; - this.comparator = comparator; } /// /// Constructor for a binary heap data structure. /// /// Function used to compare the elements. /// Initial capacity of the heap. Used for initial alocation of the array. - public BinaryHeap(Comparison comparator, int capacity) + public BinaryHeap(int capacity) { this.capacity = capacity; initialCapacity = capacity; items = new T[capacity]; - this.comparator = comparator; } #endregion #region Public Methods @@ -94,7 +91,7 @@ namespace SystemExtensions.Collections Capacity = 2 * Capacity; } int position = ++count; - for (; position > 1 && comparator.Invoke(value, items[position / 2]) < 0; position = position / 2) + for (; position > 1 && value.CompareTo(items[position / 2]) < 0; position = position / 2) { items[position] = items[position / 2]; } @@ -175,11 +172,11 @@ namespace SystemExtensions.Collections for(; 2*index <= count; index = childIndex) { childIndex = 2 * index; - if(childIndex != Count && comparator.Invoke(items[childIndex], items[childIndex + 1]) > 0) + if(childIndex != Count && items[childIndex].CompareTo(items[childIndex + 1]) > 0) { childIndex++; } - if(comparator.Invoke(temp, items[childIndex]) > 0) + if(temp.CompareTo(items[childIndex]) > 0) { items[index] = items[childIndex]; } diff --git a/SystemExtensions/Collections/FibonacciHeap.cs b/SystemExtensions/Collections/FibonacciHeap.cs index 2f31933..75a606e 100644 --- a/SystemExtensions/Collections/FibonacciHeap.cs +++ b/SystemExtensions/Collections/FibonacciHeap.cs @@ -11,11 +11,10 @@ namespace SystemExtensions.Collections /// Fibonacci Heap implementation. /// /// Provided type - public class FibonacciHeap : IEnumerable + public class FibonacciHeap : IEnumerable where T : IComparable { #region Fields private FibonacciNode root; - private Comparison comparator; private int count; #endregion #region Properties @@ -45,9 +44,9 @@ namespace SystemExtensions.Collections /// Constructor for Fibonacci heap data structure. /// /// Function used to compare the elements. - public FibonacciHeap(Comparison comparator) + public FibonacciHeap() { - this.comparator = comparator; + } #endregion #region Public Methods @@ -238,7 +237,7 @@ namespace SystemExtensions.Collections { return node1; } - if(comparator(node1.Value, node2.Value) > 0) + if(node1.Value.CompareTo(node2.Value) > 0) { FibonacciNode temp = node1; node1 = node2; @@ -316,7 +315,7 @@ namespace SystemExtensions.Collections break; } trees[node.Degree] = null; - if(comparator(node.Value, t.Value) < 0) + if(node.Value.CompareTo(t.Value) < 0) { t.Previous.Next = t.Next; t.Next.Previous = t.Previous; @@ -354,7 +353,7 @@ namespace SystemExtensions.Collections FibonacciNode start = node; do { - if(comparator(node.Value, min.Value) < 0) + if(node.Value.CompareTo(min.Value) < 0) { min = node; } @@ -393,14 +392,14 @@ namespace SystemExtensions.Collections /// private FibonacciNode DecreaseKey(FibonacciNode root, FibonacciNode node, T value) { - if(comparator(node.Value, value) < 0) + if(node.Value.CompareTo(value) < 0) { return root; } node.Value = value; if(node.Parent != null) { - if(comparator(node.Value, node.Parent.Value) < 0) + if(node.Value.CompareTo(node.Parent.Value) < 0) { root = Cut(root, node); FibonacciNode parent = node.Parent; @@ -420,7 +419,7 @@ namespace SystemExtensions.Collections } else { - if(comparator(node.Value, root.Value) < 0) + if(node.Value.CompareTo(root.Value) < 0) { root = node; } @@ -442,7 +441,7 @@ namespace SystemExtensions.Collections } do { - if(comparator(node.Value, value) == 0) + if(node.Value.CompareTo(value) == 0) { return node; } diff --git a/SystemExtensions/Collections/PriorityQueue.cs b/SystemExtensions/Collections/PriorityQueue.cs index e1f12bf..76f507b 100644 --- a/SystemExtensions/Collections/PriorityQueue.cs +++ b/SystemExtensions/Collections/PriorityQueue.cs @@ -12,7 +12,7 @@ namespace SystemExtensions.Collections /// Exposes some of the functionality of the Binary Heap as a queue. /// /// Provided type. - public class PriorityQueue : IQueue + public class PriorityQueue : IQueue where T : IComparable { #region Fields private BinaryHeap binaryHeap; @@ -34,9 +34,9 @@ namespace SystemExtensions.Collections /// Constructor for priority queue data structure. /// /// Function used to compare the elements. - public PriorityQueue(Comparison comparator) + public PriorityQueue() { - binaryHeap = new BinaryHeap(comparator); + binaryHeap = new BinaryHeap(); } #endregion #region Public Methods diff --git a/SystemExtensions/Collections/Treap.cs b/SystemExtensions/Collections/Treap.cs index 8140eef..059c262 100644 --- a/SystemExtensions/Collections/Treap.cs +++ b/SystemExtensions/Collections/Treap.cs @@ -11,7 +11,7 @@ namespace SystemExtensions.Collections /// Treap implementation. /// /// Provided type. - public class Treap : ICollection + public class Treap : ICollection where T : IComparable { #region Fields private class Item @@ -29,7 +29,6 @@ namespace SystemExtensions.Collections } private Random randomGen; private Item root; - private Comparison comparator; private int count; #endregion #region Properties @@ -51,10 +50,9 @@ namespace SystemExtensions.Collections /// Constructor for treap. /// /// Comparator method used to compare values. - public Treap(Comparison comparator) + public Treap() { randomGen = new Random(); - this.comparator = comparator; } #endregion #region Public Methods @@ -138,7 +136,7 @@ namespace SystemExtensions.Collections node = new Item(key, randomGen.Next(0, 100)); return node; } - else if (comparator(key, node.Key) <= 0) + else if (key.CompareTo(node.Key) <= 0) { node.Left = InsertNode(node.Left, key); if(node.Left.Priority > node.Priority) @@ -162,11 +160,11 @@ namespace SystemExtensions.Collections { return node; } - if(comparator.Invoke(key, node.Key) < 0) + if(key.CompareTo(node.Key) < 0) { node.Left = RemoveNode(node.Left, key); } - else if(comparator.Invoke(key, node.Key) > 0) + else if(key.CompareTo(node.Key) > 0) { node.Right = RemoveNode(node.Right, key); } @@ -224,7 +222,7 @@ namespace SystemExtensions.Collections } else { - if(comparator.Invoke(node.Key, key) < 0) + if(node.Key.CompareTo(key) < 0) { Item found = Find(node.Left, key); if(found == null) @@ -233,7 +231,7 @@ namespace SystemExtensions.Collections } return found; } - else if(comparator.Invoke(node.Key, key) > 0) + else if(node.Key.CompareTo(key) > 0) { Item found = Find(node.Right, key); if (found == null) diff --git a/SystemExtensions/Comparators.cs b/SystemExtensions/Comparators.cs deleted file mode 100644 index e04c877..0000000 --- a/SystemExtensions/Comparators.cs +++ /dev/null @@ -1,470 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SystemExtensions -{ - /// - /// Static class containing implementation of comparators to be used when creating and using collections. - /// - public static class Comparators - { - #region Fields - private static Comparison intComparison = new Comparison(IntegerComparison); - private static Comparison floatComparison = new Comparison(FloatComparison); - private static Comparison doubleComparison = new Comparison(DoubleComparison); - private static Comparison boolComparison = new Comparison(BoolComparison); - private static Comparison decimalComparison = new Comparison(DecimalComparison); - private static Comparison byteComparison = new Comparison(ByteComparison); - private static Comparison longComparison = new Comparison(LongComparison); - private static Comparison uintComparison = new Comparison(UintComparison); - private static Comparison int16Comparison = new Comparison(Int16Comparison); - private static Comparison int32Comparison = new Comparison(Int32Comparison); - private static Comparison int64Comparison = new Comparison(int64Comparison); - private static Comparison uInt16Comparison = new Comparison(uInt16Comparison); - private static Comparison uInt32Comparison = new Comparison(uInt32Comparison); - private static Comparison uInt64Comparison = new Comparison(uInt64Comparison); - #endregion - #region Properties - /// - /// Comparison between two ints. - /// - public static Comparison Int - { - get - { - return intComparison; - } - } - /// - /// Comparison between two floats. - /// - public static Comparison Float - { - get - { - return floatComparison; - } - } - /// - /// Comparison between two doubles. - /// - public static Comparison Double - { - get - { - return doubleComparison; - } - } - /// - /// Comparison between two decimals. - /// - public static Comparison Decimal - { - get - { - return decimalComparison; - } - } - /// - /// Comparison between two bools. - /// - public static Comparison Bool - { - get - { - return boolComparison; - } - } - /// - /// Comparison between two bytes. - /// - public static Comparison Byte - { - get - { - return byteComparison; - } - } - /// - /// Comparison between two longs. - /// - public static Comparison Long - { - get - { - return longComparison; - } - } - /// - /// Comparison between two uints. - /// - public static Comparison Uint - { - get - { - return uintComparison; - } - } - /// - /// Comparison between two int16. - /// - public static Comparison Int16 - { - get - { - return int16Comparison; - } - } - /// - /// Comparison between two int32. - /// - public static Comparison Int32 - { - get - { - return int32Comparison; - } - } - /// - /// Comparison between two int64. - /// - public static Comparison Int64 - { - get - { - return int64Comparison; - } - } - /// - /// Comparison between two uint16. - /// - public static Comparison UInt16 - { - get - { - return uInt16Comparison; - } - } - /// - /// Comparison between two uint32. - /// - public static Comparison UInt32 - { - get - { - return uInt32Comparison; - } - } - /// - /// Comparison between two uint64. - /// - public static Comparison UInt64 - { - get - { - return uInt64Comparison; - } - } - #endregion - #region Private Methods - /// - /// Compares two UInt64. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int Uint64Comparison(UInt64 x, UInt64 y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two UInt32. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int Uint32Comparison(UInt32 x, UInt32 y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two UInt16. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int Uint16Comparison(UInt16 x, UInt16 y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Int64. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int Int64Comparison(Int64 x, Int64 y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two UInt32. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int Int32Comparison(Int32 x, Int32 y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two UInt16. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int Int16Comparison(Int16 x, Int16 y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two uint. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int UintComparison(uint x, uint y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Long. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int LongComparison(long x, long y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Byte. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int ByteComparison(byte x, byte y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Decimal. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int DecimalComparison(decimal x, decimal y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Bool. - /// - /// First value. - /// Second value. - /// Returns 1 if x is true and y is false. 0 if they are the same and -1 - /// if y is true and x is false. - private static int BoolComparison(bool x, bool y) - { - if (x == y) - { - return 0; - } - else if (x == true && y == false) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Double. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int DoubleComparison(double x, double y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Float. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int FloatComparison(float x, float y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - /// - /// Compares two Integer. - /// - /// First value. - /// Second value. - /// Returns 1 if x > y. 0 if equal and -1 if y > x. - private static int IntegerComparison(int x, int y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - #endregion - } -} diff --git a/SystemExtensions/SystemExtensions.csproj b/SystemExtensions/SystemExtensions.csproj index 4b872f6..84b461e 100644 --- a/SystemExtensions/SystemExtensions.csproj +++ b/SystemExtensions/SystemExtensions.csproj @@ -51,7 +51,6 @@ - diff --git a/SystemExtensions/Threading/PriorityThreadPool.cs b/SystemExtensions/Threading/PriorityThreadPool.cs index c62cbaf..dd9febc 100644 --- a/SystemExtensions/Threading/PriorityThreadPool.cs +++ b/SystemExtensions/Threading/PriorityThreadPool.cs @@ -15,6 +15,72 @@ namespace SystemExtensions.Threading /// public class PriorityThreadPool : IDisposable { + private class QueueEntry : IComparable + { + public TaskPriority TaskPriority; + public WaitCallback WaitCallback; + public Object Object; + public QueueEntry(TaskPriority priority, WaitCallback callback, object obj) + { + this.TaskPriority = priority; + this.WaitCallback = callback; + this.Object = obj; + } + + public int CompareTo(QueueEntry other) + { + int priority1 = 0, priority2 = 0; + switch (this.TaskPriority) + { + case TaskPriority.Highest: + priority1 = 4; + break; + case TaskPriority.AboveNormal: + priority1 = 3; + break; + case TaskPriority.Normal: + priority1 = 2; + break; + case TaskPriority.BelowNormal: + priority1 = 1; + break; + case TaskPriority.Lowest: + priority1 = 0; + break; + } + switch (other.TaskPriority) + { + case TaskPriority.Highest: + priority2 = 4; + break; + case TaskPriority.AboveNormal: + priority2 = 3; + break; + case TaskPriority.Normal: + priority2 = 2; + break; + case TaskPriority.BelowNormal: + priority2 = 1; + break; + case TaskPriority.Lowest: + priority2 = 0; + break; + } + if (priority1 == priority2) + { + return 0; + } + else if (priority1 > priority2) + { + return -1; + } + else + { + return 1; + } + } + } + #region Enum /// /// Enum for priority of task scheduled @@ -48,7 +114,7 @@ namespace SystemExtensions.Threading /// List that contains current running threads and their status. /// private volatile List threadpool; - private volatile PriorityQueue> tasks; + private volatile PriorityQueue tasks; private Thread observer; private int maxThreads; private object tasksLock = new object(); @@ -109,7 +175,7 @@ namespace SystemExtensions.Threading public PriorityThreadPool() { threadpool = new List(); - tasks = new PriorityQueue>(PriorityCompare); + tasks = new PriorityQueue(); maxThreads = System.Environment.ProcessorCount; for (int i = 0; i < maxThreads; i++) { @@ -138,7 +204,7 @@ namespace SystemExtensions.Threading public PriorityThreadPool(int maxThreads) { threadpool = new List(); - tasks = new PriorityQueue>(PriorityCompare); + tasks = new PriorityQueue(); this.maxThreads = Math.Max(maxThreads, 1); for (int i = 0; i < maxThreads; i++) { @@ -172,7 +238,7 @@ namespace SystemExtensions.Threading public PriorityThreadPool(int lowest, int belowNormal, int normal, int aboveNormal, int highest) { threadpool = new List(); - tasks = new PriorityQueue>(PriorityCompare); + tasks = new PriorityQueue(); for(int i = 0; i < lowest; i++) { WorkerThread worker = new WorkerThread(); @@ -250,7 +316,7 @@ namespace SystemExtensions.Threading public void QueueUserWorkItem(WaitCallback waitCallback, object callbackState, TaskPriority taskPriority) { while (!Monitor.TryEnter(tasksLock)); - tasks.Enqueue(new Tuple(taskPriority, waitCallback, callbackState)); + tasks.Enqueue(new QueueEntry(taskPriority, waitCallback, callbackState)); Monitor.Exit(tasksLock); } /// @@ -265,64 +331,6 @@ namespace SystemExtensions.Threading #endregion #region Private Methods /// - /// Function that compares two tasks based on their priorities - /// - /// First tuple to compare - /// Second tuple to compare - /// 1 if tp1 is bigger. 0 if equal and -1 if tp1 is lower. - private static int PriorityCompare(Tuple tp1, Tuple tp2) - { - int priority1 = 0, priority2 = 0; - switch (tp1.Item1) - { - case TaskPriority.Highest: - priority1 = 4; - break; - case TaskPriority.AboveNormal: - priority1 = 3; - break; - case TaskPriority.Normal: - priority1 = 2; - break; - case TaskPriority.BelowNormal: - priority1 = 1; - break; - case TaskPriority.Lowest: - priority1 = 0; - break; - } - switch (tp2.Item1) - { - case TaskPriority.Highest: - priority2 = 4; - break; - case TaskPriority.AboveNormal: - priority2 = 3; - break; - case TaskPriority.Normal: - priority2 = 2; - break; - case TaskPriority.BelowNormal: - priority2 = 1; - break; - case TaskPriority.Lowest: - priority2 = 0; - break; - } - if (priority1 == priority2) - { - return 0; - } - else if(priority1 > priority2) - { - return -1; - } - else - { - return 1; - } - } - /// /// Main loop that a thread from the pool is running. /// /// Id of thread @@ -340,7 +348,7 @@ namespace SystemExtensions.Threading //Finally, release the lock and invoke the task. thisWorkerThread.working = true; - Tuple task = null; + QueueEntry task = null; while (!Monitor.TryEnter(tasksLock)) ; if (tasks.Count > 0) { @@ -350,8 +358,8 @@ namespace SystemExtensions.Threading if (task != null) { System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.Name + " - Running task!"); - WaitCallback waitCallback = task.Item2; - waitCallback.Invoke(task.Item3); + WaitCallback waitCallback = task.WaitCallback; + waitCallback.Invoke(task.Object); } thisWorkerThread.working = false; } diff --git a/SystemExtensionsTests/Collections/AVLTreeTests.cs b/SystemExtensionsTests/Collections/AVLTreeTests.cs index e99fbb4..b012881 100644 --- a/SystemExtensionsTests/Collections/AVLTreeTests.cs +++ b/SystemExtensionsTests/Collections/AVLTreeTests.cs @@ -11,26 +11,11 @@ namespace SystemExtensions.Collections.Tests [TestClass()] public class AVLTreeTests { - private static int IntegerComparison(int x, int y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - private AVLTree avlTree = new AVLTree(new Comparison(IntegerComparison)); + private AVLTree avlTree = new AVLTree(); [TestMethod()] public void AVLTreeTest() { - avlTree = new AVLTree(IntegerComparison); + avlTree = new AVLTree(); } [TestMethod()] diff --git a/SystemExtensionsTests/Collections/BinaryHeapTests.cs b/SystemExtensionsTests/Collections/BinaryHeapTests.cs index 7f1a4f5..7240ebc 100644 --- a/SystemExtensionsTests/Collections/BinaryHeapTests.cs +++ b/SystemExtensionsTests/Collections/BinaryHeapTests.cs @@ -12,32 +12,17 @@ namespace SystemExtensions.Collections.Tests [TestClass()] public class BinaryHeapTests { - private static int IntegerComparison(int x, int y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - private BinaryHeap binaryHeap = new BinaryHeap(new Comparison(IntegerComparison)); + private BinaryHeap binaryHeap = new BinaryHeap(); [TestMethod()] public void BinaryHeapTest() { - binaryHeap = new BinaryHeap(new Comparison(IntegerComparison)); + binaryHeap = new BinaryHeap(); } [TestMethod()] public void BinaryHeapTest1() { - binaryHeap = new BinaryHeap(new Comparison(IntegerComparison), 100); + binaryHeap = new BinaryHeap(100); if (binaryHeap.Count != 0 && binaryHeap.Capacity != 100) { Assert.Fail(); diff --git a/SystemExtensionsTests/Collections/FibonacciHeapTests.cs b/SystemExtensionsTests/Collections/FibonacciHeapTests.cs index 5c388bd..a0a0619 100644 --- a/SystemExtensionsTests/Collections/FibonacciHeapTests.cs +++ b/SystemExtensionsTests/Collections/FibonacciHeapTests.cs @@ -12,22 +12,7 @@ namespace SystemExtensions.Collections.Tests [TestClass()] public class FibonacciHeapTests { - private static int IntegerComparison(int x, int y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - FibonacciHeap fibonacciHeap = new FibonacciHeap(new Comparison(IntegerComparison)); + FibonacciHeap fibonacciHeap = new FibonacciHeap(); [TestMethod()] public void InsertTest() { @@ -40,7 +25,7 @@ namespace SystemExtensions.Collections.Tests [TestMethod()] public void FibonacciHeapTest() { - fibonacciHeap = new FibonacciHeap(new Comparison(IntegerComparison)); + fibonacciHeap = new FibonacciHeap(); if(fibonacciHeap.Count != 0) { Assert.Fail(); @@ -50,8 +35,8 @@ namespace SystemExtensions.Collections.Tests [TestMethod()] public void MergeTest() { - FibonacciHeap fibonacciHeap1 = new FibonacciHeap(new Comparison(IntegerComparison)); - FibonacciHeap fibonacciHeap2 = new FibonacciHeap(new Comparison(IntegerComparison)); + FibonacciHeap fibonacciHeap1 = new FibonacciHeap(); + FibonacciHeap fibonacciHeap2 = new FibonacciHeap(); for(int i = 0; i < 100; i++) { diff --git a/SystemExtensionsTests/Collections/PriorityQueueTests.cs b/SystemExtensionsTests/Collections/PriorityQueueTests.cs index 22af644..4fd420b 100644 --- a/SystemExtensionsTests/Collections/PriorityQueueTests.cs +++ b/SystemExtensionsTests/Collections/PriorityQueueTests.cs @@ -12,28 +12,13 @@ namespace SystemExtensions.Collections.Tests [TestClass()] public class PriorityQueueTests { - private static int IntegerComparison(int x, int y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - private PriorityQueue priorityQueue = new PriorityQueue(new Comparison(IntegerComparison)); + private PriorityQueue priorityQueue = new PriorityQueue(); [TestMethod()] public void PriorityQueueTest() { try { - priorityQueue = new PriorityQueue(new Comparison(IntegerComparison)); + priorityQueue = new PriorityQueue(); if(priorityQueue.Count > 0) { Assert.Fail(); diff --git a/SystemExtensionsTests/Collections/TreapTests.cs b/SystemExtensionsTests/Collections/TreapTests.cs index 25ece11..8919ffc 100644 --- a/SystemExtensionsTests/Collections/TreapTests.cs +++ b/SystemExtensionsTests/Collections/TreapTests.cs @@ -11,26 +11,11 @@ namespace SystemExtensions.Collections.Tests [TestClass()] public class TreapTests { - private static int IntegerComparison(int x, int y) - { - if (x == y) - { - return 0; - } - else if (x > y) - { - return 1; - } - else - { - return -1; - } - } - Treap treap = new Treap(new Comparison(IntegerComparison)); + Treap treap = new Treap(); [TestMethod()] public void TreapTest() { - treap = new Treap(new Comparison(IntegerComparison)); + treap = new Treap(); } [TestMethod()]