Hi Ken,

Having a mutable stm-map would be awesome. I actually had to implement one
for my project at work. Sorry can't publish it due to licensing issues, but
anyway my implementation is dead simple and won't perform well on big data
sets. I was trying to understand how to implement detection of new/removed
keys with current Clojure's STM, and could find a solution. As you
mentioned, second issue is merging of changes to the same map from two
different transactions.

I know that there is a transactional map somewhere inside Clojure that is
based on references, but its partitioning is too coarse and doesn't depend
on the data set.

I would love to implement stm-map, but I couldn't find a data structure that
would give good performance and small memory usage. I would appreciate if
you could point me to relevant documentation or research.

Cheers,
Ivan.


On 25 June 2011 22:33, Ken Wesson <kwess...@gmail.com> wrote:

> On Sat, Jun 25, 2011 at 4:18 PM, Laurent PETIT <laurent.pe...@gmail.com>
> wrote:
> > Beware the devil hidden in the details:
> > "
> > Note that an array map will only maintain sort order when
> > un-'modified'. Subsequent assoc-ing will eventually cause it to
> > 'become' a hash-map.
> > "
>
> Besides a LinkedHashMap-alike, Clojure could probably use at least
> these other map variations:
>
> * WeakHashMap (keys weakly bound)
> * Map with weak values (useful for caching)
> * ConcurrentHashMap
>
> and possibly combinations of the above. Even Java seems to lack
> weak-value maps; you can fudge it though by putting a
> WeakReference(val) in in a wrapper layer and using a ReferenceQueue
> and a thread that drains the queue every so often to prune dead
> Map.Entries from the map.
>
> Note that a map of refs doesn't cut it as a substitute for a
> ConcurrentHashMap if keys will be added/removed by multiple threads,
> and sticking the entire map in an atom doesn't if you want to support
> more concurrency than a plain old Collections.synchronizedMap.
> Sticking the entire map in a ref and using commute doesn't quite work,
> if two concurrent assoces of the same key should force a retry, and
> sticking the entire map in a ref and using alter allows no more
> concurrency than synchronizedMap.
>
> We really could use an STM-map that supports normal Clojure map get
> semantics, but not assoc or dissoc, and supports alter-key and
> remove-key which have to be called in a transaction and act like
> commuted assoc and dissoc except that one transaction retries if there
> are concurrent attempts to change the *same* key.
>
> Perhaps we should also have a way to simply specify, separately and
> combinably, in both stm-map and hash-map, options to make the keys
> weak, the values weak, or the seq/keys/vals views use the insertion
> order. With both weakable keys and weakable vals you can also throw in
> a weak-hash-set which can be used to "intern" or "canonicalize" any
> desired immutable objects, without packratting them and eventually
> blowing the heap, and is implemented under the hood as a weak-keyed,
> weak-valued map of objects to themselves.
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
>
> --
> 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

Reply via email to