Public Vars

Back

aclone (clj)

(source)

function

(aclone array)
Returns a clone of the Java array. Works on arrays of known types.

Examples

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)))

    (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)))))
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 (== p/non-regular-array-len (alength ^objects new-arr))
          (aset new-arr p/max-branches (aclone (ints (aget ^objects new-arr p/max-branches)))))
        (.node nm (AtomicReference. (Thread/currentThread)) new-arr)))

    (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 (== p/non-regular-array-len (alength ^objects new-arr))
              (aset new-arr p/max-branches (aclone (ints (aget ^objects new-arr p/max-branches)))))
            (.node nm root-edit new-arr)))))
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)))

(def ^ITransientHelper transient-helper
  (reify ITransientHelper
    (editableRoot [this nm am root]
      (.node nm
             (AtomicReference. (Thread/currentThread))
             (clojure.core/aclone ^objects (.array nm root))))

    (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)))))