forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out strict implementations of transformation operations.
Add StrictOptimizedMapOps and StrictOptimizedSortedMapOps. Only operations that were implemented more than once have been factored out. Some other operations could be factored out so that they could be reused by custom collection implementations. Fixes scala/collection-strawman#325
- Loading branch information
Showing
19 changed files
with
219 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,29 @@ | ||
package scala.collection | ||
|
||
import scala.language.higherKinds | ||
|
||
/** | ||
* Trait that overrides map operations to take advantage of strict builders. | ||
* | ||
* @tparam K Type of keys | ||
* @tparam V Type of values | ||
* @tparam CC Collection type constructor | ||
* @tparam C Collection type | ||
*/ | ||
trait StrictOptimizedMapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C] | ||
extends MapOps[K, V, CC, C] | ||
with StrictOptimizedIterableOps[(K, V), Iterable, C] { | ||
|
||
override def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2, V2] = | ||
strictOptimizedMap(mapFactory.newBuilder, f) | ||
|
||
override def flatMap[K2, V2](f: ((K, V)) => IterableOnce[(K2, V2)]): CC[K2, V2] = | ||
strictOptimizedFlatMap(mapFactory.newBuilder, f) | ||
|
||
override def concat[V2 >: V](suffix: Iterable[(K, V2)]): CC[K, V2] = | ||
strictOptimizedConcat(suffix, mapFactory.newBuilder) | ||
|
||
override def collect[K2, V2](pf: PartialFunction[(K, V), (K2, V2)]): CC[K2, V2] = | ||
strictOptimizedCollect(mapFactory.newBuilder, pf) | ||
|
||
} |
This file contains 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 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,17 @@ | ||
package scala.collection | ||
|
||
/** | ||
* Trait that overrides set operations to take advantage of strict builders. | ||
* | ||
* @tparam A Elements type | ||
* @tparam CC Collection type constructor | ||
* @tparam C Collection type | ||
*/ | ||
trait StrictOptimizedSetOps[A, +CC[_], +C <: SetOps[A, CC, C]] | ||
extends SetOps[A, CC, C] | ||
with StrictOptimizedIterableOps[A, CC, C] { | ||
|
||
override def concat(that: Iterable[A]): C = | ||
strictOptimizedConcat(that, newSpecificBuilder) | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/library/scala/collection/StrictOptimizedSortedMapOps.scala
This file contains 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,29 @@ | ||
package scala.collection | ||
|
||
import scala.annotation.implicitNotFound | ||
|
||
/** | ||
* Trait that overrides sorted map operations to take advantage of strict builders. | ||
* | ||
* @tparam K Type of keys | ||
* @tparam V Type of values | ||
* @tparam CC Collection type constructor | ||
* @tparam C Collection type | ||
*/ | ||
trait StrictOptimizedSortedMapOps[K, +V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC, _], +C <: SortedMapOps[K, V, CC, C]] | ||
extends SortedMapOps[K, V, CC, C] | ||
with StrictOptimizedMapOps[K, V, Map, C] { | ||
|
||
override def map[K2, V2](f: ((K, V)) => (K2, V2))(implicit @implicitNotFound(SortedMapOps.ordMsg) ordering: Ordering[K2]): CC[K2, V2] = | ||
strictOptimizedMap(sortedMapFactory.newBuilder, f) | ||
|
||
override def flatMap[K2, V2](f: ((K, V)) => IterableOnce[(K2, V2)])(implicit @implicitNotFound(SortedMapOps.ordMsg) ordering: Ordering[K2]): CC[K2, V2] = | ||
strictOptimizedFlatMap(sortedMapFactory.newBuilder, f) | ||
|
||
override def concat[V2 >: V](xs: Iterable[(K, V2)]): CC[K, V2] = | ||
strictOptimizedConcat(xs, sortedMapFactory.newBuilder) | ||
|
||
override def collect[K2, V2](pf: PartialFunction[(K, V), (K2, V2)])(implicit @implicitNotFound(SortedMapOps.ordMsg) ordering: Ordering[K2]): CC[K2, V2] = | ||
strictOptimizedCollect(sortedMapFactory.newBuilder, pf) | ||
|
||
} |
This file contains 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 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 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.