Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!aioe.org!.POSTED!not-for-mail From: Cthun Newsgroups: comp.lang.java.programmer Subject: Re: Immutable Datastructures with good Sharing Date: Mon, 07 Nov 2011 12:54:54 -0500 Organization: Ph'nglui mglw'nfah Cthulhu R'lyeh wgah'nagl fhtagn Lines: 26 Message-ID: References: <4eb7e76f$0$6972$e4fe514c@news2.news.xs4all.nl> NNTP-Posting-Host: PeK9C/JchrWuRhsTrIEaEA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (CYGWIN_NT-6.0/1.5.22(0.156/4/2) (i686)) Hamster/2.0.2.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9749 On 07/11/2011 9:13 AM, Silvio Bierman wrote: > Perhaps looking into the standard libraries of Scala or Clojure would be > a good idea. Both provide immutable lists, trees, vectors, hashmaps etc. Clojure's can be used from in Java by importing clojure.lang classes and having the Clojure jar in the classpath. No generics, but they implement the unmodifiable-foo portions of the Map, Set, List, etc. interfaces from java.util and have their own return-a-modified-version methods. There's a persistent immutable stack class included. I'm not sure if clojure.lang has a persistent immutable queue, or if it does if it's a deque, but someone posted code for a queue on their mailing list a year or so ago. I'm not sure who or exactly when, but a search for "persistent queue" will probably turn it up. I think it was a full deque with pushes, peeks, and pops at both ends stated to be O(1). It used deftype/defprotocol which, if I understand them correctly, generates named Java classes and interfaces that can be imported into and used from Java if the Clojure code is AOT-compiled to generate .class files. I don't know what, if any, license the author specified though. I also recall seeing a priority queue implementation posted there at some point. Of course, you might want to take the larger step of actually using Clojure if persistence and immutability are things you crave. ;)