Immutable / persistent list in Java?

You can create a head::tail like list, and get the benefits of easy creation and good memory footprint, and then provide an API that layers a skip list on top to get efficient random access when needed.

You can create a head::tail like list, and get the benefits of easy creation and good memory footprint, and then provide an API that layers a skip list on top to get efficient random access when needed. As far as efficient mutation in middle, the skip list view might have a side table mapping mutated indices to elements, and a binary searchable array mapping original index to index offsets after inserts and removes. All this mapping raises the question of how to provide efficient immutable maps for some definition of efficient.

The best way I've come up with is to use be trees which allow for O(log n) access to sortable keys, and O(log n) node creation on insertion and removal. The number of nodes shared between two holders of a b-tree based map after k modifications are approx. (n - k log n) which is pretty good in practice for infrequently updated maps.

Immutable list means you cannot modify lists items after it is created. So you are abusing the notation. What you want to do is: have a mutable list and return its immutable view.

Google Guava can return immutable view for you. ImmutableList view = ImmutableList. CopyOf(mutableList); You can make multiple updates to your mutableList before you ask for a new view, if you want to minimize copies as much as possible.

For all intents and purposes it is immutable to the outside world even if the internal implementation itself is mutable, yes. But somewhere you do have to start mutating state. – Philip K Jul 30 at 19:16 This still will copy the whole list (e.g. Needs O(size) operations).

– PaÅ­lo Ebermann Jul 30 at 19:18 If you don't want to copy it, use Collections. UnmodifiableList. – Clark Gaebel Jul 30 at 22:29 @Clark Gaebel: this doesn't solve anything.

– Philip K Jul 300 at 8:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions