Back
alength (clj)
(source)function
(alength array)
Returns the length of the Java array. Works on arrays of all
types.
Examples
mikera/core.matrix
(ns clojure.core.matrix.macros-cljs
"Namespace for core.matrix macros. Keeping them separate allows us to do conditional
macros that can handle the differences between Clojure and Clojurescript."
(:require [clojure.core.matrix.macros :refer [c-for TODO]]))
(defmacro abutnth [i xs]
`(let [n# (alength ~xs)
length# (int (dec n#))
new-xs# (.slice ~xs 0 length#)]
(c-for [j# (int ~i) (< j# (dec n#)) (inc j#)]
(aset new-xs# (int j#) (aget ~xs (int (inc j#)))))
new-xs#))
(defmacro areverse [xs]
`(let [n# (alength ~xs)
new-xs# (.slice ~xs 0 n#)]
(c-for [i# (int 0) (< i# (quot n# 2)) (inc i#)]
(let [j# (- (- n# 1) i#)
t# (aget new-xs# j#)]
(aset new-xs# j# (aget new-xs# i#))
(aset new-xs# i# t#)))
new-xs#))
mikera/core.matrix
(ns clojure.core.matrix.macros-clj
"Namespace for core.matrix macros. Keeping them separate allows us to do conditional
macros that can handle the differences between Clojure and Clojurescript."
(:require [clojure.core.matrix.macros :refer [TODO c-for]])
(:import [java.util Arrays]))
(defmacro abutnth [i xs]
`(let [n# (alength ~xs)
length# (int (dec n#))
new-xs# (Arrays/copyOf ~xs length#)]
(c-for [j# (int ~i) (< j# (dec n#)) (inc j#)]
(aset new-xs# (int j#) (aget ~xs (int (inc j#)))))
new-xs#))
(defmacro areverse [xs]
`(let [n# (alength ~xs)
new-xs# (Arrays/copyOf ~xs (int n#))]
(c-for [i# (int 0) (< i# (quot n# 2)) (inc i#)]
(let [j# (- (- n# 1) i#)
t# (aget new-xs# j#)]
(aset new-xs# j# (aget new-xs# i#))
(aset new-xs# i# t#)))
new-xs#))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
cc/alength [(ReadOnlyArray t/Any) :-> t/AnyInteger]
cc/aclone (t/All [x] [(ReadOnlyArray x) :-> (Array x)])
cc/aget (t/All [x]
(t/IFn [(ReadOnlyArray x)
t/AnyInteger :-> x]
[(ReadOnlyArray (ReadOnlyArray x))
t/AnyInteger t/AnyInteger :-> x]
[(ReadOnlyArray (ReadOnlyArray (ReadOnlyArray x)))
t/AnyInteger t/AnyInteger t/AnyInteger :-> x]
[(ReadOnlyArray (ReadOnlyArray (ReadOnlyArray (ReadOnlyArray x))))
t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger :-> x]
; don't support unsound cases
[(ReadOnlyArray (ReadOnlyArray (ReadOnlyArray (ReadOnlyArray (ReadOnlyArray x)))))
t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger :-> x]))
clojure/core.rrb-vector
(ns clojure.core.rrb-vector.transients
(:require [clojure.core.rrb-vector.parameters :as p]
[clojure.core.rrb-vector.nodes :refer [ranges last-range
overflow?]])
(:import (clojure.core.rrb_vector.nodes NodeManager)
(clojure.core ArrayManager)
(java.util.concurrent.atomic AtomicReference)))
(def ^ITransientHelper transient-helper
(reify ITransientHelper
(editableRoot [this nm am root]
(let [new-arr (clojure.core/aclone ^objects (.array nm root))]
(if (== 33 (alength ^objects new-arr))
(aset new-arr 32 (aclone (ints (aget ^objects new-arr 32)))))
(.node nm (AtomicReference. (Thread/currentThread)) new-arr)))
(editableTail [this am tail]
(let [ret (.array am 32)]
(System/arraycopy tail 0 ret 0 (.alength am tail))
ret))
(ensureEditable [this nm am root-edit current-node shift]
(if (identical? root-edit (.edit nm current-node))
current-node
(if (zero? shift)
(let [new-arr (.aclone am (.array nm current-node))]
(.node nm root-edit new-arr))
(let [new-arr (aclone ^objects (.array nm current-node))]
(if (== 33 (alength ^objects new-arr))
(aset new-arr 32 (aclone (ints (aget ^objects new-arr 32)))))
(.node nm root-edit new-arr)))))
(newPath [this nm am tail edit shift current-node]
(if (== (.alength am tail) 32)
(loop [s 0 n current-node]
(if (== s shift)
n
(let [arr (object-array 32)
ret (.node nm edit arr)]
(aset ^objects arr 0 n)
(recur (unchecked-add s (int 5)) ret))))
(loop [s 0 n current-node]
(if (== s shift)
n
(let [arr (object-array 33)
rngs (int-array 33)
ret (.node nm edit arr)]
(aset ^objects arr 0 n)
(aset ^objects arr 32 rngs)
(aset rngs 32 1)
(aset rngs 0 (.alength am tail))
(recur (unchecked-add s (int 5)) ret))))))))
datastax/fallout
(ns clojure.core.rrb-vector.transients
(:require [clojure.core.rrb-vector.nodes :refer [ranges last-range]])
(:import (clojure.core.rrb_vector.nodes NodeManager)
(clojure.core ArrayManager)
(java.util.concurrent.atomic AtomicReference)))
(editableTail [this am tail]
(let [ret (.array am 32)]
(System/arraycopy tail 0 ret 0 (.alength am tail))
ret))
(ensureEditable [this nm am root-edit current-node shift]
(if (identical? root-edit (.edit nm current-node))
current-node
(if (zero? shift)
(let [new-arr (.aclone am (.array nm current-node))]
(.node nm root-edit new-arr))
(let [new-arr (aclone ^objects (.array nm current-node))]
(if (== 33 (alength ^objects new-arr))
(aset new-arr 32 (aclone (ints (aget ^objects new-arr 32)))))
(.node nm root-edit new-arr)))))
(newPath [this nm am tail edit shift current-node]
(if (== (.alength am tail) 32)
(loop [s 0 n current-node]
(if (== s shift)
n
(let [arr (object-array 32)
ret (.node nm edit arr)]
(aset ^objects arr 0 n)
(recur (unchecked-add s 5) ret))))
(loop [s 0 n current-node]
(if (== s shift)
n
(let [arr (object-array 33)
rngs (int-array 33)
ret (.node nm edit arr)]
(aset ^objects arr 0 n)
(aset ^objects arr 32 rngs)
(aset rngs 32 1)
(aset rngs 0 (.alength am tail))
(recur (unchecked-add s 5) ret))))))))