scala-rrb-vector icon indicating copy to clipboard operation
scala-rrb-vector copied to clipboard

Exception when building vector via concatenation

Open arximboldi opened this issue 8 years ago • 1 comments

Hi!

I am doing some benchmarking over various RRB vector implementations. I am trying to build an RRBVector that is very relaxed. For that, I am trying to build it by concatenating elements at the front. This is the function I wrote to build such vector:

  def relaxedV(v : RRBVector[Int], n : Int) : RRBVector[Int] = {
    var r = v
    for (i <- 0 to n) {
      r = (RRBVector.empty[Int] :+ i) ++ r
    }
    r
  }

I am when trying to build a 100000 element vector with:

relaxedV(RRBVector.empty[Int], 100000)

I get the following error:

Test threw exception: scala.MatchError: 7 (of class java.lang.Integer)
scala.MatchError: 7 (of class java.lang.Integer)
	at scala.collection.immutable.rrbvector.RRBVectorPointer$class.initFromRoot(RRBVector.scala:1698)
	at scala.collection.immutable.rrbvector.RRBVector.initFromRoot(RRBVector.scala:53)
	at scala.collection.immutable.rrbvector.RRBVector.concatenate(RRBVector.scala:735)
	at scala.collection.immutable.rrbvector.RRBVector.$plus$plus(RRBVector.scala:508)

I do not usually write Scala, so maybe it is my fault?

arximboldi avatar Feb 24 '17 16:02 arximboldi

This is clearly a bug.

I do not remember all the details on the bounds of the RRB vector, but it might be missing one level of depth for the vector (the depth is explicitly bounded). Or, while rebalancing it is generating an additional temporary level before rebalancing which is not accounted for there.

nicolasstucki avatar Feb 27 '17 09:02 nicolasstucki