What does structural sharing means in List?

650 views
Skip to first unread message

Harit Himanshu

unread,
Jun 7, 2015, 5:38:30 PM6/7/15
to scala...@googlegroups.com
I was reading List API and saw the following statement

Space: List implements structural sharing of the tail list. This means that many operations are either zero- or constant-memory cost.


So, what is the meaning of structural sharing? I did not understand meaning of this line at all

Thank you

Som Snytt

unread,
Jun 7, 2015, 6:48:50 PM6/7/15
to Harit Himanshu, scala-user
Sharing a data structure instead of making a defensive copy.

The old saying is that "two can live cheaper than one."

Anyone who has shared an apartment knows this is not easy.

Example peril: https://issues.scala-lang.org/browse/SI-8976


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

Chandu Kavar

unread,
Jun 10, 2015, 4:04:12 AM6/10/15
to scala...@googlegroups.com
Hi Himanshu,

Suppose we have one list:  val  list = List(1,2,3) and we want to create a list of four elements 1 to 4. Then you can use the concept of structural sharing. what that means,
you can create list like:

val list2 = Cons(4,list)

Here, list shared his structure with list2. we can reduce the cost of creating list2 using structural sharing.

Harit Himanshu

unread,
Jun 14, 2015, 1:38:03 AM6/14/15
to Chandu Kavar, scala-user
Interesting, thanks a lot

--
You received this message because you are subscribed to a topic in the Google Groups "scala-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-user/xWmGlUc2F0U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages