diff --git a/SystemExtensions/Collections/AVLTree.cs b/SystemExtensions/Collections/AVLTree.cs
index 7c8f127..638095c 100644
--- a/SystemExtensions/Collections/AVLTree.cs
+++ b/SystemExtensions/Collections/AVLTree.cs
@@ -13,15 +13,17 @@ namespace SystemExtensions.Collections
/// Read on https://simpledevcode.wordpress.com/2014/09/16/avl-tree-in-c/
///
/// Provided type.
+ [Serializable]
public class AVLTree : ICollection where T : IComparable
{
#region Fields
- private class AVLNode
+ [Serializable]
+ private class AVLNode
{
- public T Value;
- public AVLNode Left;
- public AVLNode Right;
- public AVLNode(T value)
+ public TKey Value;
+ public AVLNode Left;
+ public AVLNode Right;
+ public AVLNode(TKey value)
{
this.Value = value;
}
diff --git a/SystemExtensions/Collections/BinaryHeap.cs b/SystemExtensions/Collections/BinaryHeap.cs
index 415c821..6af65aa 100644
--- a/SystemExtensions/Collections/BinaryHeap.cs
+++ b/SystemExtensions/Collections/BinaryHeap.cs
@@ -11,6 +11,7 @@ namespace SystemExtensions.Collections
/// Binary heap implementation.
///
/// Provided type.
+ [Serializable]
public class BinaryHeap : IEnumerable where T : IComparable
{
#region Fields
diff --git a/SystemExtensions/Collections/FibonacciHeap.cs b/SystemExtensions/Collections/FibonacciHeap.cs
index 75a606e..f97f2cd 100644
--- a/SystemExtensions/Collections/FibonacciHeap.cs
+++ b/SystemExtensions/Collections/FibonacciHeap.cs
@@ -11,6 +11,7 @@ namespace SystemExtensions.Collections
/// Fibonacci Heap implementation.
///
/// Provided type
+ [Serializable]
public class FibonacciHeap : IEnumerable where T : IComparable
{
#region Fields
@@ -460,7 +461,7 @@ namespace SystemExtensions.Collections
}
#endregion
}
-
+ [Serializable]
internal class FibonacciNode
{
#region Fields
diff --git a/SystemExtensions/Collections/PriorityQueue.cs b/SystemExtensions/Collections/PriorityQueue.cs
index c3a54df..f128fab 100644
--- a/SystemExtensions/Collections/PriorityQueue.cs
+++ b/SystemExtensions/Collections/PriorityQueue.cs
@@ -12,6 +12,7 @@ namespace SystemExtensions.Collections
/// Exposes some of the functionality of the Binary Heap as a queue.
///
/// Provided type.
+ [Serializable]
public class PriorityQueue : IQueue where T : IComparable
{
#region Fields
diff --git a/SystemExtensions/Collections/SkipList.cs b/SystemExtensions/Collections/SkipList.cs
index aa970e0..66963cd 100644
--- a/SystemExtensions/Collections/SkipList.cs
+++ b/SystemExtensions/Collections/SkipList.cs
@@ -11,9 +11,11 @@ namespace SystemExtensions.Collections
/// Skip list implementation.
///
/// Provided type.
+ [Serializable]
public class SkipList : ICollection where T : IComparable
{
#region Fields
+ [Serializable]
private class NodeSet
{
public TKey Key;
diff --git a/SystemExtensions/Collections/Treap.cs b/SystemExtensions/Collections/Treap.cs
index 059c262..3615634 100644
--- a/SystemExtensions/Collections/Treap.cs
+++ b/SystemExtensions/Collections/Treap.cs
@@ -11,15 +11,17 @@ namespace SystemExtensions.Collections
/// Treap implementation.
///
/// Provided type.
+ [Serializable]
public class Treap : ICollection where T : IComparable
{
#region Fields
- private class Item
+ [Serializable]
+ private class Node
{
- public T Key;
+ public TKey Key;
public int Priority;
- public Item Left, Right;
- public Item(T key, int priority)
+ public Node Left, Right;
+ public Node(TKey key, int priority)
{
Key = key;
Priority = priority;
@@ -28,7 +30,7 @@ namespace SystemExtensions.Collections
}
}
private Random randomGen;
- private Item root;
+ private Node root;
private int count;
#endregion
#region Properties
@@ -130,10 +132,10 @@ namespace SystemExtensions.Collections
}
#endregion
#region Private Methods
- private Item InsertNode(Item node, T key)
+ private Node InsertNode(Node node, T key)
{
if(node == null) {
- node = new Item(key, randomGen.Next(0, 100));
+ node = new Node(key, randomGen.Next(0, 100));
return node;
}
else if (key.CompareTo(node.Key) <= 0)
@@ -154,7 +156,7 @@ namespace SystemExtensions.Collections
}
return node;
}
- private Item RemoveNode(Item node, T key)
+ private Node RemoveNode(Node node, T key)
{
if(node == null)
{
@@ -188,21 +190,21 @@ namespace SystemExtensions.Collections
}
return node;
}
- private Item RotateRight(Item node)
+ private Node RotateRight(Node node)
{
- Item temp = node.Left, temp2 = temp.Right;
+ Node temp = node.Left, temp2 = temp.Right;
temp.Right = node;
node.Left = temp2;
return temp;
}
- private Item RotateLeft(Item node)
+ private Node RotateLeft(Node node)
{
- Item temp = node.Right, temp2 = temp.Left;
+ Node temp = node.Right, temp2 = temp.Left;
temp.Left = node;
node.Right = temp2;
return temp;
}
- private void Clear(Item node)
+ private void Clear(Node node)
{
if(node.Left != null)
{
@@ -214,7 +216,7 @@ namespace SystemExtensions.Collections
}
node.Left = node.Right = null;
}
- private Item Find(Item node, T key)
+ private Node Find(Node node, T key)
{
if(node == null)
{
@@ -224,7 +226,7 @@ namespace SystemExtensions.Collections
{
if(node.Key.CompareTo(key) < 0)
{
- Item found = Find(node.Left, key);
+ Node found = Find(node.Left, key);
if(found == null)
{
found = Find(node.Right, key);
@@ -233,7 +235,7 @@ namespace SystemExtensions.Collections
}
else if(node.Key.CompareTo(key) > 0)
{
- Item found = Find(node.Right, key);
+ Node found = Find(node.Right, key);
if (found == null)
{
found = Find(node.Left, key);
@@ -246,7 +248,7 @@ namespace SystemExtensions.Collections
}
}
}
- private void ToArray(Item node, ref T[] array, ref int index)
+ private void ToArray(Node node, ref T[] array, ref int index)
{
if(node != null)
{
@@ -256,9 +258,9 @@ namespace SystemExtensions.Collections
ToArray(node.Right, ref array, ref index);
}
}
- private IEnumerator GetEnumerator(Item currentNode)
+ private IEnumerator GetEnumerator(Node currentNode)
{
- Queue- > queue = new Queue
- >();
+ Queue> queue = new Queue>();
queue.Enqueue(currentNode);
while(queue.Count > 0)
{
diff --git a/SystemExtensionsTests/Collections/AVLTreeTests.cs b/SystemExtensionsTests/Collections/AVLTreeTests.cs
index b012881..629fd62 100644
--- a/SystemExtensionsTests/Collections/AVLTreeTests.cs
+++ b/SystemExtensionsTests/Collections/AVLTreeTests.cs
@@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
namespace SystemExtensions.Collections.Tests
{
@@ -124,5 +126,35 @@ namespace SystemExtensions.Collections.Tests
int[] array = avlTree.ToArray();
}
+
+ [TestMethod()]
+ public void Serialize()
+ {
+ AVLTree avlTree2 = new AVLTree();
+ for (int i = 0; i < 100; i++)
+ {
+ avlTree.Add(i);
+ }
+ BinaryFormatter serializer = new BinaryFormatter();
+ string s = string.Empty;
+ using (var stream = new MemoryStream())
+ {
+ serializer.Serialize(stream, avlTree);
+ stream.Position = 0;
+ avlTree2 = (AVLTree)serializer.Deserialize(stream);
+ }
+ IEnumerator avlTreeEnum = avlTree.GetEnumerator();
+ IEnumerator avlTree2Enum = avlTree2.GetEnumerator();
+
+ for(int i = 0; i < 100; i++)
+ {
+ if(avlTreeEnum.Current != avlTree2Enum.Current)
+ {
+ Assert.Fail();
+ }
+ avlTreeEnum.MoveNext();
+ avlTree2Enum.MoveNext();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SystemExtensionsTests/Collections/BinaryHeapTests.cs b/SystemExtensionsTests/Collections/BinaryHeapTests.cs
index 38b1c59..aae01a3 100644
--- a/SystemExtensionsTests/Collections/BinaryHeapTests.cs
+++ b/SystemExtensionsTests/Collections/BinaryHeapTests.cs
@@ -6,6 +6,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemExtensions;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Xml.Serialization;
+using System.IO;
namespace SystemExtensions.Collections.Tests
{
@@ -173,5 +176,34 @@ namespace SystemExtensions.Collections.Tests
Assert.Fail();
}
+
+ [TestMethod()]
+ public void Serialize()
+ {
+ BinaryHeap binaryHeap2 = new BinaryHeap();
+ for (int i = 0; i < 100; i++)
+ {
+ binaryHeap.Insert(i);
+ }
+ BinaryFormatter serializer = new BinaryFormatter();
+ string s = string.Empty;
+ using (var stream = new MemoryStream()) {
+ serializer.Serialize(stream, binaryHeap);
+ stream.Position = 0;
+ binaryHeap2 = (BinaryHeap)serializer.Deserialize(stream);
+ }
+ IEnumerator binaryHeapEnum = binaryHeap.GetEnumerator();
+ IEnumerator binaryHeapEnum2 = binaryHeap2.GetEnumerator();
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (binaryHeapEnum.Current != binaryHeapEnum2.Current)
+ {
+ Assert.Fail();
+ }
+ binaryHeapEnum.MoveNext();
+ binaryHeapEnum2.MoveNext();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SystemExtensionsTests/Collections/FibonacciHeapTests.cs b/SystemExtensionsTests/Collections/FibonacciHeapTests.cs
index a0a0619..8856e44 100644
--- a/SystemExtensionsTests/Collections/FibonacciHeapTests.cs
+++ b/SystemExtensionsTests/Collections/FibonacciHeapTests.cs
@@ -6,6 +6,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
namespace SystemExtensions.Collections.Tests
{
@@ -175,5 +177,35 @@ namespace SystemExtensions.Collections.Tests
Assert.Fail();
}
+
+ [TestMethod()]
+ public void Serialize()
+ {
+ FibonacciHeap fibonacciHeap2 = new FibonacciHeap();
+ for (int i = 0; i < 100; i++)
+ {
+ fibonacciHeap.Insert(i);
+ }
+ BinaryFormatter serializer = new BinaryFormatter();
+ string s = string.Empty;
+ using (var stream = new MemoryStream())
+ {
+ serializer.Serialize(stream, fibonacciHeap);
+ stream.Position = 0;
+ fibonacciHeap2 = (FibonacciHeap)serializer.Deserialize(stream);
+ }
+ IEnumerator enum1 = fibonacciHeap.GetEnumerator();
+ IEnumerator enum2 = fibonacciHeap2.GetEnumerator();
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (enum1.Current != enum2.Current)
+ {
+ Assert.Fail();
+ }
+ enum1.MoveNext();
+ enum2.MoveNext();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SystemExtensionsTests/Collections/PriorityQueueTests.cs b/SystemExtensionsTests/Collections/PriorityQueueTests.cs
index 4fd420b..0bb55a7 100644
--- a/SystemExtensionsTests/Collections/PriorityQueueTests.cs
+++ b/SystemExtensionsTests/Collections/PriorityQueueTests.cs
@@ -6,6 +6,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemExtensions;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
namespace SystemExtensions.Collections.Tests
{
@@ -81,5 +83,35 @@ namespace SystemExtensions.Collections.Tests
Assert.Fail();
}
}
+
+ [TestMethod()]
+ public void Serialize()
+ {
+ PriorityQueue priorityQueue2 = new PriorityQueue();
+ for (int i = 0; i < 100; i++)
+ {
+ priorityQueue.Enqueue(i);
+ }
+ BinaryFormatter serializer = new BinaryFormatter();
+ string s = string.Empty;
+ using (var stream = new MemoryStream())
+ {
+ serializer.Serialize(stream, priorityQueue);
+ stream.Position = 0;
+ priorityQueue2 = (PriorityQueue)serializer.Deserialize(stream);
+ }
+ IEnumerator enum1 = priorityQueue.GetEnumerator();
+ IEnumerator enum2 = priorityQueue2.GetEnumerator();
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (enum1.Current != enum2.Current)
+ {
+ Assert.Fail();
+ }
+ enum1.MoveNext();
+ enum2.MoveNext();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SystemExtensionsTests/Collections/SkipListTests.cs b/SystemExtensionsTests/Collections/SkipListTests.cs
index 7c6c427..4f6511f 100644
--- a/SystemExtensionsTests/Collections/SkipListTests.cs
+++ b/SystemExtensionsTests/Collections/SkipListTests.cs
@@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
namespace SystemExtensions.Collections.Tests
{
@@ -124,5 +126,35 @@ namespace SystemExtensions.Collections.Tests
Assert.Fail();
}
}
+
+ [TestMethod()]
+ public void Serialize()
+ {
+ SkipList skipList2 = new SkipList();
+ for (int i = 0; i < 100; i++)
+ {
+ skipList.Add(i);
+ }
+ BinaryFormatter serializer = new BinaryFormatter();
+ string s = string.Empty;
+ using (var stream = new MemoryStream())
+ {
+ serializer.Serialize(stream, skipList);
+ stream.Position = 0;
+ skipList2 = (SkipList)serializer.Deserialize(stream);
+ }
+ IEnumerator enum1 = skipList.GetEnumerator();
+ IEnumerator enum2 = skipList2.GetEnumerator();
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (enum1.Current != enum2.Current)
+ {
+ Assert.Fail();
+ }
+ enum1.MoveNext();
+ enum2.MoveNext();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SystemExtensionsTests/Collections/TreapTests.cs b/SystemExtensionsTests/Collections/TreapTests.cs
index 8919ffc..423c64a 100644
--- a/SystemExtensionsTests/Collections/TreapTests.cs
+++ b/SystemExtensionsTests/Collections/TreapTests.cs
@@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
namespace SystemExtensions.Collections.Tests
{
@@ -110,5 +112,35 @@ namespace SystemExtensions.Collections.Tests
Assert.Fail();
}
+
+ [TestMethod()]
+ public void Serialize()
+ {
+ Treap treap2 = new Treap();
+ for (int i = 0; i < 100; i++)
+ {
+ treap.Add(i);
+ }
+ BinaryFormatter serializer = new BinaryFormatter();
+ string s = string.Empty;
+ using (var stream = new MemoryStream())
+ {
+ serializer.Serialize(stream, treap);
+ stream.Position = 0;
+ treap2 = (Treap)serializer.Deserialize(stream);
+ }
+ IEnumerator enum1 = treap.GetEnumerator();
+ IEnumerator enum2 = treap2.GetEnumerator();
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (enum1.Current != enum2.Current)
+ {
+ Assert.Fail();
+ }
+ enum1.MoveNext();
+ enum2.MoveNext();
+ }
+ }
}
}
\ No newline at end of file
diff --git a/SystemExtensionsTests/SystemExtensionsTests.csproj b/SystemExtensionsTests/SystemExtensionsTests.csproj
index be24684..74d98d4 100644
--- a/SystemExtensionsTests/SystemExtensionsTests.csproj
+++ b/SystemExtensionsTests/SystemExtensionsTests.csproj
@@ -46,6 +46,7 @@
..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
+