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

exception when prepending

Open wishfoundry opened this issue 7 years ago • 2 comments

Hi,

I'm trying to step through a test I'm writing, but it seems the issue might be in RRBVector

In the simplest case I can reproduce with:

import org.scalatest._
import scala.collection.immutable.rrbvector._

class MyTest extends FlatSpec {

  "A Vector" should "prepend in a range up to 2048 items" in {
    var vec = RRBVector.empty[Int]

    for (i <- 0 to 2048)
    {
      vec =  i +: vec
    }

    for (i <- 0 to 2048) 
    {
      assert(vec(i).equals(i))
    }
  }
}

I get the following error:

java.lang.NullPointerException was thrown.
java.lang.NullPointerException
	at scala.collection.immutable.rrbvector.RRBVectorPointer$class.treeSizeRec$1(RRBVector.scala:2936)
	at scala.collection.immutable.rrbvector.RRBVectorPointer$class.treeSize(RRBVector.scala:2947)
	at scala.collection.immutable.rrbvector.RRBVectorPointer$class.withRecomputeSizes(RRBVector.scala:2858)
	at scala.collection.immutable.rrbvector.RRBVector.withRecomputeSizes(RRBVector.scala:53)
	at scala.collection.immutable.rrbvector.RRBVectorPointer$class.setupNewBlockInInitBranch(RRBVector.scala:2146)
	at scala.collection.immutable.rrbvector.RRBVector.setupNewBlockInInitBranch(RRBVector.scala:53)
	at scala.collection.immutable.rrbvector.RRBVector.prependFrontNewBlock(RRBVector.scala:381)
	at scala.collection.immutable.rrbvector.RRBVector.prepend(RRBVector.scala:324)
	at scala.collection.immutable.rrbvector.RRBVector.$plus$colon(RRBVector.scala:306)

wishfoundry avatar Mar 07 '17 16:03 wishfoundry

I think the problem is with the sizes (relaxed indices?) here since we're prepending we can't reuse the existing cache, and must always rebuild it

wishfoundry avatar Apr 03 '17 18:04 wishfoundry

It might be. I will need some time to debug this one. Thanks for the input.

nicolasstucki avatar Apr 04 '17 08:04 nicolasstucki