On Dec 2, 1:32 pm, Stefan Kamphausen <ska2...@googlemail.com> wrote:
> Hi,
>
> On Dec 2, 10:24 pm, ataggart <alex.tagg...@gmail.com> wrote:
>
> > My guess is that String and array, while not implementing the
> > IAssociative interface, all have the O(1) lookup performance
> > guarantees of associative data structures,
>
> um, no?  According to the bit-partition implementation of vector and
> the slightly more complex implementation of maps they are O(log_{32}
> (N)), which of course given the size of Integer doesn't get too
> large.  So I wouldn't think, the Big-O was the reason.

Yes, yes it's not truly O(1), but it's close enough.  Vectors are
distinct from lists not only in which end new elements are appended,
but also in the performance guarantees they try to meet.  Again, my
guess is that the lookup complexity was the driver as the intention of
the function is to be used with associative structures.

> But lists, as others, have O(1) lookup for count, so at least the
> index-based contains? which is used for vectors, Strings and arrays
> should be usable.  

I will further guess that lists weren't added since the key to
contains? can't be used to lookup a value in (near) O(1), whereas you
can do so with Strings and arrays, e.g., (get "hello" 1) returns \e.

The parameter to get is "map" and not "coll".  I would agree that
contains? should likewise reflect the associative nature of the
collection (though the doc does use the word "key").

>Actually it may be usable for every class extending Counted.

If you want to know the number of elements in a collection, or whether
an index is valid for a collection, use count.  The contains?
function, like the get function, is intended to operate on suitable
data structures without being concerned with type.  In short, if you
can't pass your data to get, you shouldn't expect contains? to work
either.

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