Re: removing a hash-map from a set using hash-map's field.

2012-03-25 Thread Philip Potter
On 23 March 2012 14:47, Leandro Oliveira wrote: > Thank you for all replies. > > Can I say that if you need remove an item you should use a map? It depends entirely on how you intend to look up your values. If your lookup is by the entire value, then sets make sense. If it's by only part of a val

Re: removing a hash-map from a set using hash-map's field.

2012-03-23 Thread Andy Fingerhut
Sets are good when you have a collection of things, the precise order isn't important to you, and you want to avoid duplicates. I used one in some code recently where I wanted to maintain a collection of people who were co-authors in a Clojure patch, and the input file I started with could ment

Re: removing a hash-map from a set using hash-map's field.

2012-03-23 Thread Leandro Oliveira
Thank you for all replies. The reason that I was using set instead of map was to use the functions from closure.set. I like them. But now I agree that map is a better approach. (select (fn [{:keys [id]}] (not= id 1)) xrel) is O(n). Right? Can I say that if you need remove an item you should use

Re: removing a hash-map from a set using hash-map's field.

2012-03-23 Thread Jay Fields
Disclaimer, I'm only looking at how I would want to write it. You may need to do something else if you have specific performance requirements. clojure.set is probably your friend. user=> (def xrel #{{:id 1, :foo "bar"} {:id 2, :foo "car"} {:id 3, :foo "dog"}}) #'user/xrel user=> (use 'clojure.set

Re: removing a hash-map from a set using hash-map's field.

2012-03-22 Thread Philip Potter
Might it be possible to use a map instead? Maps are designed to look values up by a key which may differ from the value, which seems to be your use case here. If you have {1 {:id 1, :foo "bar"}, 2 {:id 2, :foo "car"}} You can just do (disj my-map 2) To convert the original set into a map, you

Re: removing a hash-map from a set using hash-map's field.

2012-03-22 Thread Cedric Greevey
On Thu, Mar 22, 2012 at 10:32 PM, Cedric Greevey wrote: (into #{} (remove #(= (:id %) foo) input-set)) > You could stop when :id foo got hit by using a loop/recur, and save half the > iterations on average. Clarification: stop comparing to match the :id key against the target. You'd have to con

Re: removing a hash-map from a set using hash-map's field.

2012-03-22 Thread Cedric Greevey
On Wed, Mar 21, 2012 at 5:00 PM, Leandro Oliveira wrote: > Hi all, > > I have a set of hash like this: > > #{{:id 1, :foo "bar"} {:id 2, :foo "car"}} > > and I'd like to remove an item based on its id value. > > Unfortunately, disj requires that I pass the whole map as key to remove it. > > Can I