>From a mathematical perspective the essential aspect of a set is its 
>extension, namely what elements are contained in the set. This leads 
>immediately to the property of uniqueness you mentioned. But the fundamental 
>operation is 'contains?'. In other words, does the set contain some object or 
>not? 

In order to search a vector to answer this question we have to perform a linear 
search. Thus, the longer the vector, the longer this search could take. In 
Clojure, sets are ultimately constructed out of hash tables, which allows a 
constant time check to see whether an object is a key and therefore a member of 
the set. The fact that the keys in a hash table are unique is a useful side 
benefit, but I believe that an efficient 'contains?' method is the main reason 
for their choice.

All of the other set operations (union, intersection, etc...) are derived from 
our ability to determine whether or not an element is present in some set.

In case you haven't found it yet, there is a section on Sets on the data 
structures page:
http://clojure.org/data_structures
Note especially that you have a choice between hash-set and sorted-set.

Also check out the documentation for clojure.set:
http://clojure.github.com/clojure/clojure.set-api.html

Have all good days,
David Sletten



On Oct 31, 2010, at 10:55 PM, tonyl wrote:

> I guess I should've look harder (and ask more in the irc ;) it is a
> data structure and has a set fn too. #{} is just a reader macro for
> syntactic sugar. And the difference of usage between sets and vectors
> are they sets can't have duplicates.
> This is great, clojure group with irc chat, good learning.
> 
> On Oct 31, 9:35 pm, tonyl <celtich...@gmail.com> wrote:
>> I've been wondering if sets are actually a defined data structure like
>> vectors and maps or are they a result of an expansion of the dispatch
>> macro? I was wondering since it uses the dispatch macro and AFAIK
>> there is no api fn to create them like hash-maps to create maps,
>> vector/vec for vectors, or list for lists.
>> 
>> Another thing I am trying to figure out is, are they really needed?
>> vectors seem to fill in anytime sets could be used, unless I am
>> missing something here.
>> 
>> Any information would be appreciated.
> 
> -- 
> 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