Skip to content
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

Fix serialization of MutablePair. Also provide an interface for easy updating. #141

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion core/src/main/scala/org/apache/spark/util/MutablePair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ package org.apache.spark.util
* @param _2 Element 2 of this MutablePair
*/
case class MutablePair[@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T1,
@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T2]
@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T2]
(var _1: T1, var _2: T2)
extends Product2[T1, T2]
{
/** No-arg constructor for serialization */
def this() = this(null.asInstanceOf[T1], null.asInstanceOf[T2])

/** Updates this pair with new values and returns itself */
def update(n1: T1, n2: T2): MutablePair[T1, T2] = {
_1 = n1
_2 = n2
this
}

override def toString = "(" + _1 + "," + _2 + ")"

override def canEqual(that: Any): Boolean = that.isInstanceOf[MutablePair[_,_]]
Expand Down