Skip to content

Commit 4fd953b

Browse files
committed
v2.0.0 release
1 parent 7acdf5f commit 4fd953b

9 files changed

+513
-35
lines changed

PriorityQueues/BinaryPriorityQueue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ public BinaryPriorityQueue(IEnumerable<T> collection, Comparison<T> comparer)
5252
_heap = new List<T>(collection.Count());
5353
_comparer = comparer;
5454

55-
int i = 0;
5655
foreach (var elem in collection)
5756
{
5857
_heap.Add(elem);
5958
}
6059

6160
// heapify process
62-
for (int j = Math.Max(0, (_heap.Count / 2) - 1); j >= 0; j--)
61+
for (int i = Math.Max(0, (_heap.Count / 2) - 1); i >= 0; i--)
6362
{
6463
Sink(i);
6564
}
@@ -243,6 +242,7 @@ protected virtual T RemoveAt(int index)
243242
#endregion
244243

245244
#region IEnumerable interface implementation
245+
/// <inheritdoc/>
246246
public IEnumerator<T> GetEnumerator()
247247
{
248248
return ((IEnumerable<T>)_heap).GetEnumerator();

PriorityQueues/FibonacciPriorityQueue.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal QueueElement(T value, double priority)
4141
}
4242

4343
/// <summary>
44-
/// The actual <see cref="T"/>
44+
/// The actual value of the user-specified type
4545
/// </summary>
4646
public T Value { get; set; }
4747

@@ -52,7 +52,7 @@ internal QueueElement(T value, double priority)
5252
}
5353

5454
/// <summary>
55-
///
55+
/// Represents a single node in the fibonacci heap
5656
/// </summary>
5757
public sealed class Node
5858
{
@@ -82,8 +82,10 @@ internal Node(QueueElement value)
8282
/// <summary>
8383
/// Initializes a new instance of the <see cref="FibonacciPriorityQueue{T}"/> class that is empty
8484
/// </summary>
85+
/// <param name="type">The type of this priority queue used for comparing nodes</param>
8586
public FibonacciPriorityQueue(PriorityQueueType type)
8687
{
88+
Type = type;
8789
if(type == PriorityQueueType.Maximum)
8890
{
8991
_isMaxHeap = true;
@@ -119,10 +121,8 @@ public FibonacciPriorityQueue(Comparison<QueueElement> comparer)
119121
/// </summary>
120122
/// <param name="collection">The collection whose elements are copied to the <see cref="FibonacciPriorityQueue{T}"/></param>
121123
/// <param name="comparer"></param>
122-
public FibonacciPriorityQueue(IEnumerable<T> collection, Comparison<QueueElement> comparer)
124+
public FibonacciPriorityQueue(IEnumerable<T> collection, Comparison<QueueElement> comparer) : this(comparer)
123125
{
124-
_comparer = comparer;
125-
_hasCustomComparer = true;
126126
foreach (var element in collection)
127127
{
128128
Enqueue(element);
@@ -133,6 +133,11 @@ public FibonacciPriorityQueue(IEnumerable<T> collection, Comparison<QueueElement
133133
#region Public properties
134134
/// <inheritdoc/>
135135
public int Count => _count;
136+
137+
/// <summary>
138+
/// Gets the type of this priority queue
139+
/// </summary>
140+
public PriorityQueueType Type { get; }
136141
#endregion
137142

138143
#region Public methods
@@ -155,10 +160,10 @@ public bool Contains(T element)
155160
}
156161

157162
/// <summary>
158-
///
163+
/// Sets a new priority for the specified node. The new value has to be lower if the <see cref="Type"/> is <see cref="PriorityQueueType.Maximum"/> or higher if the <see cref="Type"/> is <see cref="PriorityQueueType.Minimum"/>
159164
/// </summary>
160-
/// <param name="node"></param>
161-
/// <param name="newPriority"></param>
165+
/// <param name="node"><see cref="Node"/> to be modified</param>
166+
/// <param name="newPriority">A finite value representing the new priority</param>
162167
public void DecreaseKey(Node node, double newPriority)
163168
{
164169
if(double.IsNaN(newPriority))
@@ -281,7 +286,7 @@ public void Enqueue(T element)
281286
/// /// <exception cref="ArgumentNullException"></exception>
282287
/// <param name="element">The element to be added to the queue</param>
283288
/// <param name="priority">The priority value</param>
284-
public void Enqueue(T element, double priority)
289+
public Node Enqueue(T element, double priority)
285290
{
286291
if(element == null)
287292
{
@@ -293,6 +298,8 @@ public void Enqueue(T element, double priority)
293298
_minNode = MergeLists(_minNode, newNode);
294299

295300
_count++;
301+
302+
return newNode;
296303
}
297304

298305
/// <inheritdoc/>
@@ -321,9 +328,9 @@ public bool Remove(T element)
321328
}
322329

323330
/// <summary>
324-
///
331+
/// Removes a node from the queue
325332
/// </summary>
326-
/// <param name="node">Node to be removed</param>
333+
/// <param name="node"><see cref="Node"/> to be removed</param>
327334
public void Remove(Node node)
328335
{
329336
if(_hasCustomComparer)

PriorityQueues/MappedBinaryPriorityQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public MappedBinaryPriorityQueue(IEnumerable<T> collection, Comparison<T> compar
5252
// heapify process
5353
for (int j = Math.Max(0, (_heap.Count / 2) - 1); j >= 0; j--)
5454
{
55-
Sink(i);
55+
Sink(j);
5656
}
5757
}
5858
#endregion

PriorityQueues/PriorityQueues.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@
77
<UpgradeBackupLocation />
88
<ProjectGuid>{68BC24ED-9C80-4BE1-8FBC-21E42AF7E1BD}</ProjectGuid>
99
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
10+
<Authors>Mikołaj Kuleszow</Authors>
11+
<PackageProjectUrl>https://github.com/mikkul/PriorityQueue</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/mikkul/PriorityQueue</RepositoryUrl>
13+
<PackageTags>priorityqueue, heap, pq, comparer, collection</PackageTags>
14+
<Company />
15+
<Copyright>Copyright 2021</Copyright>
16+
<PackageLicenseExpression></PackageLicenseExpression>
17+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
18+
<Version>2.0.0</Version>
1019
</PropertyGroup>
1120
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
1221
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
1322
</PropertyGroup>
1423
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
1524
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
1625
</PropertyGroup>
26+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
27+
<DocumentationFile>D:\C#_Stuff\PriorityQueue\PriorityQueues\PriorityQueues.xml</DocumentationFile>
28+
</PropertyGroup>
29+
<ItemGroup>
30+
<None Include="LICENSE.txt" Pack="true" PackagePath="" />
31+
</ItemGroup>
1732
</Project>

0 commit comments

Comments
 (0)