On Sun, Aug 16, 2009 at 1:30 AM, botgerry <botge...@gmail.com> wrote:

>
> Hello,all
>
> new to functional programming, I have one nested dynamic vecter just
> like this:
>
> (def a [[1 2 3 4] ["ok" 89 22] [25 78 99] ...]]
>
> it has to support ops:
> 1*   add new item,it's easy: eg. (conj   a  ["metoo" "oops"] )
> 2*  insert one element  into inner vector based that vector's
> content,eg  i have to append 50 in inner vectors which includes 99.
> the result  is [[1 2 3 4] ["ok 89 22] [25 78 99 50]...]
> 3*  merge inner vectors in a , eg. if there are same elements in
> inner vectors , they should be merged and delete same elements.
>  [[1 2 3 4] [ "ok" 89 22] [ 5 6 7 2 ]...] -> [[1 2 3 4 5 6 7] ["ok" 89
> 22]]


If you are implementing a disjoint set forest, it might be better to use a
map from values to sets, where the lookup-set-given-value operation is a
simple map lookup, adding a new one-element set is just (assoc map object
#{object}), and merging two sets is almost as simple:

(let [new-set (into set-1 set-2)]
  (reduce #(assoc %1 %2 new-set) map new-set))

evaluates to the new forest map.

--~--~---------~--~----~------------~-------~--~----~
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