`count`在Clojure集合上的性能是什么? [英] What is the performance of `count` on a Clojure set?
问题描述
所以,我看到对于Clojure向量,列表和映射, count
操作是 O(1)。
So, I read that the count
operation is O(1) for a Clojure vectors, lists and maps.
(count [1 2 3]) ;=> 3
但是对于Clojure集合,它还是 O(1)我想象它可能是,但我不知道如何找到。我快速阅读了 http://clojure.org/data_structures#Data%20Structures-Sets
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.
推荐答案
这是 O(1)
您可以通过观察 clojure.lang.PersistentSet
c $ c> _count 字段:
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
这篇关于`count`在Clojure集合上的性能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!