Here are some experiments that aren't polymorphic. The System/arraycopy version is fastest, by far. Is there any good way to make the other versions faster, or make them handle any array type?
(defn bconcat [& arrays] (let [sizes (map count arrays) sizes_r (vec (reductions + sizes)) offsets (cons 0 (drop-last sizes_r)) total (last sizes_r) out (float-array total)] (dorun (map #(System/arraycopy %2 0 out %1 %3) offsets arrays sizes)) out)) (defn cconcat [& arrays] (let [vs (map vec arrays) cc (apply concat vs)] (float-array cc))) (defn dconcat [& arrays] (let [vs (map vec arrays) cc (reduce into [] vs)] (float-array cc))) (defn econcat [& arrays] (let [cc (reduce into [] arrays)] (float-array cc))) On Saturday, July 20, 2013 2:24:14 PM UTC-7, Brian Craft wrote: > > Is there an easy, fast way to concat primitive arrays? I was hoping java > arrays had some common interface for this, but I haven't found much of use. > I mostly see code like this: > > byte[] c = new byte[a.length + b.length]; > System.arraycopy(a, 0, c, 0, a.length); > System.arraycopy(b, 0, c, a.length, b.length); > > which only works for bytes (in this case). > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.