小编Zuz*_*ana的帖子

为什么在Clojure中的瞬态映射中插入1000 000个值会产生一个包含8个项目的映射?

如果我尝试assoc!在瞬态向量上做1000 000 ,我将获得1000 000个元素的向量

(count
  (let [m (transient [])]
    (dotimes [i 1000000]
      (assoc! m i i)) (persistent! m)))
; => 1000000
Run Code Online (Sandbox Code Playgroud)

另一方面,如果我对地图做同样的事情,它只会有8个项目

(count
  (let [m (transient {})]
    (dotimes [i 1000000]
      (assoc! m i i)) (persistent! m)))
; => 8
Run Code Online (Sandbox Code Playgroud)

有没有理由发生这种情况?

collections dictionary vector clojure transient

11
推荐指数
2
解决办法
1169
查看次数

标签 统计

clojure ×1

collections ×1

dictionary ×1

transient ×1

vector ×1