On Sat, Mar 21, 2009 at 12:23 PM, mikel <mev...@mac.com> wrote: > > I haven't looked at Clojure at all with this in mind, but I know I'm > soon going to need to implement this updating mechanism. If you know > how to efficiently obtain just the diffrences between two otherwise > shared Maps, I'd be interested to learn how to do it.
This is interesting to me. I've thought for a while that I wanted to be notified of changes to a collection, such as in a Ref's watcher. But I couldn't think of a good way to go about it, since the new value of a Ref may have no relationship at all with the old value. But your question suggests a different approach. Efficiently obtaining a "diff" that describes the differences between two collections would suffice for most of my use cases.o The collections don't support this now, as far as I know, but off the top of my head it seems like it would be possible for any collection instance to walk itself at the same time as another instance of the exact same type, following only nodes that are not identical references. This wouldn't work to compare an array-map with a hash-map, for example, but in an ideal case of two hash-maps with a single changed entry, it seems like it could be very efficient. Perhaps O(n) where n is the number of changed leaf nodes? I'm not sure what the resulting "diff" would look like. It would be nice if it were simple another hash-map: (diff a b) would return a map c such that (merge a c) would produce a value equal to b again. But for course this can't be as 'merge' never removes an entry. An option that would work (but doesn't strike me as terribly elegant) would be for (diff a b) to return [c d], such that: (= b (merge (apply dissoc a c) d)) --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---