Guest User

Untitled

a guest
Jun 17th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. Scala unexpected stack overflow
  2. import scala.collection.mutable.HashMap
  3.  
  4. object HelloWorld {
  5.  
  6. val treasureMap = new HashMap[BigInt, BigInt]
  7.  
  8. def main(args: Array[String]) {
  9. println(fibCache(10))
  10. }
  11.  
  12. def fibCache(n: BigInt): BigInt = {
  13. if (n == 0 || n == 1) {
  14. return n
  15. }
  16. return treasureMap.getOrElseUpdate(n, fibCache(n - 1) + fibCache(n - 2))
  17. }
  18. }
  19.  
  20. Exception in thread "main" java.lang.StackOverflowError
  21. at java.math.BigInteger.compareMagnitude(Unknown Source)
  22. at java.math.BigInteger.compareTo(Unknown Source)
  23. at scala.math.BigInt.compare(BigInt.scala:141)
  24. at scala.math.BigInt.$less$eq(BigInt.scala:145)
  25. at scala.math.BigInt.fitsInLong(BigInt.scala:130)
  26. at scala.math.BigInt.hashCode(BigInt.scala:120)
  27. at scala.runtime.BoxesRunTime.hashFromNumber(Unknown Source)
  28. at scala.collection.mutable.HashTable$HashUtils$class.elemHashCode(HashTable.scala:366)
  29. at scala.collection.mutable.HashMap.elemHashCode(HashMap.scala:43)
  30. at scala.collection.mutable.HashTable$class.findEntry(HashTable.scala:108)
  31. at scala.collection.mutable.HashMap.findEntry(HashMap.scala:43)
  32. at scala.collection.mutable.HashMap.get(HashMap.scala:63)
  33. at scala.collection.mutable.MapLike$class.getOrElseUpdate(MapLike.scala:186)
  34. at scala.collection.mutable.HashMap.getOrElseUpdate(HashMap.scala:43)
Advertisement
Add Comment
Please, Sign In to add comment