Here is the code for assoc:
(def assoc
(fn assoc
([map key val] (. clojure.lang.RT (assoc map key val)))))
-
What is the meaning of
clojure.lang.RT? -
What is the complexity of calling
assocon a vector/map? -
What is the complexity of accessing a structure that has been created by
assoc?
clojure.lang.RTis the main Clojure RunTime class. It has most of the methods that make up the core of the language.associs O(1) for all the associative data structure including vectors and maps.array-mapstarts out linear for the first few item, then promoted itself to ahash-mapso it is O(1) as well. You could of course implement the associative interface with something that is not O(1) if you need to.Technically the access time for an item in a map or vector that was created by calling
assocon another map is O(log32 N). Because these data structures have an upper bound on the size of ~2^32 items this leaves a maximum tree depth of six which effectively constant timeClojure’s associative data structures are all O(nLog n) in space (because they are trees).