On Tue, Sep 13, 2011 at 2:39 AM, Michael Gardner <[email protected]> wrote: > On Sep 12, 2011, at 11:28 PM, Ken Wesson wrote: > >> But if, as you say, take, drop, etc. work for larger n, it should be >> easy to make nth work with larger n and non-random-access seqs, just >> by changing the non-random-access case to (first (drop n the-seq)). > > I'd be rather surprised if nth suddenly started giving linear performance on > arrays for large values of n. If nth can't be made to work in constant time > on arrays for n > 2**31, then I'd favor the IllegalArgumentException > approach. One can always do (first (drop …)) manually if linear performance > is acceptable.
It already gives log32 rather than constant time performance on vectors, I think. That would stay the same. It can be extended to sorted-set and sorted-map with log2 time performance, again including with large-n support. On actual java.util collections and Java arrays it can just check if n exceeds 2^31 - 1, give not-found behavior if so, and otherwise punt to Java. And on non-random-access stuff it can use (first (drop n thingy)). -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
