-
-
Notifications
You must be signed in to change notification settings - Fork 738
Add approaches for Parallel Letter Frequency #2863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I think this generally looks good! There's just a couple of things to fix in the Markdown.
| <!-- Your content goes here: --> | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this related to the PR. Could you please undo this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this related to the PR. Could you please undo this change?
the following error will occur.
.github/PULL_REQUEST_TEMPLATE.md:5 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
.github/PULL_REQUEST_TEMPLATE.md:6 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 3]
Should we go ahead and cancel it anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we should. I've just tried running our Markdown Lint action on our main branch (before your change). I think the rules are a bit different with that one.
| # Introduction | ||
|
|
||
| There are multiple ways to solve the Parallel Letter Frequency problem. | ||
| One approach is to use parallelStream, and another involves using ForkJoinPool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the existing approaches for other exercises, such as grains, I think it would be good to format the methods and classes with backticks (``) to maintain consistency in the formatting (example in the suggestion below). Could you go through and update?
| One approach is to use parallelStream, and another involves using ForkJoinPool. | |
| One approach is to use `Stream.parallelStream`, and another involves using `ForkJoinPool`. |
|
|
||
| ## General guidance | ||
|
|
||
| To count occurrences of items, a map data structure is often used, though arrays and lists can work as well. A map, being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally format our Markdown one sentence per line. Could you please go through and update the format?
| To count occurrences of items, a map data structure is often used, though arrays and lists can work as well. A map, being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key. | |
| To count occurrences of items, a map data structure is often used, though arrays and lists can work as well. | |
| A map, being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key. |
|
|
||
| Each subtask in LetterCountTask will continue calling compute() to divide itself further until the range is smaller than or equal to the threshold. | ||
|
|
||
| For tasks that are within the threshold, letter frequency is calculated. The [`isAlphabetic`][isAlphabetic] method is used to identify all characters classified as alphabetic in Unicode, covering various languages like English, Korean, Japanese, Chinese, etc., returning true for alphabetic characters and false for numbers, special characters, spaces, and others. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest using Character.isAlphabetic here to make it clear the method is from the Character class.
| For tasks that are within the threshold, letter frequency is calculated. The [`isAlphabetic`][isAlphabetic] method is used to identify all characters classified as alphabetic in Unicode, covering various languages like English, Korean, Japanese, Chinese, etc., returning true for alphabetic characters and false for numbers, special characters, spaces, and others. | |
| For tasks that are within the threshold, letter frequency is calculated. | |
| The [`Character.isAlphabetic`][isAlphabetic] method is used to identify all characters classified as alphabetic in Unicode, covering various languages like English, Korean, Japanese, Chinese, etc., returning `true` for alphabetic characters and `false` for numbers, special characters, spaces, and others. |
|
Hi @kahgoh Thanks for reviewing! I’ve incorporated the feedback and committed the changes. However, when I run markdownlint-cli2 on PULL_REQUEST_TEMPLATE.md encounter the error , Please check it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! There are still some places where I think we should place backticks. I've gone ahead and added them as suggestions.
I wasn't sure if there was misunderstanding in regards my earlier comment about having a sentence per line as I can see there are now empty lines between each sentence. While each sentence should start on its own line, there should only be empty lines between paragraphs.
For example, this from your first commit was fine:
It looks like this:
For example, this from your first commit was fine:
There are multiple ways to solve the Parallel Letter Frequency problem.
One approach is to use `parallelStream`, and another involves using `ForkJoinPool`.
It renders like this:
There are multiple ways to solve the Parallel Letter Frequency problem. One approach is to use
parallelStream, and another involves usingForkJoinPool.
But this makes two paragraphs:
There are multiple ways to solve the Parallel Letter Frequency problem.
One approach is to use `parallelStream`, and another involves using `ForkJoinPool`.
It looks like this:
There are multiple ways to solve the Parallel Letter Frequency problem.
One approach is to use
parallelStream, and another involves usingForkJoinPool.
Notice the first example looks like one paragraph, whereas the second looks like two.
See other approaches, like the collatz conjecture or Difference of squares for examples on how they are formatted.
I thought the arrangement of paragraphs or empty lines from your first commit was fine - we just needed to move the sentences to start on its own line. I have added some suggestions where the empty lines can be removed to turn them back to paragraphs. Feel free to go through and update other spots accordingly.
| <!-- Your content goes here: --> | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we should. I've just tried running our Markdown Lint action on our main branch (before your change). I think the rules are a bit different with that one.
|
|
||
| The core of [`ForkJoinPool`][ForkJoinPool] is the Fork/Join mechanism, which divides tasks into smaller units and processes them in parallel. | ||
|
|
||
| THRESHOLD is the criterion for task division. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| THRESHOLD is the criterion for task division. | |
| `THRESHOLD` is the criterion for task division. |
|
|
||
| THRESHOLD is the criterion for task division. | ||
|
|
||
| If the range of texts exceeds the THRESHOLD, the task is divided into two subtasks, and [`invokeAll`][invokeAll](leftTask, rightTask) is called to execute both tasks in parallel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| If the range of texts exceeds the THRESHOLD, the task is divided into two subtasks, and [`invokeAll`][invokeAll](leftTask, rightTask) is called to execute both tasks in parallel. | |
| If the range of texts exceeds the `THRESHOLD`, the task is divided into two subtasks, and [`invokeAll(leftTask, rightTask)`][invokeAll] is called to execute both tasks in parallel. |
|
|
||
| If the range of texts exceeds the THRESHOLD, the task is divided into two subtasks, and [`invokeAll`][invokeAll](leftTask, rightTask) is called to execute both tasks in parallel. | ||
|
|
||
| Each subtask in LetterCountTask will continue calling compute() to divide itself further until the range is smaller than or equal to the threshold. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Each subtask in LetterCountTask will continue calling compute() to divide itself further until the range is smaller than or equal to the threshold. | |
| Each subtask in `LetterCountTask` will continue calling `compute()` to divide itself further until the range is smaller than or equal to the threshold. |
|
|
||
| The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the parallelStream() method. | ||
|
|
||
| With parallelStream(), developers can use the ForkJoinPool model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| With parallelStream(), developers can use the ForkJoinPool model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools. | |
| With `parallelStream()`, developers can use the ForkJoinPool model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools. |
|
|
||
| The [`Character.isAlphabetic`][isAlphabetic] method is used to identify all characters classified as alphabetic in Unicode, covering various languages like English, Korean, Japanese, Chinese, etc., returning true for alphabetic characters and false for numbers, special characters, spaces, and others. | ||
|
|
||
| Additionally, since uppercase and lowercase letters are treated as the same character (e.g., A and a), each character is converted to lowercase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Additionally, since uppercase and lowercase letters are treated as the same character (e.g., A and a), each character is converted to lowercase. | |
| Additionally, since uppercase and lowercase letters are treated as the same character (e.g., `A` and `a`), each character is converted to lowercase. |
| # Introduction | ||
|
|
||
| There are multiple ways to solve the Parallel Letter Frequency problem. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest removing the empty line to turn back into paragraph.
| ## General guidance | ||
|
|
||
| To count occurrences of items, a map data structure is often used, though arrays and lists can work as well. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| To count occurrences of items, a map data structure is often used, though arrays and lists can work as well. | ||
|
|
||
| A [`map`][map], being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Parallel processing typically takes place in a multi-[`thread`][thread] environment. | ||
|
|
||
| The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the parallelStream() method. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Hi @kahgoh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think we're almost there! Just spotted a couple of minor things.
|
|
||
| `THRESHOLD` is the criterion for task division. | ||
| If the range of texts exceeds the `THRESHOLD`, the task is divided into two subtasks, and [`invokeAll(leftTask, rightTask)`][invokeAll] is called to execute both tasks in parallel. | ||
| Each subtask in LetterCountTask will continue calling compute() to divide itself further until the range is smaller than or equal to the `THRESHOLD`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest clarifying that compute is called through invokeAll. Your example only shows invokeAll being called, not compute, so it might be confusing. Also, suggest putting the LetterCountTask and compute in backticks for formatting.
| Each subtask in LetterCountTask will continue calling compute() to divide itself further until the range is smaller than or equal to the `THRESHOLD`. | |
| Each subtask in `LetterCountTask` will continue calling `compute()` (via `invokeAll(leftTask, rightTask)`) to divide itself further until the range is smaller than or equal to the `THRESHOLD`. |
|
@kahgoh Thank you! Is there anything else that could be improved? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It looks good to me now!
|
@kahgoh Thank you so much for the detailed review. This is my first time contributing to open source, and since I'm not very familiar with English, I made a lot of mistakes. Thanks to you, I was able to have a great experience! |
pull request
Approaches for Parallel Letter Frequency, ready for review!
Resolves #2710
Reviewer Resources:
Track Policies