Skip to content

Refactor Shuffle in Get-Random to save a full iteration of the objects.#8969

Merged
iSazonov merged 7 commits intoPowerShell:masterfrom
st0le:users/gakama/RefactorGetRandom
Mar 1, 2019
Merged

Refactor Shuffle in Get-Random to save a full iteration of the objects.#8969
iSazonov merged 7 commits intoPowerShell:masterfrom
st0le:users/gakama/RefactorGetRandom

Conversation

@st0le
Copy link
Copy Markdown
Contributor

@st0le st0le commented Feb 24, 2019

PR Summary

Minor refactoring of the Fisher Yates shuffle to save an additional iteration.

PR Context

Micro-optimization to the shuffle function.

PR Checklist

@st0le st0le changed the title Refactor Shuffle in Get-Random to save an iteration. Refactor Shuffle in Get-Random to save a full iteration of the objects. Feb 24, 2019
@st0le st0le closed this Feb 24, 2019
@st0le st0le reopened this Feb 24, 2019
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 26, 2019
@iSazonov iSazonov requested a review from TravisEz13 February 26, 2019 03:38
object tmp = _chosenListItems[i];
_chosenListItems[i] = _chosenListItems[j];
_chosenListItems[j] = tmp;
_chosenListItems[j] = _chosenListItems[i];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this cause the value in i to be duplicated? Shouldn't we swap like we did before?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand now, the assignment effectively removes the output value from the list for the next iteration. The comment should be updated to make this more clear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do it soon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

Please update code comment to make assignment rather than swap change more clear.

object tmp = _chosenListItems[i];
_chosenListItems[i] = _chosenListItems[j];
_chosenListItems[j] = tmp;
_chosenListItems[j] = _chosenListItems[i];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand now, the assignment effectively removes the output value from the list for the next iteration. The comment should be updated to make this more clear.

@iSazonov iSazonov self-assigned this Feb 27, 2019
@st0le
Copy link
Copy Markdown
Contributor Author

st0le commented Feb 28, 2019

How do I trigger the CI Build without a dummy commit? The build broke due to an unrelated change

@TravisEz13
Copy link
Copy Markdown
Member

Just ask and a maintainer can do it for you. Otherwise it requires a dummy commit. In this scenario, asking was better.

@TravisEz13
Copy link
Copy Markdown
Member

But looking at the history, it looks like GitHub is not remerging your PR. You might need to rebase your PR to reliably get a clean Windows CI.

@TravisEz13
Copy link
Copy Markdown
Member

I can do that for you if you don't know how, but the failures I saw are intermittent.

Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

@st0le Please fix the style issues and we'll merge.

@iSazonov iSazonov merged commit f31b338 into PowerShell:master Mar 1, 2019
@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Mar 1, 2019

@st0le Thanks for your contribution!

Perhaps you might be interested in #8986.

@st0le st0le deleted the users/gakama/RefactorGetRandom branch March 19, 2019 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants