clojure:O(1)时间得到矢量的大小

use*_*359 6 clojure

上下文

(doc count)
-------------------------
clojure.core/count
([coll])
  Returns the number of items in the collection. (count nil) returns
  0.  Also works on strings, arrays, and Java Collections and Maps
Run Code Online (Sandbox Code Playgroud)

题

计数是否保证在向量上是恒定的时间?

如果没有,无论如何都要在恒定时间内获得矢量的大小?

更多背景

我实际上想得到一个向量的列表元素,我可以在O(1)中用nth做,假设我知道向量大小.

编辑:

我忘了提这个.我需要这个来处理瞬态向量.

ama*_*loy 9

是的,向量上的计数总是很快.但你可以打电话peek来获取它的最后一个元素.