Skip to content

Fix reported PriorityQueue issue.#77229

Merged
eiriktsarpalis merged 2 commits intodotnet:mainfrom
eiriktsarpalis:priorityqueue-consistency
Oct 24, 2022
Merged

Fix reported PriorityQueue issue.#77229
eiriktsarpalis merged 2 commits intodotnet:mainfrom
eiriktsarpalis:priorityqueue-consistency

Conversation

@eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Oct 19, 2022

Fix #77212.

@ghost
Copy link

ghost commented Oct 19, 2022

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Collections

Milestone: -

@eiriktsarpalis eiriktsarpalis changed the title Fix #77212. Fix reported PriorityQueue issue. Oct 19, 2022
@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Oct 19, 2022
ArgumentNullException.ThrowIfNull(elements);

int count;
if (elements is ICollection<(TElement Element, TPriority Priority)> collection &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously checking for the wrong ICollection type resulting in the optimization never being used.

// there at this point, as such an assignment would be redundant.

int currentSize = _size++;
int currentSize = _size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could MoveUpDefaultComparer/MoveUpCustomComparer throw? If so should you be doing _size + 1 here and _size = currentSize in the end of this method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it cannot. I could have moved it to the end of the method, but the Move* implementations currently require the size being up to date and I didn't want to change that invariant.

@eiriktsarpalis eiriktsarpalis merged commit 090003a into dotnet:main Oct 24, 2022
@eiriktsarpalis eiriktsarpalis deleted the priorityqueue-consistency branch October 24, 2022 21:10
@ghost ghost locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PriorityQueue<TElement, TPriority> edge case Count out of sync

2 participants