On Tuesday, June 12, 2012 12:54:08 PM UTC+2, Chris Ford wrote: > > I guess the question should then be, should nth call seq on its argument? >
This is horrible for performance. For a sequence, nth will run in O(n) time, whereas it for any indexed data structure (vectors, strings, arraylists, etc.) runs in constant time. It is also semantically scary: By adding maps into the nth-definition, you may "trick" people into believing all maps are sorted. Besides, what should it return that "makes sense"? The value, or the key-value pair? If you really need nth for your hash map in the way you describe and don't need to remove elements from the map, then I suggest creating a new data structure with a vector and a hash map. assoc will add a key-value pair in the hash map as well as conj(oin) [key value] onto the vector. Now, whenever you need to perform nth, you will get the speed of the vector, while maintaining the speed a map has otherwise. -- 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