So, I read that the count
operation is O(1) for a Clojure vectors, lists and maps.
(count [1 2 3]) ;=> 3
But is it also O(1) for a Clojure set? I imagine it probably is, but I'm not really sure how to find out. I had a quick read of http://clojure.org/data_structures#Data%20Structures-Sets, but couldn't see the info there.
It is O(1)
You can verify this by observing that clojure.lang.PersistentSet
maintains a _count
field in the Java source code:
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentList.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With