Improvement in IndexedSeq "last" operation

32 views
Skip to first unread message

Wilson de Carvalho

unread,
Oct 19, 2016, 8:50:17 AM10/19/16
to scala-sips
Hello,

I hope this is the right list for this issue:

I'd like to make an improvement in IndexedSeq derived traits. "last" operation performance is currently linear, since its implementation is inherited from TraversableLike, but it could be constant due to the nature of this type of collection. Since I'm a begginner here, I'd like to know if there is any reason why this was not implemented (besides it was forgotten).

Regards.

Hanns Holger Rutz

unread,
Oct 19, 2016, 9:12:10 AM10/19/16
to scala...@googlegroups.com
It would be great if this could be fixed. It is overridden in Vector,
though:

override /*TraversableLike*/ def last: A = {
if (isEmpty) throw new UnsupportedOperationException("empty.last")
apply(length-1)
}

I don't know if there is a reason why this is not in `IndexedSeq` instead.

best, .h.h.
> --
> You received this message because you are subscribed to the Google
> Groups "scala-sips" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scala-sips+...@googlegroups.com
> <mailto:scala-sips+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


signature.asc

martin odersky

unread,
Oct 19, 2016, 9:34:09 AM10/19/16
to scala...@googlegroups.com
It's overridden in IndexedSeqOptimized. IndexedSeq generally does not guarantee fast random access, but IndexedSeqOptimized does.

 - Martin



On Wed, Oct 19, 2016 at 3:11 PM, Hanns Holger Rutz <con...@sciss.de> wrote:
It would be great if this could be fixed. It is overridden in Vector,
though:

  override /*TraversableLike*/ def last: A = {
    if (isEmpty) throw new UnsupportedOperationException("empty.last")
    apply(length-1)
  }

I don't know if there is a reason why this is not in `IndexedSeq` instead.

best, .h.h.



On 19/10/16 14:50, Wilson de Carvalho wrote:
> Hello,
>
> I hope this is the right list for this issue:
>
> I'd like to make an improvement in IndexedSeq derived traits. "last"
> operation performance is currently linear, since its implementation is
> inherited from TraversableLike, but it could be constant due to the
> nature of this type of collection. Since I'm a begginner here, I'd like
> to know if there is any reason why this was not implemented (besides it
> was forgotten).
>
> Regards.
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-sips" group.
> To unsubscribe from this group and stop receiving emails from it, send
> For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "scala-sips" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-sips+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Martin Odersky
EPFL and Lightbend
Reply all
Reply to author
Forward
0 new messages