Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS-206 Demos
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sankalp Gambhir
CS-206 Demos
Commits
6586fff1
Unverified
Commit
6586fff1
authored
2 years ago
by
Hamza Remmal
Browse files
Options
Downloads
Patches
Plain Diff
Add Intersection Correct example from lecture 3
parent
526b675b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/lecture3/03_IntersectionWrong.scala
+3
-3
3 additions, 3 deletions
src/main/scala/lecture3/03_IntersectionWrong.scala
src/main/scala/lecture3/04_IntersectionCorrect.scala
+22
-0
22 additions, 0 deletions
src/main/scala/lecture3/04_IntersectionCorrect.scala
with
25 additions
and
3 deletions
src/main/scala/lecture3/03_IntersectionWrong.scala
+
3
−
3
View file @
6586fff1
...
...
@@ -5,14 +5,14 @@ import scala.collection.parallel.CollectionConverters.IterableIsParallelizable
import
org.scalameter._
// TODO : THIS DOES NOT COMPILE
def
intersection
(
a
:
GenSet
[
Int
],
b
:
GenSet
[
Int
])
:
Set
[
Int
]
=
def
intersection
_wrong
(
a
:
GenSet
[
Int
],
b
:
GenSet
[
Int
])
:
Set
[
Int
]
=
val
result
=
mutable
.
Set
[
Int
]()
for
(
x
<-
a
)
if
(
b
contains
x
)
result
+=
x
result
@main
def
intersectionWrong
=
val
seqres
=
intersection
((
0
until
1000
).
toSet
,
(
0
until
1000
by
4
).
toSet
)
val
parres
=
intersection
((
0
until
1000
).
par
.
toSet
,
(
0
until
1000
by
4
).
par
.
toSet
)
val
seqres
=
intersection
_wrong
((
0
until
1000
).
toSet
,
(
0
until
1000
by
4
).
toSet
)
val
parres
=
intersection
_wrong
((
0
until
1000
).
par
.
toSet
,
(
0
until
1000
by
4
).
par
.
toSet
)
log
(
s
"Sequential result - ${seqres.size}"
)
log
(
s
"Parallel result - ${parres.size}"
)
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/lecture3/04_IntersectionCorrect.scala
0 → 100644
+
22
−
0
View file @
6586fff1
package
lecture3
import
org.scalameter.
*
import
java.util.
*
import
java.util.concurrent.ConcurrentSkipListSet
import
scala.collection.
*
import
scala.collection.parallel.CollectionConverters.IterableIsParallelizable
// TODO : THIS DOES NOT COMPILE
def
intersection_correct
(
a
:
GenSet
[
Int
],
b
:
GenSet
[
Int
])
=
val
result
=
new
ConcurrentSkipListSet
[
Int
]()
for
(
x
<-
a
)
if
(
b
contains
x
)
result
add
x
result
@main
def
intersectionCorrect
=
val
seqres
=
intersection_correct
((
0
until
1000
).
toSet
,
(
0
until
1000
by
4
).
toSet
)
val
parres
=
intersection_correct
((
0
until
1000
).
par
.
toSet
,
(
0
until
1000
by
4
).
par
.
toSet
)
log
(
s
"Sequential result - ${seqres.size}"
)
log
(
s
"Parallel result - ${parres.size}"
)
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