To my knowledge, there are no built-in data structures that are mutable and that use the same access functions.
There are built-in data structures called transients that are mutable, and use almost the same hash functions. Read the docs on transient, persistent!, conj!, etc. Transient data structures are restricted to be modified from a single thread, to avoid concurrency issues. Any attempt to modify a transient data structure from multiple threads is detected as an error at run time. Note that even the immutable data structures do not make a copy of the entire data structure. If the data structure is large, most of the data is shared between the old and new data structure. See the tree example on this Wikipedia page for a small example, but I know I've seen elsewhere pictures of examples closer to Clojure's persistent data structure implementations: http://en.wikipedia.org/wiki/Persistent_data_structure Your scenario: "What if I have a hash-map that needs to handle concurrent changes to the data structure, but never needs to have concurrent changes to a given piece of data (i.e. a key/value pair)." My question: How do you know, in advance, that it doesn't need to handle such concurrent changes? If it is because you have multiple threads that will always modify disjoint subsets of the keys, then you could have a separate hash-map for each of those sets of keys (perhaps a transient), and modify each one from its own thread. Readers of the hash map would then have to search for keys in multiple tables, or if it was easy to calculate in advance which table the key must be in, then only one table lookup is sufficient. Andy On Tue, Sep 13, 2011 at 4:00 PM, Trevor <tcr1...@gmail.com> wrote: > For the most part, I *believe* I understand why immutable data > structures with transactions are important to manage concurrent > operations to shared data, but I often wonder why it matters in some > cases... > > For example, what if I have a hash-map that needs to handle concurrent > changes to the data structure, but never needs to have concurrent > changes to a given piece of data (i.e a key/value pair). Wouldn't > there be value in being able to modify the data "in-place" without > making a copy, or needing to endure the overhead associated with STM? > > And if what I am suggesting is reasonable how can I create a mutable > hash-map in Clojure and still use (mostly) the same access functions. > > Notes: > * Yes, I have watched Rich's video on identity and state, but it > hasn't helped my understand the above scenario. > * I am not suggesting a hash-map data structure should support mixed > operations. > > Thanks, > Trevor > > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en