52 changed files with 1309 additions and 109 deletions
@ -0,0 +1,83 @@ |
|||
/* |
|||
Copyright 2007-2013 The NGenerics Team |
|||
(https://github.com/ngenerics/ngenerics/wiki/Team)
|
|||
|
|||
This program is licensed under the GNU Lesser General Public License (LGPL). You should |
|||
have received a copy of the license along with the source code. If not, an online copy |
|||
of the license can be found at http://www.gnu.org/copyleft/lesser.html.
|
|||
*/ |
|||
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using NGenerics.Util; |
|||
|
|||
namespace NGenerics.Comparers |
|||
{ |
|||
/// <summary>
|
|||
/// A comparer that wraps the IComparable interface to reproduce the opposite comparison result.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the objects to compare.</typeparam>
|
|||
//[Serializable]
|
|||
public sealed class ReverseComparer<T> : IComparer<T> |
|||
{ |
|||
#region Globals
|
|||
|
|||
private IComparer<T> comparerToUse; |
|||
|
|||
#endregion
|
|||
|
|||
#region Construction
|
|||
/// <inheritdoc />
|
|||
public ReverseComparer() |
|||
{ |
|||
comparerToUse = Comparer<T>.Default; |
|||
} |
|||
|
|||
|
|||
/// <param name="comparer">The comparer to reverse.</param>
|
|||
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
|
|||
public ReverseComparer(IComparer<T> comparer) |
|||
{ |
|||
|
|||
Guard.ArgumentNotNull(comparer, "comparer"); |
|||
comparerToUse = comparer; |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region IComparer<T> Members
|
|||
|
|||
/// <inheritdoc />
|
|||
public int Compare(T x, T y) |
|||
{ |
|||
return (comparerToUse.Compare(y, x)); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Public Members
|
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the comparer used in this instance.
|
|||
/// </summary>
|
|||
/// <value>The comparer.</value>
|
|||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
|
|||
public IComparer<T> Comparer |
|||
{ |
|||
get |
|||
{ |
|||
return comparerToUse; |
|||
} |
|||
set |
|||
{ |
|||
|
|||
Guard.ArgumentNotNull(value, "value"); |
|||
|
|||
comparerToUse = value; |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,429 @@ |
|||
/* |
|||
Copyright 2007-2013 The NGenerics Team |
|||
(https://github.com/ngenerics/ngenerics/wiki/Team)
|
|||
|
|||
This program is licensed under the GNU Lesser General Public License (LGPL). You should |
|||
have received a copy of the license along with the source code. If not, an online copy |
|||
of the license can be found at http://www.gnu.org/copyleft/lesser.html.
|
|||
*/ |
|||
|
|||
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using NGenerics.Comparers; |
|||
using System.Diagnostics.CodeAnalysis; |
|||
using NGenerics.Util; |
|||
|
|||
namespace NGenerics.DataStructures.General |
|||
{ |
|||
/// <summary>
|
|||
/// An implementation of a Heap data structure.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of item stored in the <see cref="Heap{T}"/>.</typeparam>
|
|||
//[Serializable]
|
|||
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] |
|||
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] |
|||
public class Heap<T> : ICollection<T>, IHeap<T> |
|||
{ |
|||
#region Globals
|
|||
|
|||
const string heapIsEmpty = "The heap is empty."; |
|||
private readonly List<T> data; |
|||
private readonly IComparer<T> comparerToUse; |
|||
private readonly HeapType thisType; |
|||
|
|||
#endregion
|
|||
|
|||
#region Construction
|
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Heap<T>"/> class.
|
|||
/// </summary>
|
|||
/// <param name="type">The type of Heap to create.</param>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Constructor" lang="cs" title="The following example shows how to use the default constructor."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Constructor" lang="vbnet" title="The following example shows how to use the default constructor."/>
|
|||
/// </example>
|
|||
public Heap(HeapType type) : this(type, Comparer<T>.Default) { } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Heap<T>"/> class.
|
|||
/// </summary>
|
|||
/// <param name="type">The type of heap.</param>
|
|||
/// <param name="capacity">The capacity.</param>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
|
|||
/// .
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="ConstructorCapacity" lang="cs" title="The following example shows how to use the capacity constructor."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="ConstructorCapacity" lang="vbnet" title="The following example shows how to use the capacity constructor."/>
|
|||
/// </example>
|
|||
public Heap(HeapType type, int capacity) : this(type, capacity, Comparer<T>.Default) { } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Heap<T>"/> class.
|
|||
/// </summary>
|
|||
/// <param name="type">The type of heap.</param>
|
|||
/// <param name="comparer">The comparer.</param>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
|
|||
public Heap(HeapType type, Comparison<T> comparer) : this(type, new ComparisonComparer<T>(comparer)){} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Heap<T>"/> class.
|
|||
/// </summary>
|
|||
/// <param name="type">The type of heap.</param>
|
|||
/// <param name="capacity">The capacity of the heap to start with.</param>
|
|||
/// <param name="comparer">The comparer.</param>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
|
|||
public Heap(HeapType type, int capacity, Comparison<T> comparer) : this(type, capacity, new ComparisonComparer<T>(comparer)) { } |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Heap<T>"/> class.
|
|||
/// </summary>
|
|||
/// <param name="type">The type of Heap to create.</param>
|
|||
/// <param name="comparer">The comparer to use.</param>
|
|||
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="ConstructorComparer" lang="cs" title="The following example shows how to use the comparer constructor."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="ConstructorComparer" lang="vbnet" title="The following example shows how to use the comparer constructor."/>
|
|||
/// </example>
|
|||
public Heap(HeapType type, IComparer<T> comparer) |
|||
{ |
|||
Guard.ArgumentNotNull(comparer, "comparer"); |
|||
|
|||
if ((type != HeapType.Minimum) && (type != HeapType.Maximum)) |
|||
{ |
|||
throw new ArgumentOutOfRangeException("type"); |
|||
} |
|||
|
|||
thisType = type; |
|||
|
|||
data = new List<T> {default(T)}; |
|||
|
|||
comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer<T>(comparer); |
|||
} |
|||
|
|||
|
|||
/// <param name="type">The type of heap.</param>
|
|||
/// <param name="capacity">The initial capacity of the Heap.</param>
|
|||
/// <param name="comparer">The comparer to use.</param>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>.
|
|||
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
|
|||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="type"/> is not either <see cref="HeapType.Maximum"/> or <see cref="HeapType.Minimum"/> .</exception>
|
|||
public Heap(HeapType type, int capacity, IComparer<T> comparer) |
|||
{ |
|||
Guard.ArgumentNotNull(comparer, "comparer"); |
|||
|
|||
if ((type != HeapType.Minimum) && (type != HeapType.Maximum)) |
|||
{ |
|||
throw new ArgumentOutOfRangeException("type"); |
|||
} |
|||
thisType = type; |
|||
|
|||
data = new List<T>(capacity) {default(T)}; |
|||
|
|||
comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer<T>(comparer); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Public Members
|
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Root" lang="cs" title="The following example shows how to use the Root property."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Root" lang="vbnet" title="The following example shows how to use the Root property."/>
|
|||
/// </example>
|
|||
public T Root |
|||
{ |
|||
get |
|||
{ |
|||
#region Validation
|
|||
|
|||
if (Count == 0) |
|||
{ |
|||
throw new InvalidOperationException(heapIsEmpty); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
return data[1]; |
|||
} |
|||
} |
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="RemoveRoot" lang="cs" title="The following example shows how to use the RemoveRoot method."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="RemoveRoot" lang="vbnet" title="The following example shows how to use the RemoveRoot method."/>
|
|||
/// </example>
|
|||
public T RemoveRoot() |
|||
{ |
|||
#region Validation
|
|||
|
|||
if (Count == 0) |
|||
{ |
|||
throw new InvalidOperationException(heapIsEmpty); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
// The minimum item to return.
|
|||
var minimum = data[1]; |
|||
|
|||
RemoveRootItem(minimum); |
|||
return minimum; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Removes the root item.
|
|||
/// </summary>
|
|||
/// <param name="item">The item.</param>
|
|||
/// <remarks>
|
|||
/// <b>Notes to Inheritors: </b>
|
|||
/// Derived classes can override this method to change the behavior of the <see cref="RemoveRoot"/> method.
|
|||
/// </remarks>
|
|||
protected virtual void RemoveRootItem(T item) |
|||
{ |
|||
|
|||
// The last item in the heap
|
|||
var last = data[Count]; |
|||
data.RemoveAt(Count); |
|||
|
|||
// If there's still items left in this heap, re-heapify it.
|
|||
if (Count > 0) |
|||
{ |
|||
// Re-heapify the binary tree to conform to the heap property
|
|||
var counter = 1; |
|||
|
|||
while ((counter * 2) < (data.Count)) |
|||
{ |
|||
var child = counter * 2; |
|||
|
|||
if (((child + 1) < (data.Count)) && |
|||
(comparerToUse.Compare(data[child + 1], data[child]) < 0)) |
|||
{ |
|||
child++; |
|||
} |
|||
|
|||
if (comparerToUse.Compare(last, data[child]) <= 0) |
|||
{ |
|||
break; |
|||
} |
|||
|
|||
data[counter] = data[child]; |
|||
counter = child; |
|||
} |
|||
|
|||
data[counter] = last; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Gets the type of heap represented by this instance.
|
|||
/// </summary>
|
|||
/// <value>The type of heap.</value>
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Type" lang="cs" title="The following example shows how to use the Type property."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Type" lang="vbnet" title="The following example shows how to use the Type property."/>
|
|||
/// </example>
|
|||
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] |
|||
public HeapType Type |
|||
{ |
|||
get |
|||
{ |
|||
return thisType; |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region ICollection<T> Members
|
|||
|
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="IsEmpty" lang="cs" title="The following example shows how to use the IsEmpty property."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="IsEmpty" lang="vbnet" title="The following example shows how to use the IsEmpty property."/>
|
|||
/// </example>
|
|||
public bool IsEmpty |
|||
{ |
|||
get |
|||
{ |
|||
return Count == 0; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Contains" lang="cs" title="The following example shows how to use the Contains method."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Contains" lang="vbnet" title="The following example shows how to use the Contains method."/>
|
|||
/// </example>
|
|||
public bool Contains(T item) |
|||
{ |
|||
return data.Contains(item); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="CopyTo" lang="cs" title="The following example shows how to use the CopyTo method."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="CopyTo" lang="vbnet" title="The following example shows how to use the CopyTo method."/>
|
|||
/// </example>
|
|||
public void CopyTo(T[] array, int arrayIndex) |
|||
{ |
|||
#region Validation
|
|||
|
|||
Guard.ArgumentNotNull(array, "array"); |
|||
|
|||
if ((array.Length - arrayIndex) < Count) |
|||
{ |
|||
throw new ArgumentException(Constants.NotEnoughSpaceInTheTargetArray, "array"); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
for (var i = 1; i < data.Count; i++) |
|||
{ |
|||
array[arrayIndex++] = data[i]; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Count" lang="cs" title="The following example shows how to use the Count property."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Count" lang="vbnet" title="The following example shows how to use the Count property."/>
|
|||
/// </example>
|
|||
public int Count |
|||
{ |
|||
get |
|||
{ |
|||
return data.Count - 1; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Add" lang="cs" title="The following example shows how to use the Add method."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Add" lang="vbnet" title="The following example shows how to use the Add method."/>
|
|||
/// </example>
|
|||
public void Add(T item) |
|||
{ |
|||
AddItem(item); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds the item.
|
|||
/// </summary>
|
|||
/// <param name="item">The item to add.</param>
|
|||
/// <remarks>
|
|||
/// <b>Notes to Inheritors: </b>
|
|||
/// Derived classes can override this method to change the behavior of the <see cref="Add"/> method.
|
|||
/// </remarks>
|
|||
protected virtual void AddItem(T item) |
|||
{ |
|||
// Add a dummy to the end of the list (it will be replaced)
|
|||
data.Add(default(T)); |
|||
|
|||
var counter = data.Count - 1; |
|||
|
|||
while ((counter > 1) && (comparerToUse.Compare(data[counter / 2], item) > 0)) |
|||
{ |
|||
data[counter] = data[counter / 2]; |
|||
counter = counter / 2; |
|||
} |
|||
|
|||
data[counter] = item; |
|||
} |
|||
|
|||
|
|||
|
|||
/// <inheritdoc />
|
|||
/// <exception cref="NotSupportedException">Always.</exception>
|
|||
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] |
|||
bool ICollection<T>.Remove(T item) |
|||
{ |
|||
throw new NotSupportedException(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns an enumerator that iterates through the collection.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
|
|||
/// </returns>
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="GetEnumerator" lang="cs" title="The following example shows how to use the GetEnumerator method."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="GetEnumerator" lang="vbnet" title="The following example shows how to use the GetEnumerator method."/>
|
|||
/// </example>
|
|||
public IEnumerator<T> GetEnumerator() |
|||
{ |
|||
for (var i = 1; i < data.Count; i++) |
|||
{ |
|||
yield return data[i]; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="Clear" lang="cs" title="The following example shows how to use the Clear method."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="Clear" lang="vbnet" title="The following example shows how to use the Clear method."/>
|
|||
/// </example>
|
|||
public void Clear() |
|||
{ |
|||
ClearItems(); |
|||
} |
|||
/// <summary>
|
|||
/// Clears all the objects in this instance.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// <b>Notes to Inheritors: </b>
|
|||
/// Derived classes can override this method to change the behavior of the <see cref="Clear"/> method.
|
|||
/// </remarks>
|
|||
protected virtual void ClearItems() |
|||
{ |
|||
data.RemoveRange(1, data.Count - 1); // Clears all objects in this instance except the first dummy one.
|
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region ICollection<T> Members
|
|||
|
|||
/// <inheritdoc />
|
|||
/// <example>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\HeapExamples.cs" region="IsReadOnly" lang="cs" title="The following example shows how to use the IsReadOnly property."/>
|
|||
/// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\HeapExamples.vb" region="IsReadOnly" lang="vbnet" title="The following example shows how to use the IsReadOnly property."/>
|
|||
/// </example>
|
|||
public bool IsReadOnly |
|||
{ |
|||
get |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region IEnumerable Members
|
|||
|
|||
/// <inheritdoc />
|
|||
IEnumerator IEnumerable.GetEnumerator() |
|||
{ |
|||
return GetEnumerator(); |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/* |
|||
Copyright 2007-2013 The NGenerics Team |
|||
(https://github.com/ngenerics/ngenerics/wiki/Team)
|
|||
|
|||
This program is licensed under the GNU Lesser General Public License (LGPL). You should |
|||
have received a copy of the license along with the source code. If not, an online copy |
|||
of the license can be found at http://www.gnu.org/copyleft/lesser.html.
|
|||
*/ |
|||
|
|||
|
|||
|
|||
namespace NGenerics.DataStructures.General |
|||
{ |
|||
/// <summary>
|
|||
/// The type of <see cref="Heap{T}"/> to implemented.
|
|||
/// </summary>
|
|||
public enum HeapType |
|||
{ |
|||
/// <summary>
|
|||
/// Makes the heap a Minimum-Heap - the smallest item is kept in the root of the <see cref="Heap{T}"/>.
|
|||
/// </summary>
|
|||
Minimum, |
|||
|
|||
/// <summary>
|
|||
/// Makes the heap a Maximum-Heap - the largest item is kept in the root of the <see cref="Heap{T}"/>.
|
|||
/// </summary>
|
|||
Maximum |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/* |
|||
Copyright 2007-2013 The NGenerics Team |
|||
(https://github.com/ngenerics/ngenerics/wiki/Team)
|
|||
|
|||
This program is licensed under the GNU Lesser General Public License (LGPL). You should |
|||
have received a copy of the license along with the source code. If not, an online copy |
|||
of the license can be found at http://www.gnu.org/copyleft/lesser.html.
|
|||
*/ |
|||
|
|||
|
|||
using System; |
|||
|
|||
namespace NGenerics.DataStructures.General |
|||
{ |
|||
/// <summary>
|
|||
/// An interface for the <see cref="Heap{T}"/> data structure.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of elements in the heap.</typeparam>
|
|||
public interface IHeap<T> |
|||
{ |
|||
/// <summary>
|
|||
/// Adds the specified item.
|
|||
/// </summary>
|
|||
/// <param name="item">The item.</param>
|
|||
void Add(T item); |
|||
|
|||
/// <summary>
|
|||
/// Removes the root and returns it.
|
|||
/// </summary>
|
|||
/// <returns>The root of the <see cref="Heap{T}"/>.</returns>
|
|||
/// <exception cref="InvalidOperationException">The <see cref="Graph{T}"/> is empty.</exception>
|
|||
T RemoveRoot(); |
|||
|
|||
/// <summary>
|
|||
/// Gets the root.
|
|||
/// </summary>
|
|||
/// <value>The root.</value>
|
|||
/// <exception cref="InvalidOperationException">The <see cref="Heap{T}"/> is empty.</exception>
|
|||
T Root { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{415E048E-4611-4815-9CF2-D774E29079AC}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>NGenerics</RootNamespace> |
|||
<AssemblyName>NGenerics</AssemblyName> |
|||
<DefaultLanguage>en-US</DefaultLanguage> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<!-- A reference to the entire .NET Framework is automatically included --> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="DataStructures\Comparers\ReverseComparer.cs" /> |
|||
<Compile Include="DataStructures\General\Heap.cs" /> |
|||
<Compile Include="DataStructures\General\HeapType.cs" /> |
|||
<Compile Include="DataStructures\General\IHeap.cs" /> |
|||
<Compile Include="DataStructures\Trees\BinarySearchTreeBase.cs" /> |
|||
<Compile Include="DataStructures\Trees\BinaryTree.cs" /> |
|||
<Compile Include="DataStructures\Comparers\ComparisonComparer.cs" /> |
|||
<Compile Include="Constants.cs" /> |
|||
<Compile Include="Util\Guard.cs" /> |
|||
<Compile Include="Patterns\Visitor\InOrderVisitor.cs" /> |
|||
<Compile Include="DataStructures\Queues\IQueue.cs" /> |
|||
<Compile Include="DataStructures\Trees\ISearchTree.cs" /> |
|||
<Compile Include="DataStructures\Trees\ITree.cs" /> |
|||
<Compile Include="Patterns\Visitor\IVisitor.cs" /> |
|||
<Compile Include="Patterns\Visitor\KeyTrackingVisitor.cs" /> |
|||
<Compile Include="DataStructures\Comparers\KeyValuePairComparer.cs" /> |
|||
<Compile Include="DataStructures\Trees\NodeColor.cs" /> |
|||
<Compile Include="Patterns\Visitor\OrderedVisitor.cs" /> |
|||
<Compile Include="DataStructures\Queues\PriorityQueue.cs" /> |
|||
<Compile Include="DataStructures\Queues\PriorityQueueType.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="DataStructures\Trees\RedBlackTree.cs" /> |
|||
<Compile Include="DataStructures\Trees\RedBlackTreeDictionary.cs" /> |
|||
<Compile Include="DataStructures\Trees\RedBlackTreeList.cs" /> |
|||
<Compile Include="DataStructures\Trees\RedBlackTreeNode.cs" /> |
|||
<Compile Include="Patterns\Visitor\TrackingVisitor.cs" /> |
|||
<Compile Include="Patterns\Visitor\ValueTrackingVisitor.cs" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,30 @@ |
|||
using System.Resources; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("NGenerics")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("NGenerics")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
[assembly: NeutralResourcesLanguage("en")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,51 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="LayoutableTests.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Layout.UnitTests |
|||
{ |
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
using Moq; |
|||
using Moq.AutoMock; |
|||
using Perspex.Controls; |
|||
using Perspex.Input; |
|||
using Perspex.Platform; |
|||
using Perspex.Rendering; |
|||
using Perspex.Styling; |
|||
using Splat; |
|||
|
|||
[TestClass] |
|||
public class LayoutableTests |
|||
{ |
|||
private Mock<ILayoutManager> layoutManager; |
|||
|
|||
[TestMethod] |
|||
public void Calling_InvalidateMeasure_On_Window_Should_Call_LayoutManager_InvalidateMeasure() |
|||
{ |
|||
using (var d = Locator.Current.WithResolver()) |
|||
{ |
|||
this.RegisterServices(); |
|||
|
|||
Window target = new Window(); |
|||
} |
|||
} |
|||
|
|||
private void RegisterServices() |
|||
{ |
|||
var l = Locator.CurrentMutable; |
|||
var m = new AutoMocker(); |
|||
|
|||
var lm = m.CreateInstance<ILayoutManager>(); |
|||
//this.layoutManager =
|
|||
|
|||
l.RegisterConstant(new Mock<IInputManager>().Object, typeof(IInputManager)); |
|||
l.RegisterConstant(this.layoutManager.Object, typeof(ILayoutManager)); |
|||
l.RegisterConstant(new Mock<IPlatformRenderInterface>().Object, typeof(IPlatformRenderInterface)); |
|||
l.RegisterConstant(new Mock<IRenderManager>().Object, typeof(IRenderManager)); |
|||
l.RegisterConstant(new Mock<IStyler>().Object, typeof(IStyler)); |
|||
l.RegisterConstant(new Mock<IWindowImpl>().Object, typeof(IWindowImpl)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,122 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{DB070A10-BF39-4752-8456-86E9D5928478}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Layout.UnitTests</RootNamespace> |
|||
<AssemblyName>Perspex.Layout.UnitTests</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> |
|||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> |
|||
<IsCodedUITest>False</IsCodedUITest> |
|||
<TestProjectType>UnitTest</TestProjectType> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Moq"> |
|||
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="Moq.AutoMock"> |
|||
<HintPath>..\packages\Moq.AutoMock.0.3.2.1\lib\net40\Moq.AutoMock.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="Splat"> |
|||
<HintPath>..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
|||
</ItemGroup> |
|||
</When> |
|||
<Otherwise> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> |
|||
</ItemGroup> |
|||
</Otherwise> |
|||
</Choose> |
|||
<ItemGroup> |
|||
<Compile Include="LayoutableTests.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Controls\Perspex.Controls.csproj"> |
|||
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
|||
<Name>Perspex.Controls</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="app.config" /> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
</ItemGroup> |
|||
</When> |
|||
</Choose> |
|||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Layout.UnitTests")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Layout.UnitTests")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("dbe66cf2-493d-42f4-bd18-d56b15d5dffd")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,11 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<configuration> |
|||
<runtime> |
|||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> |
|||
<dependentAssembly> |
|||
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" /> |
|||
<bindingRedirect oldVersion="0.0.0.0-4.2.1409.1722" newVersion="4.2.1409.1722" /> |
|||
</dependentAssembly> |
|||
</assemblyBinding> |
|||
</runtime> |
|||
</configuration> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" /> |
|||
<package id="Moq.AutoMock" version="0.3.2.1" targetFramework="net45" /> |
|||
<package id="Splat" version="1.5.1" targetFramework="net45" /> |
|||
</packages> |
|||
Loading…
Reference in new issue