If the thing you want to index by is not unique, you could do...
something like:

(def m (atom (sorted-map)))
(def rm (atom (sorted-map)))

(defn add
  [k v]
  (swap! m assoc k v)
  (swap! rm assoc v (conj (get @rm v []) k)))

(add 1 "bbb")
(add 2 "ccc")
(add 3 "aaa")
(add 4 "aaa")

; @rm is now {"aaa" [3 4], "bbb" [1], "ccc" [2]}

This seems simpler to code than a sorted vector index, but would
require more memory. However you can quickly lookup by key or by index
or by range.


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