3 ms·
How do you intend to "update" an immutable list? Isn't it... immutable?
by nknight 14y ago
How do you intend to "update" an immutable list? Isn't it... immutable?
- snprbob86 14y agoAs a pure function where the returned value utilizes structural sharing with the input values.
- swannodette 14y agohttp://en.wikipedia.org/wiki/Persistent_data_structure http://en.wikipedia.org/wiki/Persistent_data_structure
- lihaoyi 14y agoImmutable lists can be preppended/popped in O(1)time, without affecting previous versions. Immutable dicts can have stuff added and removed in O(log n) time, without affecting previous versions. Scala's immutable vectors can have appending/prepending/concatenation/splitting/insertion/deletion in O(log n) time, without affecting previous versions. it's log base 32, so for any arrays using integer indexes, it'll never go above ~7, so it's basically constant. Basically, you get (almost) the performance of mutable data structures, except you don't mess up the old versions of the thing every time you change something. It's really pretty incredible, the performance characteristics people manage to get with structural sharing: http://www.scala-lang.org/docu/files/collections-api/collections_40.html http://www.scala-lang.org/docu/files/collections-api/collect...
- soc88 14y agoThe Scala stuff is impressive. Updated docs at the new site: http://docs.scala-lang.org/overviews/collections/performance-characteristics.html http://docs.scala-lang.org/overviews/collections/performance... The new ConcurrentTrie is also a great addition to 2.10.
- sureshv 14y agoThere's still a lookup hit of log-b32n versus contiguous memory immutable vector with O(1). Locality can also an issue with tree-like structures but muted with the large branch factor. Of course the flip side scala gives you the kitchen sink for persistance.