-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extend Tuple API #7732
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
Merged
Merged
Extend Tuple API #7732
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2d9c1ec
Create a definition of the Split[T, N] type
34adaad
Finish implementing tuple.splitAt
4fad817
Add mergeSort benchmark to tupleOps.scala
e4dfcf5
Seed random generator for more constant results
769cd8a
Add take and drop methods on Tuples
e9d601f
Wrote tests for take and drop
87e5819
Add benchmarks for take and drop
dfb8033
Add benchmarks for tuple split
79d8ede
Add test for tuple split
2f09cf1
Add tuple tests to blacklist so that pickling test passes
08a7f8d
Replace itToArray by Iterator.copyToArray
68750ea
Remove Unit case in pattern matches
77a4496
Optimized some branches in take and drop
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
size:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
size:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
size:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools.benchmarks.tuples | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import scala.runtime.DynamicTuple | ||
|
||
@State(Scope.Thread) | ||
class Drop { | ||
@Param(Array("0")) | ||
var size: Int = _ | ||
var tuple: Tuple = _ | ||
var array: Array[Object] = _ | ||
var half: Int = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
tuple = () | ||
half = size / 2 | ||
|
||
for (i <- 1 to size) | ||
tuple = "elem" *: tuple | ||
|
||
array = new Array[Object](size) | ||
} | ||
|
||
@Benchmark | ||
def tupleDrop(): Tuple = { | ||
DynamicTuple.dynamicDrop(tuple, half) | ||
} | ||
|
||
@Benchmark | ||
def arrayDrop(): Array[Object] = { | ||
array.drop(half) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools.benchmarks.tuples | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import scala.runtime.DynamicTuple | ||
|
||
@State(Scope.Thread) | ||
class Split { | ||
@Param(Array("0")) | ||
var size: Int = _ | ||
var tuple: Tuple = _ | ||
var array: Array[Object] = _ | ||
var half: Int = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
tuple = () | ||
half = size / 2 | ||
|
||
for (i <- 1 to size) | ||
tuple = "elem" *: tuple | ||
|
||
array = new Array[Object](size) | ||
} | ||
|
||
@Benchmark | ||
def tupleSplit(): (Tuple, Tuple) = { | ||
DynamicTuple.dynamicSplitAt(tuple, half) | ||
} | ||
|
||
@Benchmark | ||
def arraySplit(): (Array[Object], Array[Object]) = { | ||
array.splitAt(half) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools.benchmarks.tuples | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import scala.runtime.DynamicTuple | ||
|
||
@State(Scope.Thread) | ||
class Take { | ||
@Param(Array("0")) | ||
var size: Int = _ | ||
var tuple: Tuple = _ | ||
var array: Array[Object] = _ | ||
var half: Int = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
tuple = () | ||
half = size / 2 | ||
|
||
for (i <- 1 to size) | ||
tuple = "elem" *: tuple | ||
|
||
array = new Array[Object](size) | ||
} | ||
|
||
@Benchmark | ||
def tupleTake(): Tuple = { | ||
DynamicTuple.dynamicTake(tuple, half) | ||
} | ||
|
||
@Benchmark | ||
def arrayTake(): Array[Object] = { | ||
array.take(half) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
() | ||
() | ||
() | ||
(1,2,3,4,5) | ||
(2,3,4,5) | ||
(4,5) | ||
() | ||
() | ||
(11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35) | ||
(12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35) | ||
(21,22,23,24,25,26,27,28,29,30,31,32,33,34,35) | ||
(31,32,33,34,35) | ||
() | ||
() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
object Test extends App { | ||
val emptyTuple: Tuple = () | ||
val tuple: Tuple = ("1", "2", "3", "4", "5") | ||
val tupleXXL: Tuple = ("11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35") | ||
|
||
println(emptyTuple.drop(0)) | ||
println(emptyTuple.drop(1)) | ||
println(emptyTuple.drop(10)) | ||
|
||
println(tuple.drop(0)) | ||
println(tuple.drop(1)) | ||
println(tuple.drop(3)) | ||
println(tuple.drop(5)) | ||
println(tuple.drop(10)) | ||
|
||
println(tupleXXL.drop(0)) | ||
println(tupleXXL.drop(1)) | ||
println(tupleXXL.drop(10)) | ||
println(tupleXXL.drop(20)) | ||
println(tupleXXL.drop(25)) | ||
println(tupleXXL.drop(30)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.