Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Monoid Design in Class
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 260
Monoid Design in Class
Commits
92f5ed6c
Commit
92f5ed6c
authored
Oct 12, 2023
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Switch to flavored code snippets.
parent
315de703
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
monoid-design.md
+6
-6
6 additions, 6 deletions
monoid-design.md
with
6 additions
and
6 deletions
monoid-design.md
+
6
−
6
View file @
92f5ed6c
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
## Iterative Reducers
## Iterative Reducers
```
```
js
function
iterativeReduce
(
monoid
,
sequence
)
{
function
iterativeReduce
(
monoid
,
sequence
)
{
let
result
=
monoid
.
identity
;
let
result
=
monoid
.
identity
;
for
(
const
element
of
sequence
)
{
for
(
const
element
of
sequence
)
{
...
@@ -71,7 +71,7 @@ function iterativeReduce(monoid, sequence) {
...
@@ -71,7 +71,7 @@ function iterativeReduce(monoid, sequence) {
## Recursive Reducers
## Recursive Reducers
```
```
js
function
recursiveReduce
(
monoid
,
sequence
)
{
function
recursiveReduce
(
monoid
,
sequence
)
{
if
(
sequence
.
length
===
0
)
{
if
(
sequence
.
length
===
0
)
{
return
monoid
.
identity
;
return
monoid
.
identity
;
...
@@ -122,7 +122,7 @@ function recursiveReduce(monoid, sequence) {
...
@@ -122,7 +122,7 @@ function recursiveReduce(monoid, sequence) {
*
In Code:
*
In Code:
```
```
js
async function parallelReduce(monoid, sequence, threadCount) {
async function parallelReduce(monoid, sequence, threadCount) {
const jobs = [];
const jobs = [];
for (let threadIndex = 0; threadIndex < threadCount; ++threadIndex) {
for (let threadIndex = 0; threadIndex < threadCount; ++threadIndex) {
...
@@ -241,7 +241,7 @@ Problem: Given a string of parentheses, determine if the parentheses are balance
...
@@ -241,7 +241,7 @@ Problem: Given a string of parentheses, determine if the parentheses are balance
## Clues about the Monoid from an Iterative Design
## Clues about the Monoid from an Iterative Design
```
```
js
function
isBalanced
(
parentheses
)
{
function
isBalanced
(
parentheses
)
{
let
nesting
=
0
;
let
nesting
=
0
;
for
(
const
character
of
parentheses
)
{
for
(
const
character
of
parentheses
)
{
...
@@ -300,7 +300,7 @@ function isBalanced(parentheses) {
...
@@ -300,7 +300,7 @@ function isBalanced(parentheses) {
## New Iterative Solution
## New Iterative Solution
```
```
js
function
encode
(
character
)
{
function
encode
(
character
)
{
if
(
character
===
'
(
'
)
{
if
(
character
===
'
(
'
)
{
return
[
…
,
…
];
return
[
…
,
…
];
...
@@ -327,7 +327,7 @@ function iterativeReduce(parentheses) {
...
@@ -327,7 +327,7 @@ function iterativeReduce(parentheses) {
## Parallel Solution
## Parallel Solution
```
```
js
async
function
parallelReduce
(
parentheses
,
threadCount
)
{
async
function
parallelReduce
(
parentheses
,
threadCount
)
{
const
jobs
=
[];
const
jobs
=
[];
for
(
let
threadIndex
=
0
;
threadIndex
<
threadCount
;
++
threadIndex
)
{
for
(
let
threadIndex
=
0
;
threadIndex
<
threadCount
;
++
threadIndex
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment