Skip to content

Commit

Permalink
Merge pull request #111 from kzrnm/fix/EnqueueDequeue
Browse files Browse the repository at this point in the history
 Fix EnqueueDequeue
  • Loading branch information
kzrnm committed Nov 26, 2023
2 parents 6cd1b90 + 3e5a2a5 commit a1fbf30
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.6.0] - 2023-11-25
## [3.6.2] - 2023-11-26
### Changed
- Fix EnqueueDequeue

## [3.6.1] - 2023-11-25
### Changed
- Fix doc of FloorSum

Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<RepositoryUrl>https://github.com/kzrnm/ac-library-csharp</RepositoryUrl>
<PackageReleaseNotes>https://github.com/kzrnm/ac-library-csharp/blob/main/CHANGELOG.md</PackageReleaseNotes>

<Version>3.6.1</Version>
<AssemblyVersion>3.6.1.101</AssemblyVersion>
<Version>3.6.2</Version>
<AssemblyVersion>3.6.2.101</AssemblyVersion>
<RepositoryCommit Condition="'$(GIT_COMMIT)' != ''">$(GIT_COMMIT)</RepositoryCommit>

<SignAssembly>True</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public T Dequeue()
public T EnqueueDequeue(T value)
{
var res = data[0];
if (_comparer.Compare(value, res) <= 0)
if (Count == 0 || _comparer.Compare(value, res) <= 0)
{
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public KeyValuePair<TKey, TValue> Dequeue()
public KeyValuePair<TKey, TValue> EnqueueDequeue(TKey key, TValue value)
{
var res = KeyValuePair.Create(keys[0], values[0]);
if (_comparer.Compare(key, keys[0]) <= 0)
if (Count == 0 || _comparer.Compare(key, keys[0]) <= 0)
{
return KeyValuePair.Create(key, value);
}
Expand Down
6 changes: 6 additions & 0 deletions Test/ac-library-csharp.Test/STL/PriorityQueueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public void EnqueueDequeue()
{
var pq1 = new PriorityQueue<int>();
var pq2 = new PriorityQueue<int>();

pq1.EnqueueDequeue(1).Should().Be(1);

for (int i = 10; i > 0; i--)
{
pq1.Enqueue(i);
Expand All @@ -242,6 +245,9 @@ public void EnqueueDequeueKV()
{
var pq1 = new PriorityQueueDictionary<int, string>();
var pq2 = new PriorityQueueDictionary<int, string>();

pq1.EnqueueDequeue(1, "ab").Should().Be(KeyValuePair.Create(1, "ab"));

for (int i = 10; i > 0; i--)
{
pq1.Enqueue(i, i.ToString());
Expand Down

0 comments on commit a1fbf30

Please sign in to comment.