这是frequencies
in的实现clojure
:
(defn frequencies
"Returns a map from distinct items in coll to the number of times
they appear."
[coll]
(persistent!
(reduce (fn [counts x]
(assoc! counts x (inc (get counts x 0))))
(transient {}) coll)))
是否被assoc!
认为是突变?
assoc!
里面的复杂度是frequencies
多少?
此外,似乎counts
每次迭代都会访问两次:它会导致性能损失吗?