From 74c1ebb852d373fe7202a0b641696ee66a7c2fc9 Mon Sep 17 00:00:00 2001 From: Ian O Connell Date: Fri, 31 Jul 2015 16:39:01 -0700 Subject: [PATCH] Re-order the private constructor so that its signature looks different erased than the old constructor. Add the old constructor as an overloaded constructor so that we can keep our binary compatibility to a minimum We now are just missing copy constructors: [error] * synthetic method copy$default$6()scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$6") [error] * synthetic method com$twitter$algebird$QTree$$findRankUpperBound(Long)scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.com$twitter$algebird$QTree$$findRankUpperBound") [error] * synthetic method copy$default$2()Int in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$2") [error] * synthetic method copy$default$5()scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$5") [error] * synthetic method com$twitter$algebird$QTree$$findRankLowerBound(Long)scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.com$twitter$algebird$QTree$$findRankLowerBound") [error] * method copy(Long,Int,Long,java.lang.Object,scala.Option,scala.Option)com.twitter.algebird.QTree in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy") [error] * synthetic method copy$default$1()Long in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$1") [error] * synthetic method copy$default$4()java.lang.Object in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$4") [error] * synthetic method copy$default$3()Long in class com.twitter.algebird.QTree does not have a correspondent in new version [error] filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$3") java.lang.RuntimeException: algebird-core: Binary compatibility check failed! Do we mind that? --- .../scala/com/twitter/algebird/QTree.scala | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/algebird-core/src/main/scala/com/twitter/algebird/QTree.scala b/algebird-core/src/main/scala/com/twitter/algebird/QTree.scala index 657e311ff..ec927ba26 100644 --- a/algebird-core/src/main/scala/com/twitter/algebird/QTree.scala +++ b/algebird-core/src/main/scala/com/twitter/algebird/QTree.scala @@ -46,10 +46,10 @@ object QTree { val offset = math.floor(kv._1 / math.pow(2.0, level)).toLong require(offset >= 0, "QTree can not accept negative values") - new QTree(offset, + new QTree(kv._2, + offset, level, 1, - kv._2, null, null) } @@ -57,10 +57,10 @@ object QTree { def apply[A](kv: (Long, A)): QTree[A] = { require(kv._1 >= 0, "QTree can not accept negative values") - new QTree(kv._1, + new QTree(kv._2, + kv._1, 0, 1, - kv._2, null, null) } @@ -73,7 +73,7 @@ object QTree { upperChild: Option[QTree[A]]): QTree[A] = { require(offset >= 0, "QTree can not accept negative values") - new QTree(offset, level, count, sum, lowerChild.orNull, upperChild.orNull) + new QTree(sum, offset, level, count, lowerChild.orNull, upperChild.orNull) } /** @@ -113,9 +113,9 @@ object QTree { assert(right.lowerBound == left.lowerBound, "lowerBound " + right.lowerBound + " != " + left.lowerBound) assert(right.level == left.level, "level " + right.level + " != " + left.level) - new QTree[A](left.offset, + new QTree[A](monoid.plus(left.sum, right.sum), + left.offset, left.level, left.count + right.count, - monoid.plus(left.sum, right.sum), mergeOptions(left.lowerChildNullable, right.lowerChildNullable), mergeOptions(left.upperChildNullable, right.upperChildNullable)) } @@ -157,13 +157,13 @@ class QTreeSemigroup[A](k: Int)(implicit val underlyingMonoid: Monoid[A]) extend } class QTree[@specialized(Int, Long, Float, Double) A] private[algebird] ( + _sum: A, //the sum at just this node (*not* including its children) _offset: Long, //the range this tree covers is offset*(2^level) ... (offset+1)*(2^level) _level: Int, _count: Long, //the total count for this node and all of its children - _sum: A, //the sum at just this node (*not* including its children) _lowerChildNullable: QTree[A], _upperChildNullable: QTree[A]) - extends scala.Product6[Long, Int, Long, A, Option[QTree[A]], Option[QTree[A]]] with java.io.Serializable { + extends scala.Product6[Long, Int, Long, A, Option[QTree[A]], Option[QTree[A]]] with Serializable { import QTree._ val range: Double = @@ -178,6 +178,9 @@ class QTree[@specialized(Int, Long, Float, Double) A] private[algebird] ( def lowerChild: Option[QTree[A]] = Option(_lowerChildNullable) def upperChild: Option[QTree[A]] = Option(_upperChildNullable) + def this(offset: Long, level: Int, count: Long, sum: A, lowerChild: Option[QTree[A]], upperChild: Option[QTree[A]]) = + this(sum, offset, level, count, lowerChild.orNull, upperChild.orNull) + // Helpers to access the nullable ones from inside the QTree work @inline private[algebird] def lowerChildNullable: QTree[A] = _lowerChildNullable @inline private[algebird] def upperChildNullable: QTree[A] = _upperChildNullable @@ -218,7 +221,7 @@ class QTree[@specialized(Int, Long, Float, Double) A] private[algebird] ( val r = if (offset % 2 == 0) null else this val parent = - new QTree[A](nextOffset, nextLevel, _count, monoid.zero, l, r) + new QTree[A](monoid.zero, nextOffset, nextLevel, _count, l, r) parent.extendToLevel(n) } @@ -367,7 +370,7 @@ class QTree[@specialized(Int, Long, Float, Double) A] private[algebird] ( // If we don't prune we MUST return this private def pruneChildren(minCount: Long)(implicit m: Monoid[A]): QTree[A] = if (_count < minCount) { - new QTree[A](_offset, _level, _count, totalSum, null, null) + new QTree[A](totalSum, _offset, _level, _count, null, null) } else { val newLower = pruneChild(minCount, lowerChildNullable) val lowerNotPruned = newLower eq lowerChildNullable @@ -376,7 +379,7 @@ class QTree[@specialized(Int, Long, Float, Double) A] private[algebird] ( if (lowerNotPruned && upperNotPruned) this else - new QTree[A](_offset, _level, _count, _sum, newLower, newUpper) + new QTree[A](_sum, _offset, _level, _count, newLower, newUpper) } // If we don't prune we MUST return child