This repository was archived by the owner on Dec 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
SI-10167: Implement mutable.ArrayDeque #49
Closed
Closed
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
fcaa01a
First commit of ArrayDeque for collections-strawman
pathikrit 834d9d7
switch to scalatest
pathikrit 51e4f4a
upgrade scala version
pathikrit e6838e6
First pass through code review suggestions
pathikrit 57dbc41
move checkIndex to companion object
pathikrit faba4cd
rename arrayCopy to copySliceToArray
pathikrit 4f94cdd
break foreach+if into 2 while loops
pathikrit aa20b6c
change scalaversion to original
pathikrit fa6c7e0
DRY setting nulls
pathikrit 436a665
make defaultInitialSize final
pathikrit 56ca57b
remove ++=:
pathikrit 65133dc
inline fencePost util
pathikrit fab70a1
use Any instead of AnyRef
pathikrit ebbbb2a
use array copy for larger insertAll
pathikrit a17f38c
faster insertAll
pathikrit 5f137d5
switch back to using AnyRef arrays
pathikrit e418495
faster reverse
pathikrit b955281
use sizeHintIfCheap in insertAll
pathikrit c82c14e
fix typo
pathikrit aca8957
faster reverse
pathikrit 804bf43
implement sizeHint
pathikrit 595d6c5
downsize in removeFirst/removeLast
pathikrit 7892282
overwrite ++=:
pathikrit 0cde632
Add clear and shrink
pathikrit f7ed01c
Give user option to resize when using removeFirst/removeLast
pathikrit c09de3a
privatize internal constructor and state
pathikrit 1ecaf48
faster prepend
pathikrit 0f203ad
sliding works when windowSize > stepSize
pathikrit 27a8e6d
Document alternative sliding
pathikrit 49bb07a
Simplify sliding
pathikrit c9063c6
Make the assumingCapacity utils return this
pathikrit 64bc294
DRY-up bitmasking
pathikrit 185d61c
:lipstick:
pathikrit 68c9933
First pass through code review suggestions
pathikrit 3640fa6
Merge remote-tracking branch 'upstream/master'
pathikrit 076d6f5
Use junit for tests
pathikrit 42ff0e3
Switch to strawman.collection.mutable package
pathikrit bcab165
mimic behaviour of ArrayBuffer when count<0 and idx is out of bounds
pathikrit b0b6d78
do not resize if current size is fine
pathikrit 38147a5
PoC implementations of mutable.{Stack, Queue} using mutable.ArrayDeque
pathikrit 87ea88b
change names for private methods
pathikrit 33c7e67
optimize prependAll and insertAll
pathikrit f0e8ea8
Remove dependency on Predef.scala
pathikrit 891e519
DRY up mutable.{Stack, Queue}
pathikrit 35ae179
Go back to Array.clone()
pathikrit 36f27c4
Remove internal mask variable
pathikrit d46dd19
Optimized `++=:`
pathikrit 6c48477
simpler bound check
pathikrit 96d996d
Consistent naming of remove APIs
pathikrit 1dfc995
Faster Reverse APIs
pathikrit 2c93ade
Optimized insertAll for inserts at beginning/end
pathikrit 2bb2c75
Remove redundant check for emptiness
pathikrit 57b2fb6
Optimized removals
pathikrit 1647625
Optimize insertAll
pathikrit 360e4bf
Internal DSL for modular arithmetic
pathikrit 959410d
Optimize removeAll()
pathikrit b4cdc9b
Better resize strategy for removals
pathikrit de9c2ec
Do not repeatedly resize smaller collections
pathikrit 0c47056
Remove unused utils
pathikrit efd6a47
Do not import scala._
pathikrit ed1ace7
Add benchmarks
pathikrit 7addd8b
Improve benchmarks
pathikrit 4b54e93
Move ArrayDequeBenchmark to benchmarks module
pathikrit 755261e
Consistent length/size usages
pathikrit cb35330
Merge remote-tracking branch 'upstream/master'
pathikrit 968aa5f
Move to correct directory
pathikrit f832409
Add self to developers (to trigger a CI build post CLA sign check)
pathikrit 7b2b9e1
First cut at porting to Scala 2.13
pathikrit 8c4a20c
Move Stack/Queue to use strawman.collection.Seq
pathikrit 92f2252
Merge branch 'master' into master
pathikrit d3d7155
Rename removeHeadWhile to removeWhile
pathikrit b8c32a6
Move peek to queue/stack APIs
pathikrit 0519263
remove reverseIterator
pathikrit 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
45 changes: 45 additions & 0 deletions
45
benchmarks/time/src/main/scala/strawman/collection/mutable/ArrayDequeBenchmark.scala
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,45 @@ | ||
| package strawman.collection.mutable | ||
|
|
||
| import scala._ | ||
| import scala.collection.mutable | ||
| import scala.Predef._ | ||
|
|
||
| import java.lang.System.nanoTime | ||
|
|
||
| object ArrayDequeBenchmark extends App { | ||
| val candidates = Seq( | ||
| strawman.collection.mutable.ArrayDeque.empty[Int], | ||
| scala.collection.mutable.ArrayBuffer.empty[Int] | ||
| ) | ||
|
|
||
| def benchmark[U](name: String, f: mutable.Buffer[Int] => U) = { | ||
| def profile(buffer: mutable.Buffer[Int]) = { | ||
| val t1 = nanoTime() | ||
| f(buffer) | ||
| (nanoTime() - t1)/1e6 | ||
| } | ||
| println(s"===============[$name]=================") | ||
| candidates foreach (c => | ||
| println(f"${c.getClass.getSimpleName}%12s: ${profile(c)}%8.2f ms") | ||
| ) | ||
| candidates.sliding(2) foreach {case Seq(a, b) => | ||
| assert(a == b, s"Operations are not same [$name] for ${a.getClass.getName} and ${b.getClass.getName}") | ||
| } | ||
| } | ||
|
|
||
| val range10m = (1 to 1e7.toInt).toArray | ||
|
|
||
| benchmark("Insert lots of items", _ ++= range10m) | ||
| benchmark("Drop some items from an head index", _.remove(5, 10000)) | ||
| benchmark("Drop some items from a tail index", b => b.remove(b.length - 10000, 10000)) | ||
| benchmark("Append lots of items one by one", b => range10m.foreach(b.+=)) | ||
| benchmark("Prepend few items one by one", b => (1 to 1000).foreach(_ +=: b)) | ||
| benchmark("Prepend lots of items at once", range10m ++=: _) | ||
| benchmark("Insert items near head", _.insertAll(1000, range10m)) | ||
| benchmark("Reversal", _.reverse) | ||
| benchmark("Insert items near tail", b => b.insertAll(b.size - 1000, range10m)) | ||
| benchmark("Sliding", _.sliding(size = 1000, step = 1000).size) | ||
| benchmark("Random indexing", b => range10m.foreach(i => if (b.isDefinedAt(i)) b(i))) | ||
| benchmark("toArray", _.toArray) | ||
| benchmark("Clear lots of items", _.clear()) | ||
| } | ||
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
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.
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 agree that your code is more readable than JMH things but we should use JMH… Could you migrate your benchmark to JMH? You can just copy-paste another benchmark (e.g. the one for
ArrayBuffer) and change a few things to make it useArrayDeque.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 can keep both for now..